MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / oprofile / oprofile_files.c
blobb22d4ea3f9b5fbaec721e8efde063049bb487b5d
1 /**
2 * @file oprofile_files.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
8 */
10 #include <linux/fs.h>
11 #include <linux/oprofile.h>
13 #include "event_buffer.h"
14 #include "oprofile_stats.h"
15 #include "oprof.h"
17 unsigned long fs_buffer_size = 131072;
18 unsigned long fs_cpu_buffer_size = 8192;
19 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
22 static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
24 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
28 static struct file_operations pointer_size_fops = {
29 .read = pointer_size_read,
33 static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
35 return oprofilefs_str_to_user(oprofile_ops->cpu_type, buf, count, offset);
39 static struct file_operations cpu_type_fops = {
40 .read = cpu_type_read,
44 static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
46 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
50 static ssize_t enable_write(struct file *file, char const __user * buf, size_t count, loff_t * offset)
52 unsigned long val;
53 int retval;
55 if (*offset)
56 return -EINVAL;
58 retval = oprofilefs_ulong_from_user(&val, buf, count);
59 if (retval)
60 return retval;
62 if (val)
63 retval = oprofile_start();
64 else
65 oprofile_stop();
67 if (retval)
68 return retval;
69 return count;
73 static struct file_operations enable_fops = {
74 .read = enable_read,
75 .write = enable_write,
79 static ssize_t dump_write(struct file *file, char const __user * buf, size_t count, loff_t * offset)
81 wake_up_buffer_waiter();
82 return count;
86 static struct file_operations dump_fops = {
87 .write = dump_write,
90 void oprofile_create_files(struct super_block * sb, struct dentry * root)
92 oprofilefs_create_file(sb, root, "enable", &enable_fops);
93 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
94 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
95 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
96 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
97 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
98 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
99 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
100 oprofile_create_stats_files(sb, root);
101 if (oprofile_ops->create_files)
102 oprofile_ops->create_files(sb, root);