Staging: strip: delete the driver
[linux/fpc-iii.git] / drivers / oprofile / oprofile_files.c
blobbbd7516e0869461c141659004580d509ec5e97a5
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>
12 #include <linux/jiffies.h>
14 #include "event_buffer.h"
15 #include "oprofile_stats.h"
16 #include "oprof.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),
34 buf, count, offset);
38 static ssize_t timeout_write(struct file *file, char const __user *buf,
39 size_t count, loff_t *offset)
41 unsigned long val;
42 int retval;
44 if (*offset)
45 return -EINVAL;
47 retval = oprofilefs_ulong_from_user(&val, buf, count);
48 if (retval)
49 return retval;
51 retval = oprofile_set_timeout(val);
53 if (retval)
54 return retval;
55 return count;
59 static const struct file_operations timeout_fops = {
60 .read = timeout_read,
61 .write = timeout_write,
64 #endif
67 static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
69 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
70 offset);
74 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
76 unsigned long val;
77 int retval;
79 if (*offset)
80 return -EINVAL;
82 retval = oprofilefs_ulong_from_user(&val, buf, count);
83 if (retval)
84 return retval;
86 retval = oprofile_set_backtrace(val);
88 if (retval)
89 return retval;
90 return count;
94 static const struct file_operations depth_fops = {
95 .read = depth_read,
96 .write = depth_write
100 static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
102 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
106 static const struct file_operations pointer_size_fops = {
107 .read = pointer_size_read,
111 static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
113 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
117 static const struct file_operations cpu_type_fops = {
118 .read = cpu_type_read,
122 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
124 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
128 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
130 unsigned long val;
131 int retval;
133 if (*offset)
134 return -EINVAL;
136 retval = oprofilefs_ulong_from_user(&val, buf, count);
137 if (retval)
138 return retval;
140 if (val)
141 retval = oprofile_start();
142 else
143 oprofile_stop();
145 if (retval)
146 return retval;
147 return count;
151 static const struct file_operations enable_fops = {
152 .read = enable_read,
153 .write = enable_write,
157 static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
159 wake_up_buffer_waiter();
160 return count;
164 static const struct file_operations dump_fops = {
165 .write = dump_write,
168 void oprofile_create_files(struct super_block *sb, struct dentry *root)
170 /* reinitialize default values */
171 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
172 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
173 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
174 oprofile_time_slice = msecs_to_jiffies(TIME_SLICE_DEFAULT);
176 oprofilefs_create_file(sb, root, "enable", &enable_fops);
177 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
178 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
179 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
180 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
181 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
182 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
183 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
184 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
185 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
186 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
187 #endif
188 oprofile_create_stats_files(sb, root);
189 if (oprofile_ops.create_files)
190 oprofile_ops.create_files(sb, root);