2 * @file oprofile_files.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
9 * Modified by Aravind Menon for Xen
10 * These modifications are:
11 * Copyright (C) 2005 Hewlett-Packard Co.
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"
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)
29 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
33 static ssize_t depth_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
41 retval = oprofilefs_ulong_from_user(&val, buf, count);
45 retval = oprofile_set_backtrace(val);
53 static struct file_operations depth_fops = {
59 static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
61 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
65 static struct file_operations pointer_size_fops = {
66 .read = pointer_size_read,
70 static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
72 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
76 static struct file_operations cpu_type_fops = {
77 .read = cpu_type_read,
81 static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
83 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
87 static ssize_t enable_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
95 retval = oprofilefs_ulong_from_user(&val, buf, count);
100 retval = oprofile_start();
110 static struct file_operations enable_fops = {
112 .write = enable_write,
116 static ssize_t dump_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
118 wake_up_buffer_waiter();
123 static struct file_operations dump_fops = {
127 #define TMPBUFSIZE 512
130 static unsigned int adomains = 0;
131 static int active_domains[MAX_OPROF_DOMAINS + 1];
132 static DEFINE_MUTEX(adom_mutex);
134 static ssize_t adomain_write(struct file * file, char const __user * buf,
135 size_t count, loff_t * offset)
141 ssize_t retval = count;
145 if (count > TMPBUFSIZE - 1)
148 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
151 if (copy_from_user(tmpbuf, buf, count)) {
157 mutex_lock(&adom_mutex);
160 /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
161 for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
162 val = simple_strtoul(startp, &endp, 0);
165 while (ispunct(*endp) || isspace(*endp))
167 active_domains[i] = val;
168 if (active_domains[i] != val)
169 /* Overflow, force error below */
170 i = MAX_OPROF_DOMAINS + 1;
173 /* Force error on trailing junk */
174 adomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
178 if (adomains > MAX_OPROF_DOMAINS
179 || oprofile_set_active(active_domains, adomains)) {
184 mutex_unlock(&adom_mutex);
188 static ssize_t adomain_read(struct file * file, char __user * buf,
189 size_t count, loff_t * offset)
196 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
199 mutex_lock(&adom_mutex);
202 for (i = 0; i < adomains; i++)
203 len += snprintf(tmpbuf + len,
204 len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
205 "%u ", active_domains[i]);
206 WARN_ON(len > TMPBUFSIZE);
207 if (len != 0 && len <= TMPBUFSIZE)
208 tmpbuf[len-1] = '\n';
210 mutex_unlock(&adom_mutex);
212 retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
219 static struct file_operations active_domain_ops = {
220 .read = adomain_read,
221 .write = adomain_write,
224 static unsigned int pdomains = 0;
225 static int passive_domains[MAX_OPROF_DOMAINS];
226 static DEFINE_MUTEX(pdom_mutex);
228 static ssize_t pdomain_write(struct file * file, char const __user * buf,
229 size_t count, loff_t * offset)
235 ssize_t retval = count;
239 if (count > TMPBUFSIZE - 1)
242 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
245 if (copy_from_user(tmpbuf, buf, count)) {
251 mutex_lock(&pdom_mutex);
254 /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
255 for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
256 val = simple_strtoul(startp, &endp, 0);
259 while (ispunct(*endp) || isspace(*endp))
261 passive_domains[i] = val;
262 if (passive_domains[i] != val)
263 /* Overflow, force error below */
264 i = MAX_OPROF_DOMAINS + 1;
267 /* Force error on trailing junk */
268 pdomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
272 if (pdomains > MAX_OPROF_DOMAINS
273 || oprofile_set_passive(passive_domains, pdomains)) {
278 mutex_unlock(&pdom_mutex);
282 static ssize_t pdomain_read(struct file * file, char __user * buf,
283 size_t count, loff_t * offset)
290 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
293 mutex_lock(&pdom_mutex);
296 for (i = 0; i < pdomains; i++)
297 len += snprintf(tmpbuf + len,
298 len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
299 "%u ", passive_domains[i]);
300 WARN_ON(len > TMPBUFSIZE);
301 if (len != 0 && len <= TMPBUFSIZE)
302 tmpbuf[len-1] = '\n';
304 mutex_unlock(&pdom_mutex);
306 retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
312 static struct file_operations passive_domain_ops = {
313 .read = pdomain_read,
314 .write = pdomain_write,
316 #endif /* CONFIG_XEN */
318 void oprofile_create_files(struct super_block * sb, struct dentry * root)
320 oprofilefs_create_file(sb, root, "enable", &enable_fops);
321 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
323 oprofilefs_create_file(sb, root, "active_domains", &active_domain_ops);
324 oprofilefs_create_file(sb, root, "passive_domains", &passive_domain_ops);
326 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
327 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
328 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
329 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
330 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
331 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
332 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
333 oprofile_create_stats_files(sb, root);
334 if (oprofile_ops.create_files)
335 oprofile_ops.create_files(sb, root);