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 BUFFER_SIZE_DEFAULT 131072
18 #define CPU_BUFFER_SIZE_DEFAULT 8192
19 #define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
21 unsigned long oprofile_buffer_size;
22 unsigned long oprofile_cpu_buffer_size;
23 unsigned long oprofile_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(oprofile_backtrace_depth, buf, count,
32 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
40 retval = oprofilefs_ulong_from_user(&val, buf, count);
44 retval = oprofile_set_backtrace(val);
52 static const struct file_operations depth_fops = {
58 static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
60 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
64 static const struct file_operations pointer_size_fops = {
65 .read = pointer_size_read,
69 static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
71 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
75 static const struct file_operations cpu_type_fops = {
76 .read = cpu_type_read,
80 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
82 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
86 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
94 retval = oprofilefs_ulong_from_user(&val, buf, count);
99 retval = oprofile_start();
109 static const struct file_operations enable_fops = {
111 .write = enable_write,
115 static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
117 wake_up_buffer_waiter();
122 static const struct file_operations dump_fops = {
126 void oprofile_create_files(struct super_block *sb, struct dentry *root)
128 /* reinitialize default values */
129 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
130 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
131 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
133 oprofilefs_create_file(sb, root, "enable", &enable_fops);
134 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
135 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
136 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
137 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
138 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
139 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
140 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
141 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
142 oprofile_create_stats_files(sb, root);
143 if (oprofile_ops.create_files)
144 oprofile_ops.create_files(sb, root);