ia64/linux-2.6.18-xen.hg

view drivers/oprofile/oprofile_files.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:32:57 2009 +0100 (2009-06-04)
parents 271d9b9bee40
children
line source
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 * Modified by Aravind Menon for Xen
10 * These modifications are:
11 * Copyright (C) 2005 Hewlett-Packard Co.
12 */
14 #include <linux/fs.h>
15 #include <linux/oprofile.h>
16 #include <asm/uaccess.h>
17 #include <linux/ctype.h>
19 #include "event_buffer.h"
20 #include "oprofile_stats.h"
21 #include "oprof.h"
23 unsigned long fs_buffer_size = 131072;
24 unsigned long fs_cpu_buffer_size = 8192;
25 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
27 static ssize_t depth_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
28 {
29 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
30 }
33 static ssize_t depth_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
34 {
35 unsigned long val;
36 int retval;
38 if (*offset)
39 return -EINVAL;
41 retval = oprofilefs_ulong_from_user(&val, buf, count);
42 if (retval)
43 return retval;
45 retval = oprofile_set_backtrace(val);
47 if (retval)
48 return retval;
49 return count;
50 }
53 static struct file_operations depth_fops = {
54 .read = depth_read,
55 .write = depth_write
56 };
59 static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
60 {
61 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
62 }
65 static struct file_operations pointer_size_fops = {
66 .read = pointer_size_read,
67 };
70 static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
71 {
72 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
73 }
76 static struct file_operations cpu_type_fops = {
77 .read = cpu_type_read,
78 };
81 static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
82 {
83 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
84 }
87 static ssize_t enable_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
88 {
89 unsigned long val;
90 int retval;
92 if (*offset)
93 return -EINVAL;
95 retval = oprofilefs_ulong_from_user(&val, buf, count);
96 if (retval)
97 return retval;
99 if (val)
100 retval = oprofile_start();
101 else
102 oprofile_stop();
104 if (retval)
105 return retval;
106 return count;
107 }
110 static struct file_operations enable_fops = {
111 .read = enable_read,
112 .write = enable_write,
113 };
116 static ssize_t dump_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
117 {
118 wake_up_buffer_waiter();
119 return count;
120 }
123 static struct file_operations dump_fops = {
124 .write = dump_write,
125 };
127 #define TMPBUFSIZE 512
129 static unsigned int adomains = 0;
130 static int active_domains[MAX_OPROF_DOMAINS + 1];
131 static DEFINE_MUTEX(adom_mutex);
133 static ssize_t adomain_write(struct file * file, char const __user * buf,
134 size_t count, loff_t * offset)
135 {
136 char *tmpbuf;
137 char *startp, *endp;
138 int i;
139 unsigned long val;
140 ssize_t retval = count;
142 if (*offset)
143 return -EINVAL;
144 if (count > TMPBUFSIZE - 1)
145 return -EINVAL;
147 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
148 return -ENOMEM;
150 if (copy_from_user(tmpbuf, buf, count)) {
151 kfree(tmpbuf);
152 return -EFAULT;
153 }
154 tmpbuf[count] = 0;
156 mutex_lock(&adom_mutex);
158 startp = tmpbuf;
159 /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
160 for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
161 val = simple_strtoul(startp, &endp, 0);
162 if (endp == startp)
163 break;
164 while (ispunct(*endp) || isspace(*endp))
165 endp++;
166 active_domains[i] = val;
167 if (active_domains[i] != val)
168 /* Overflow, force error below */
169 i = MAX_OPROF_DOMAINS + 1;
170 startp = endp;
171 }
172 /* Force error on trailing junk */
173 adomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
175 kfree(tmpbuf);
177 if (adomains > MAX_OPROF_DOMAINS
178 || oprofile_set_active(active_domains, adomains)) {
179 adomains = 0;
180 retval = -EINVAL;
181 }
183 mutex_unlock(&adom_mutex);
184 return retval;
185 }
187 static ssize_t adomain_read(struct file * file, char __user * buf,
188 size_t count, loff_t * offset)
189 {
190 char * tmpbuf;
191 size_t len;
192 int i;
193 ssize_t retval;
195 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
196 return -ENOMEM;
198 mutex_lock(&adom_mutex);
200 len = 0;
201 for (i = 0; i < adomains; i++)
202 len += snprintf(tmpbuf + len,
203 len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
204 "%u ", active_domains[i]);
205 WARN_ON(len > TMPBUFSIZE);
206 if (len != 0 && len <= TMPBUFSIZE)
207 tmpbuf[len-1] = '\n';
209 mutex_unlock(&adom_mutex);
211 retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
213 kfree(tmpbuf);
214 return retval;
215 }
218 static const struct file_operations active_domain_ops = {
219 .read = adomain_read,
220 .write = adomain_write,
221 };
223 static unsigned int pdomains = 0;
224 static int passive_domains[MAX_OPROF_DOMAINS];
225 static DEFINE_MUTEX(pdom_mutex);
227 static ssize_t pdomain_write(struct file * file, char const __user * buf,
228 size_t count, loff_t * offset)
229 {
230 char *tmpbuf;
231 char *startp, *endp;
232 int i;
233 unsigned long val;
234 ssize_t retval = count;
236 if (*offset)
237 return -EINVAL;
238 if (count > TMPBUFSIZE - 1)
239 return -EINVAL;
241 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
242 return -ENOMEM;
244 if (copy_from_user(tmpbuf, buf, count)) {
245 kfree(tmpbuf);
246 return -EFAULT;
247 }
248 tmpbuf[count] = 0;
250 mutex_lock(&pdom_mutex);
252 startp = tmpbuf;
253 /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
254 for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
255 val = simple_strtoul(startp, &endp, 0);
256 if (endp == startp)
257 break;
258 while (ispunct(*endp) || isspace(*endp))
259 endp++;
260 passive_domains[i] = val;
261 if (passive_domains[i] != val)
262 /* Overflow, force error below */
263 i = MAX_OPROF_DOMAINS + 1;
264 startp = endp;
265 }
266 /* Force error on trailing junk */
267 pdomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
269 kfree(tmpbuf);
271 if (pdomains > MAX_OPROF_DOMAINS
272 || oprofile_set_passive(passive_domains, pdomains)) {
273 pdomains = 0;
274 retval = -EINVAL;
275 }
277 mutex_unlock(&pdom_mutex);
278 return retval;
279 }
281 static ssize_t pdomain_read(struct file * file, char __user * buf,
282 size_t count, loff_t * offset)
283 {
284 char * tmpbuf;
285 size_t len;
286 int i;
287 ssize_t retval;
289 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
290 return -ENOMEM;
292 mutex_lock(&pdom_mutex);
294 len = 0;
295 for (i = 0; i < pdomains; i++)
296 len += snprintf(tmpbuf + len,
297 len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
298 "%u ", passive_domains[i]);
299 WARN_ON(len > TMPBUFSIZE);
300 if (len != 0 && len <= TMPBUFSIZE)
301 tmpbuf[len-1] = '\n';
303 mutex_unlock(&pdom_mutex);
305 retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
307 kfree(tmpbuf);
308 return retval;
309 }
311 static const struct file_operations passive_domain_ops = {
312 .read = pdomain_read,
313 .write = pdomain_write,
314 };
316 void oprofile_create_files(struct super_block * sb, struct dentry * root)
317 {
318 oprofilefs_create_file(sb, root, "enable", &enable_fops);
319 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
320 oprofilefs_create_file(sb, root, "active_domains", &active_domain_ops);
321 oprofilefs_create_file(sb, root, "passive_domains", &passive_domain_ops);
322 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
323 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
324 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
325 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
326 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
327 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
328 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
329 oprofile_create_stats_files(sb, root);
330 if (oprofile_ops.create_files)
331 oprofile_ops.create_files(sb, root);
332 }