]>
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 */ | |
37ca5eb3 | 21 | |
bd2172f5 RR |
22 | unsigned long oprofile_buffer_size; |
23 | unsigned long oprofile_cpu_buffer_size; | |
24 | unsigned long oprofile_buffer_watershed; | |
afe1b50f | 25 | unsigned long oprofile_time_slice; |
1da177e4 | 26 | |
4d4036e0 JY |
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 | { | |
afe1b50f RR |
32 | return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice), |
33 | buf, count, offset); | |
4d4036e0 JY |
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 | ||
25ad2913 | 66 | static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
1da177e4 | 67 | { |
bd2172f5 RR |
68 | return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count, |
69 | offset); | |
1da177e4 LT |
70 | } |
71 | ||
72 | ||
25ad2913 | 73 | static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
1da177e4 LT |
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 | ||
d54b1fdb | 93 | static const struct file_operations depth_fops = { |
1da177e4 LT |
94 | .read = depth_read, |
95 | .write = depth_write | |
96 | }; | |
97 | ||
6a18037d | 98 | |
25ad2913 | 99 | static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
1da177e4 LT |
100 | { |
101 | return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset); | |
102 | } | |
103 | ||
104 | ||
d54b1fdb | 105 | static const struct file_operations pointer_size_fops = { |
1da177e4 LT |
106 | .read = pointer_size_read, |
107 | }; | |
108 | ||
109 | ||
25ad2913 | 110 | static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
1da177e4 LT |
111 | { |
112 | return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset); | |
113 | } | |
6a18037d RR |
114 | |
115 | ||
d54b1fdb | 116 | static const struct file_operations cpu_type_fops = { |
1da177e4 LT |
117 | .read = cpu_type_read, |
118 | }; | |
6a18037d RR |
119 | |
120 | ||
25ad2913 | 121 | static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
1da177e4 LT |
122 | { |
123 | return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset); | |
124 | } | |
125 | ||
126 | ||
25ad2913 | 127 | static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
1da177e4 LT |
128 | { |
129 | unsigned long val; | |
130 | int retval; | |
131 | ||
132 | if (*offset) | |
133 | return -EINVAL; | |
4c168eaf | 134 | |
1da177e4 LT |
135 | retval = oprofilefs_ulong_from_user(&val, buf, count); |
136 | if (retval) | |
137 | return retval; | |
6a18037d | 138 | |
1da177e4 LT |
139 | if (val) |
140 | retval = oprofile_start(); | |
141 | else | |
142 | oprofile_stop(); | |
143 | ||
144 | if (retval) | |
145 | return retval; | |
146 | return count; | |
147 | } | |
148 | ||
6a18037d | 149 | |
d54b1fdb | 150 | static const struct file_operations enable_fops = { |
1da177e4 LT |
151 | .read = enable_read, |
152 | .write = enable_write, | |
153 | }; | |
154 | ||
155 | ||
25ad2913 | 156 | static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
1da177e4 LT |
157 | { |
158 | wake_up_buffer_waiter(); | |
159 | return count; | |
160 | } | |
161 | ||
162 | ||
d54b1fdb | 163 | static const struct file_operations dump_fops = { |
1da177e4 LT |
164 | .write = dump_write, |
165 | }; | |
6a18037d | 166 | |
25ad2913 | 167 | void oprofile_create_files(struct super_block *sb, struct dentry *root) |
1da177e4 | 168 | { |
37ca5eb3 | 169 | /* reinitialize default values */ |
bd2172f5 RR |
170 | oprofile_buffer_size = BUFFER_SIZE_DEFAULT; |
171 | oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT; | |
172 | oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT; | |
37ca5eb3 | 173 | |
1da177e4 LT |
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); | |
bd2172f5 RR |
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); | |
6a18037d | 180 | oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); |
1da177e4 LT |
181 | oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops); |
182 | oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops); | |
4d4036e0 JY |
183 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
184 | oprofilefs_create_file(sb, root, "time_slice", &timeout_fops); | |
185 | #endif | |
1da177e4 LT |
186 | oprofile_create_stats_files(sb, root); |
187 | if (oprofile_ops.create_files) | |
188 | oprofile_ops.create_files(sb, root); | |
189 | } |