Merge branch 'simplify_PRT' into release
[linux-2.6] / drivers / oprofile / oprofile_files.c
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>
12
13 #include "event_buffer.h"
14 #include "oprofile_stats.h"
15 #include "oprof.h"
16
17 #define FS_BUFFER_SIZE_DEFAULT          131072
18 #define FS_CPU_BUFFER_SIZE_DEFAULT      8192
19 #define FS_BUFFER_WATERSHED_DEFAULT     32768   /* FIXME: tune */
20
21 unsigned long fs_buffer_size;
22 unsigned long fs_cpu_buffer_size;
23 unsigned long fs_buffer_watershed;
24
25 static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
26 {
27         return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
28 }
29
30
31 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
32 {
33         unsigned long val;
34         int retval;
35
36         if (*offset)
37                 return -EINVAL;
38
39         retval = oprofilefs_ulong_from_user(&val, buf, count);
40         if (retval)
41                 return retval;
42
43         retval = oprofile_set_backtrace(val);
44
45         if (retval)
46                 return retval;
47         return count;
48 }
49
50
51 static const struct file_operations depth_fops = {
52         .read           = depth_read,
53         .write          = depth_write
54 };
55
56
57 static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
58 {
59         return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
60 }
61
62
63 static const struct file_operations pointer_size_fops = {
64         .read           = pointer_size_read,
65 };
66
67
68 static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
69 {
70         return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
71 }
72
73
74 static const struct file_operations cpu_type_fops = {
75         .read           = cpu_type_read,
76 };
77
78
79 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
80 {
81         return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
82 }
83
84
85 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
86 {
87         unsigned long val;
88         int retval;
89
90         if (*offset)
91                 return -EINVAL;
92
93         retval = oprofilefs_ulong_from_user(&val, buf, count);
94         if (retval)
95                 return retval;
96
97         if (val)
98                 retval = oprofile_start();
99         else
100                 oprofile_stop();
101
102         if (retval)
103                 return retval;
104         return count;
105 }
106
107
108 static const struct file_operations enable_fops = {
109         .read           = enable_read,
110         .write          = enable_write,
111 };
112
113
114 static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
115 {
116         wake_up_buffer_waiter();
117         return count;
118 }
119
120
121 static const struct file_operations dump_fops = {
122         .write          = dump_write,
123 };
124
125 void oprofile_create_files(struct super_block *sb, struct dentry *root)
126 {
127         /* reinitialize default values */
128         fs_buffer_size =        FS_BUFFER_SIZE_DEFAULT;
129         fs_cpu_buffer_size =    FS_CPU_BUFFER_SIZE_DEFAULT;
130         fs_buffer_watershed =   FS_BUFFER_WATERSHED_DEFAULT;
131
132         oprofilefs_create_file(sb, root, "enable", &enable_fops);
133         oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
134         oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
135         oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
136         oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
137         oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
138         oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
139         oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
140         oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
141         oprofile_create_stats_files(sb, root);
142         if (oprofile_ops.create_files)
143                 oprofile_ops.create_files(sb, root);
144 }