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 unsigned long fs_buffer_size = 131072;
19 unsigned long fs_cpu_buffer_size = 8192;
20 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
22 static ssize_t timeout_read(struct file *file, char __user *buf,
23 size_t count, loff_t *offset)
25 return oprofilefs_ulong_to_user(jiffies_to_msecs(timeout_jiffies),
30 static ssize_t timeout_write(struct file *file, char const __user *buf,
31 size_t count, loff_t *offset)
39 retval = oprofilefs_ulong_from_user(&val, buf, count);
43 retval = oprofile_set_timeout(val);
50 static const struct file_operations timeout_fops = {
52 .write = timeout_write,
56 static ssize_t depth_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
58 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
62 static ssize_t depth_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
70 retval = oprofilefs_ulong_from_user(&val, buf, count);
74 retval = oprofile_set_backtrace(val);
82 static const struct file_operations depth_fops = {
88 static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
90 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
94 static const struct file_operations pointer_size_fops = {
95 .read = pointer_size_read,
99 static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
101 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
105 static const struct file_operations cpu_type_fops = {
106 .read = cpu_type_read,
110 static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
112 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
116 static ssize_t enable_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
123 retval = oprofilefs_ulong_from_user(&val, buf, count);
128 retval = oprofile_start();
138 static const struct file_operations enable_fops = {
140 .write = enable_write,
144 static ssize_t dump_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
146 wake_up_buffer_waiter();
151 static const struct file_operations dump_fops = {
155 void oprofile_create_files(struct super_block * sb, struct dentry * root)
157 oprofilefs_create_file(sb, root, "enable", &enable_fops);
158 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
159 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
160 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
161 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
162 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
163 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
164 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
165 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
166 oprofilefs_create_file(sb, root, "timeout_ms", &timeout_fops);
167 oprofile_create_stats_files(sb, root);
168 if (oprofile_ops.create_files)
169 oprofile_ops.create_files(sb, root);