]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/oprofile/oprofile_files.c
scm: lower SCM_MAX_FD
[net-next-2.6.git] / drivers / oprofile / oprofile_files.c
CommitLineData
1da177e4
LT
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>
4d4036e0 12#include <linux/jiffies.h>
1da177e4
LT
13
14#include "event_buffer.h"
15#include "oprofile_stats.h"
16#include "oprof.h"
6a18037d 17
bd2172f5
RR
18#define BUFFER_SIZE_DEFAULT 131072
19#define CPU_BUFFER_SIZE_DEFAULT 8192
20#define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
16422a6e 21#define TIME_SLICE_DEFAULT 1
37ca5eb3 22
bd2172f5
RR
23unsigned long oprofile_buffer_size;
24unsigned long oprofile_cpu_buffer_size;
25unsigned long oprofile_buffer_watershed;
afe1b50f 26unsigned long oprofile_time_slice;
1da177e4 27
4d4036e0
JY
28#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
29
30static ssize_t timeout_read(struct file *file, char __user *buf,
31 size_t count, loff_t *offset)
32{
afe1b50f
RR
33 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
34 buf, count, offset);
4d4036e0
JY
35}
36
37
38static ssize_t timeout_write(struct file *file, char const __user *buf,
39 size_t count, loff_t *offset)
40{
41 unsigned long val;
42 int retval;
43
44 if (*offset)
45 return -EINVAL;
46
47 retval = oprofilefs_ulong_from_user(&val, buf, count);
48 if (retval)
49 return retval;
50
51 retval = oprofile_set_timeout(val);
52
53 if (retval)
54 return retval;
55 return count;
56}
57
58
59static const struct file_operations timeout_fops = {
60 .read = timeout_read,
61 .write = timeout_write,
6038f373 62 .llseek = default_llseek,
4d4036e0
JY
63};
64
65#endif
66
67
25ad2913 68static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4 69{
bd2172f5
RR
70 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
71 offset);
1da177e4
LT
72}
73
74
25ad2913 75static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
1da177e4
LT
76{
77 unsigned long val;
78 int retval;
79
80 if (*offset)
81 return -EINVAL;
82
7df01d96
RR
83 if (!oprofile_ops.backtrace)
84 return -EINVAL;
85
1da177e4
LT
86 retval = oprofilefs_ulong_from_user(&val, buf, count);
87 if (retval)
88 return retval;
89
7df01d96 90 retval = oprofile_set_ulong(&oprofile_backtrace_depth, val);
1da177e4
LT
91 if (retval)
92 return retval;
7df01d96 93
1da177e4
LT
94 return count;
95}
96
97
d54b1fdb 98static const struct file_operations depth_fops = {
1da177e4 99 .read = depth_read,
6038f373
AB
100 .write = depth_write,
101 .llseek = default_llseek,
1da177e4
LT
102};
103
6a18037d 104
25ad2913 105static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
106{
107 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
108}
109
110
d54b1fdb 111static const struct file_operations pointer_size_fops = {
1da177e4 112 .read = pointer_size_read,
6038f373 113 .llseek = default_llseek,
1da177e4
LT
114};
115
116
25ad2913 117static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
118{
119 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
120}
6a18037d
RR
121
122
d54b1fdb 123static const struct file_operations cpu_type_fops = {
1da177e4 124 .read = cpu_type_read,
6038f373 125 .llseek = default_llseek,
1da177e4 126};
6a18037d
RR
127
128
25ad2913 129static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
130{
131 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
132}
133
134
25ad2913 135static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
1da177e4
LT
136{
137 unsigned long val;
138 int retval;
139
140 if (*offset)
141 return -EINVAL;
4c168eaf 142
1da177e4
LT
143 retval = oprofilefs_ulong_from_user(&val, buf, count);
144 if (retval)
145 return retval;
6a18037d 146
1da177e4
LT
147 if (val)
148 retval = oprofile_start();
149 else
150 oprofile_stop();
151
152 if (retval)
153 return retval;
154 return count;
155}
156
6a18037d 157
d54b1fdb 158static const struct file_operations enable_fops = {
1da177e4
LT
159 .read = enable_read,
160 .write = enable_write,
6038f373 161 .llseek = default_llseek,
1da177e4
LT
162};
163
164
25ad2913 165static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
1da177e4
LT
166{
167 wake_up_buffer_waiter();
168 return count;
169}
170
171
d54b1fdb 172static const struct file_operations dump_fops = {
1da177e4 173 .write = dump_write,
6038f373 174 .llseek = noop_llseek,
1da177e4 175};
6a18037d 176
25ad2913 177void oprofile_create_files(struct super_block *sb, struct dentry *root)
1da177e4 178{
37ca5eb3 179 /* reinitialize default values */
bd2172f5
RR
180 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
181 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
182 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
16422a6e 183 oprofile_time_slice = msecs_to_jiffies(TIME_SLICE_DEFAULT);
37ca5eb3 184
1da177e4
LT
185 oprofilefs_create_file(sb, root, "enable", &enable_fops);
186 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
187 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
bd2172f5
RR
188 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
189 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
190 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
6a18037d 191 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
1da177e4
LT
192 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
193 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
4d4036e0
JY
194#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
195 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
196#endif
1da177e4
LT
197 oprofile_create_stats_files(sb, root);
198 if (oprofile_ops.create_files)
199 oprofile_ops.create_files(sb, root);
200}