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