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 = {
129 #define TMPBUFSIZE 512
131 static unsigned int adomains = 0;
132 static int active_domains[MAX_OPROF_DOMAINS + 1];
133 static DEFINE_MUTEX(adom_mutex);
135 static ssize_t adomain_write(struct file * file, char const __user * buf,
136 size_t count, loff_t * offset)
142 ssize_t retval = count;
146 if (count > TMPBUFSIZE - 1)
149 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
152 if (copy_from_user(tmpbuf, buf, count)) {
158 mutex_lock(&adom_mutex);
161 /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
162 for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
163 val = simple_strtoul(startp, &endp, 0);
166 while (ispunct(*endp) || isspace(*endp))
168 active_domains[i] = val;
169 if (active_domains[i] != val)
170 /* Overflow, force error below */
171 i = MAX_OPROF_DOMAINS + 1;
174 /* Force error on trailing junk */
175 adomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
179 if (adomains > MAX_OPROF_DOMAINS
180 || oprofile_set_active(active_domains, adomains)) {
185 mutex_unlock(&adom_mutex);
189 static ssize_t adomain_read(struct file * file, char __user * buf,
190 size_t count, loff_t * offset)
197 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
200 mutex_lock(&adom_mutex);
203 for (i = 0; i < adomains; i++)
204 len += snprintf(tmpbuf + len,
205 len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
206 "%u ", active_domains[i]);
207 WARN_ON(len > TMPBUFSIZE);
208 if (len != 0 && len <= TMPBUFSIZE)
209 tmpbuf[len-1] = '\n';
211 mutex_unlock(&adom_mutex);
213 retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
220 static struct file_operations active_domain_ops = {
221 .read = adomain_read,
222 .write = adomain_write,
225 static unsigned int pdomains = 0;
226 static int passive_domains[MAX_OPROF_DOMAINS];
227 static DEFINE_MUTEX(pdom_mutex);
229 static ssize_t pdomain_write(struct file * file, char const __user * buf,
230 size_t count, loff_t * offset)
236 ssize_t retval = count;
240 if (count > TMPBUFSIZE - 1)
243 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
246 if (copy_from_user(tmpbuf, buf, count)) {
252 mutex_lock(&pdom_mutex);
255 /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
256 for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
257 val = simple_strtoul(startp, &endp, 0);
260 while (ispunct(*endp) || isspace(*endp))
262 passive_domains[i] = val;
263 if (passive_domains[i] != val)
264 /* Overflow, force error below */
265 i = MAX_OPROF_DOMAINS + 1;
268 /* Force error on trailing junk */
269 pdomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
273 if (pdomains > MAX_OPROF_DOMAINS
274 || oprofile_set_passive(passive_domains, pdomains)) {
279 mutex_unlock(&pdom_mutex);
283 static ssize_t pdomain_read(struct file * file, char __user * buf,
284 size_t count, loff_t * offset)
291 if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
294 mutex_lock(&pdom_mutex);
297 for (i = 0; i < pdomains; i++)
298 len += snprintf(tmpbuf + len,
299 len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
300 "%u ", passive_domains[i]);
301 WARN_ON(len > TMPBUFSIZE);
302 if (len != 0 && len <= TMPBUFSIZE)
303 tmpbuf[len-1] = '\n';
305 mutex_unlock(&pdom_mutex);
307 retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
313 static struct file_operations passive_domain_ops = {
314 .read = pdomain_read,
315 .write = pdomain_write,
318 #endif /* CONFIG_XEN */
320 void oprofile_create_files(struct super_block * sb, struct dentry * root)
322 oprofilefs_create_file(sb, root, "enable", &enable_fops);
323 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
325 oprofilefs_create_file(sb, root, "active_domains", &active_domain_ops);
326 oprofilefs_create_file(sb, root, "passive_domains", &passive_domain_ops);
328 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
329 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
330 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
331 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
332 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
333 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
334 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
335 oprofile_create_stats_files(sb, root);
336 if (oprofile_ops.create_files)
337 oprofile_ops.create_files(sb, root);