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>
12 #include <linux/jiffies.h>
14 #include "event_buffer.h"
15 #include "oprofile_stats.h"
18 #define BUFFER_SIZE_DEFAULT 131072
19 #define CPU_BUFFER_SIZE_DEFAULT 8192
20 #define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
21 #define TIME_SLICE_DEFAULT 1
23 unsigned long oprofile_buffer_size
;
24 unsigned long oprofile_cpu_buffer_size
;
25 unsigned long oprofile_buffer_watershed
;
26 unsigned long oprofile_time_slice
;
28 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
30 static ssize_t
timeout_read(struct file
*file
, char __user
*buf
,
31 size_t count
, loff_t
*offset
)
33 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice
),
38 static ssize_t
timeout_write(struct file
*file
, char const __user
*buf
,
39 size_t count
, loff_t
*offset
)
47 retval
= oprofilefs_ulong_from_user(&val
, buf
, count
);
51 retval
= oprofile_set_timeout(val
);
59 static const struct file_operations timeout_fops
= {
61 .write
= timeout_write
,
62 .llseek
= default_llseek
,
68 static ssize_t
depth_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
70 return oprofilefs_ulong_to_user(oprofile_backtrace_depth
, buf
, count
,
75 static ssize_t
depth_write(struct file
*file
, char const __user
*buf
, size_t count
, loff_t
*offset
)
83 if (!oprofile_ops
.backtrace
)
86 retval
= oprofilefs_ulong_from_user(&val
, buf
, count
);
90 retval
= oprofile_set_ulong(&oprofile_backtrace_depth
, val
);
98 static const struct file_operations depth_fops
= {
100 .write
= depth_write
,
101 .llseek
= default_llseek
,
105 static ssize_t
pointer_size_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
107 return oprofilefs_ulong_to_user(sizeof(void *), buf
, count
, offset
);
111 static const struct file_operations pointer_size_fops
= {
112 .read
= pointer_size_read
,
113 .llseek
= default_llseek
,
117 static ssize_t
cpu_type_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
119 return oprofilefs_str_to_user(oprofile_ops
.cpu_type
, buf
, count
, offset
);
123 static const struct file_operations cpu_type_fops
= {
124 .read
= cpu_type_read
,
125 .llseek
= default_llseek
,
129 static ssize_t
enable_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
131 return oprofilefs_ulong_to_user(oprofile_started
, buf
, count
, offset
);
135 static ssize_t
enable_write(struct file
*file
, char const __user
*buf
, size_t count
, loff_t
*offset
)
143 retval
= oprofilefs_ulong_from_user(&val
, buf
, count
);
149 retval
= oprofile_start();
159 static const struct file_operations enable_fops
= {
161 .write
= enable_write
,
162 .llseek
= default_llseek
,
166 static ssize_t
dump_write(struct file
*file
, char const __user
*buf
, size_t count
, loff_t
*offset
)
168 wake_up_buffer_waiter();
173 static const struct file_operations dump_fops
= {
175 .llseek
= noop_llseek
,
178 void oprofile_create_files(struct dentry
*root
)
180 /* reinitialize default values */
181 oprofile_buffer_size
= BUFFER_SIZE_DEFAULT
;
182 oprofile_cpu_buffer_size
= CPU_BUFFER_SIZE_DEFAULT
;
183 oprofile_buffer_watershed
= BUFFER_WATERSHED_DEFAULT
;
184 oprofile_time_slice
= msecs_to_jiffies(TIME_SLICE_DEFAULT
);
186 oprofilefs_create_file(root
, "enable", &enable_fops
);
187 oprofilefs_create_file_perm(root
, "dump", &dump_fops
, 0666);
188 oprofilefs_create_file(root
, "buffer", &event_buffer_fops
);
189 oprofilefs_create_ulong(root
, "buffer_size", &oprofile_buffer_size
);
190 oprofilefs_create_ulong(root
, "buffer_watershed", &oprofile_buffer_watershed
);
191 oprofilefs_create_ulong(root
, "cpu_buffer_size", &oprofile_cpu_buffer_size
);
192 oprofilefs_create_file(root
, "cpu_type", &cpu_type_fops
);
193 oprofilefs_create_file(root
, "backtrace_depth", &depth_fops
);
194 oprofilefs_create_file(root
, "pointer_size", &pointer_size_fops
);
195 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
196 oprofilefs_create_file(root
, "time_slice", &timeout_fops
);
198 oprofile_create_stats_files(root
);
199 if (oprofile_ops
.create_files
)
200 oprofile_ops
.create_files(root
);