blob: 9bb4d4bdc237be4b5797e4bcea4bcccf70dbfb04 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
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>
Jason Yeh4d4036e2009-07-08 13:49:38 +020012#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "event_buffer.h"
15#include "oprofile_stats.h"
16#include "oprof.h"
Robert Richter6a180372008-10-16 15:01:40 +020017
Robert Richterbd2172f2008-12-16 16:19:54 +010018#define BUFFER_SIZE_DEFAULT 131072
19#define CPU_BUFFER_SIZE_DEFAULT 8192
20#define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
Robert Richter16422a62009-07-15 15:44:18 +020021#define TIME_SLICE_DEFAULT 1
Robert Richter37ca5eb2008-12-09 16:56:01 +010022
Robert Richterbd2172f2008-12-16 16:19:54 +010023unsigned long oprofile_buffer_size;
24unsigned long oprofile_cpu_buffer_size;
25unsigned long oprofile_buffer_watershed;
Robert Richterafe1b50f2009-07-15 15:19:29 +020026unsigned long oprofile_time_slice;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Jason Yeh4d4036e2009-07-08 13:49:38 +020028#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{
Robert Richterafe1b50f2009-07-15 15:19:29 +020033 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
34 buf, count, offset);
Jason Yeh4d4036e2009-07-08 13:49:38 +020035}
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,
Arnd Bergmann6038f372010-08-15 18:52:59 +020062 .llseek = default_llseek,
Jason Yeh4d4036e2009-07-08 13:49:38 +020063};
64
65#endif
66
67
Robert Richter25ad2912008-09-05 17:12:36 +020068static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Robert Richterbd2172f2008-12-16 16:19:54 +010070 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
71 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74
Robert Richter25ad2912008-09-05 17:12:36 +020075static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 unsigned long val;
78 int retval;
79
80 if (*offset)
81 return -EINVAL;
82
83 retval = oprofilefs_ulong_from_user(&val, buf, count);
84 if (retval)
85 return retval;
86
87 retval = oprofile_set_backtrace(val);
88
89 if (retval)
90 return retval;
91 return count;
92}
93
94
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080095static const struct file_operations depth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 .read = depth_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020097 .write = depth_write,
98 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
Robert Richter6a180372008-10-16 15:01:40 +0200101
Robert Richter25ad2912008-09-05 17:12:36 +0200102static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
105}
106
107
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800108static const struct file_operations pointer_size_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .read = pointer_size_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200110 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113
Robert Richter25ad2912008-09-05 17:12:36 +0200114static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
117}
Robert Richter6a180372008-10-16 15:01:40 +0200118
119
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800120static const struct file_operations cpu_type_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .read = cpu_type_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200122 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123};
Robert Richter6a180372008-10-16 15:01:40 +0200124
125
Robert Richter25ad2912008-09-05 17:12:36 +0200126static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
129}
130
131
Robert Richter25ad2912008-09-05 17:12:36 +0200132static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 unsigned long val;
135 int retval;
136
137 if (*offset)
138 return -EINVAL;
Robert Richter4c168ea2008-09-24 11:08:52 +0200139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 retval = oprofilefs_ulong_from_user(&val, buf, count);
141 if (retval)
142 return retval;
Robert Richter6a180372008-10-16 15:01:40 +0200143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 if (val)
145 retval = oprofile_start();
146 else
147 oprofile_stop();
148
149 if (retval)
150 return retval;
151 return count;
152}
153
Robert Richter6a180372008-10-16 15:01:40 +0200154
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800155static const struct file_operations enable_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .read = enable_read,
157 .write = enable_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200158 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161
Robert Richter25ad2912008-09-05 17:12:36 +0200162static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
164 wake_up_buffer_waiter();
165 return count;
166}
167
168
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800169static const struct file_operations dump_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 .write = dump_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200171 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
Robert Richter6a180372008-10-16 15:01:40 +0200173
Robert Richter25ad2912008-09-05 17:12:36 +0200174void oprofile_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Robert Richter37ca5eb2008-12-09 16:56:01 +0100176 /* reinitialize default values */
Robert Richterbd2172f2008-12-16 16:19:54 +0100177 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
178 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
179 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
Robert Richter16422a62009-07-15 15:44:18 +0200180 oprofile_time_slice = msecs_to_jiffies(TIME_SLICE_DEFAULT);
Robert Richter37ca5eb2008-12-09 16:56:01 +0100181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 oprofilefs_create_file(sb, root, "enable", &enable_fops);
183 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
184 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
Robert Richterbd2172f2008-12-16 16:19:54 +0100185 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
186 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
187 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
Robert Richter6a180372008-10-16 15:01:40 +0200188 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
190 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
Jason Yeh4d4036e2009-07-08 13:49:38 +0200191#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
192 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
193#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 oprofile_create_stats_files(sb, root);
195 if (oprofile_ops.create_files)
196 oprofile_ops.create_files(sb, root);
197}