Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / oprofile / oprofile_files.c
blobd8201998b0b7f8d93b5b7f1a654851374256dff9
1 /**
2 * @file oprofile_files.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
8 */
10 #include <linux/fs.h>
11 #include <linux/oprofile.h>
13 #include "event_buffer.h"
14 #include "oprofile_stats.h"
15 #include "oprof.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)
33 unsigned long val;
34 int retval;
36 if (*offset)
37 return -EINVAL;
39 retval = oprofilefs_ulong_from_user(&val, buf, count);
40 if (retval)
41 return retval;
43 retval = oprofile_set_backtrace(val);
45 if (retval)
46 return retval;
47 return count;
51 static const struct file_operations depth_fops = {
52 .read = depth_read,
53 .write = depth_write
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)
87 unsigned long val;
88 int retval;
90 if (*offset)
91 return -EINVAL;
93 retval = oprofilefs_ulong_from_user(&val, buf, count);
94 if (retval)
95 return retval;
97 if (val)
98 retval = oprofile_start();
99 else
100 oprofile_stop();
102 if (retval)
103 return retval;
104 return count;
108 static const struct file_operations enable_fops = {
109 .read = enable_read,
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();
117 return count;
121 static const struct file_operations dump_fops = {
122 .write = dump_write,
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);