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