2 * @file oprofile_files.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
11 #include <linux/oprofile.h>
13 #include "event_buffer.h"
14 #include "oprofile_stats.h"
17 #define FS_BUFFER_SIZE_DEFAULT 131072
18 #define FS_CPU_BUFFER_SIZE_DEFAULT 8192
19 #define FS_BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
21 unsigned long fs_buffer_size
;
22 unsigned long fs_cpu_buffer_size
;
23 unsigned long fs_buffer_watershed
;
25 static ssize_t
depth_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
27 return oprofilefs_ulong_to_user(backtrace_depth
, buf
, count
, offset
);
31 static ssize_t
depth_write(struct file
*file
, char const __user
*buf
, size_t count
, loff_t
*offset
)
39 retval
= oprofilefs_ulong_from_user(&val
, buf
, count
);
43 retval
= oprofile_set_backtrace(val
);
51 static const struct file_operations depth_fops
= {
57 static ssize_t
pointer_size_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
59 return oprofilefs_ulong_to_user(sizeof(void *), buf
, count
, offset
);
63 static const struct file_operations pointer_size_fops
= {
64 .read
= pointer_size_read
,
68 static ssize_t
cpu_type_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
70 return oprofilefs_str_to_user(oprofile_ops
.cpu_type
, buf
, count
, offset
);
74 static const struct file_operations cpu_type_fops
= {
75 .read
= cpu_type_read
,
79 static ssize_t
enable_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
81 return oprofilefs_ulong_to_user(oprofile_started
, buf
, count
, offset
);
85 static ssize_t
enable_write(struct file
*file
, char const __user
*buf
, size_t count
, loff_t
*offset
)
93 retval
= oprofilefs_ulong_from_user(&val
, buf
, count
);
98 retval
= oprofile_start();
108 static const struct file_operations enable_fops
= {
110 .write
= enable_write
,
114 static ssize_t
dump_write(struct file
*file
, char const __user
*buf
, size_t count
, loff_t
*offset
)
116 wake_up_buffer_waiter();
121 static const struct file_operations dump_fops
= {
125 void oprofile_create_files(struct super_block
*sb
, struct dentry
*root
)
127 /* reinitialize default values */
128 fs_buffer_size
= FS_BUFFER_SIZE_DEFAULT
;
129 fs_cpu_buffer_size
= FS_CPU_BUFFER_SIZE_DEFAULT
;
130 fs_buffer_watershed
= FS_BUFFER_WATERSHED_DEFAULT
;
132 oprofilefs_create_file(sb
, root
, "enable", &enable_fops
);
133 oprofilefs_create_file_perm(sb
, root
, "dump", &dump_fops
, 0666);
134 oprofilefs_create_file(sb
, root
, "buffer", &event_buffer_fops
);
135 oprofilefs_create_ulong(sb
, root
, "buffer_size", &fs_buffer_size
);
136 oprofilefs_create_ulong(sb
, root
, "buffer_watershed", &fs_buffer_watershed
);
137 oprofilefs_create_ulong(sb
, root
, "cpu_buffer_size", &fs_cpu_buffer_size
);
138 oprofilefs_create_file(sb
, root
, "cpu_type", &cpu_type_fops
);
139 oprofilefs_create_file(sb
, root
, "backtrace_depth", &depth_fops
);
140 oprofilefs_create_file(sb
, root
, "pointer_size", &pointer_size_fops
);
141 oprofile_create_stats_files(sb
, root
);
142 if (oprofile_ops
.create_files
)
143 oprofile_ops
.create_files(sb
, root
);