oprofile: Rename variable timeout_jiffies and move to oprofile_files.c
[safe/jmp/linux-2.6] / drivers / oprofile / oprofile_files.c
1 /**
2  * @file oprofile_files.c
3  *
4  * @remark Copyright 2002 OProfile authors
5  * @remark Read the file COPYING
6  *
7  * @author John Levon <levon@movementarian.org>
8  */
9
10 #include <linux/fs.h>
11 #include <linux/oprofile.h>
12 #include <linux/jiffies.h>
13
14 #include "event_buffer.h"
15 #include "oprofile_stats.h"
16 #include "oprof.h"
17
18 #define BUFFER_SIZE_DEFAULT             131072
19 #define CPU_BUFFER_SIZE_DEFAULT         8192
20 #define BUFFER_WATERSHED_DEFAULT        32768   /* FIXME: tune */
21
22 unsigned long oprofile_buffer_size;
23 unsigned long oprofile_cpu_buffer_size;
24 unsigned long oprofile_buffer_watershed;
25 unsigned long oprofile_time_slice;
26
27 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
28
29 static ssize_t timeout_read(struct file *file, char __user *buf,
30                 size_t count, loff_t *offset)
31 {
32         return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
33                                         buf, count, offset);
34 }
35
36
37 static ssize_t timeout_write(struct file *file, char const __user *buf,
38                 size_t count, loff_t *offset)
39 {
40         unsigned long val;
41         int retval;
42
43         if (*offset)
44                 return -EINVAL;
45
46         retval = oprofilefs_ulong_from_user(&val, buf, count);
47         if (retval)
48                 return retval;
49
50         retval = oprofile_set_timeout(val);
51
52         if (retval)
53                 return retval;
54         return count;
55 }
56
57
58 static const struct file_operations timeout_fops = {
59         .read           = timeout_read,
60         .write          = timeout_write,
61 };
62
63 #endif
64
65
66 static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
67 {
68         return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
69                                         offset);
70 }
71
72
73 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
74 {
75         unsigned long val;
76         int retval;
77
78         if (*offset)
79                 return -EINVAL;
80
81         retval = oprofilefs_ulong_from_user(&val, buf, count);
82         if (retval)
83                 return retval;
84
85         retval = oprofile_set_backtrace(val);
86
87         if (retval)
88                 return retval;
89         return count;
90 }
91
92
93 static const struct file_operations depth_fops = {
94         .read           = depth_read,
95         .write          = depth_write
96 };
97
98
99 static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
100 {
101         return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
102 }
103
104
105 static const struct file_operations pointer_size_fops = {
106         .read           = pointer_size_read,
107 };
108
109
110 static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
111 {
112         return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
113 }
114
115
116 static const struct file_operations cpu_type_fops = {
117         .read           = cpu_type_read,
118 };
119
120
121 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
122 {
123         return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
124 }
125
126
127 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
128 {
129         unsigned long val;
130         int retval;
131
132         if (*offset)
133                 return -EINVAL;
134
135         retval = oprofilefs_ulong_from_user(&val, buf, count);
136         if (retval)
137                 return retval;
138
139         if (val)
140                 retval = oprofile_start();
141         else
142                 oprofile_stop();
143
144         if (retval)
145                 return retval;
146         return count;
147 }
148
149
150 static const struct file_operations enable_fops = {
151         .read           = enable_read,
152         .write          = enable_write,
153 };
154
155
156 static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
157 {
158         wake_up_buffer_waiter();
159         return count;
160 }
161
162
163 static const struct file_operations dump_fops = {
164         .write          = dump_write,
165 };
166
167 void oprofile_create_files(struct super_block *sb, struct dentry *root)
168 {
169         /* reinitialize default values */
170         oprofile_buffer_size =          BUFFER_SIZE_DEFAULT;
171         oprofile_cpu_buffer_size =      CPU_BUFFER_SIZE_DEFAULT;
172         oprofile_buffer_watershed =     BUFFER_WATERSHED_DEFAULT;
173
174         oprofilefs_create_file(sb, root, "enable", &enable_fops);
175         oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
176         oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
177         oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
178         oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
179         oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
180         oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
181         oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
182         oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
183 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
184         oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
185 #endif
186         oprofile_create_stats_files(sb, root);
187         if (oprofile_ops.create_files)
188                 oprofile_ops.create_files(sb, root);
189 }