blob: 468ec3e4f8568f676adc7d4c54bd3f0c5dbc36e4 [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 Richter37ca5eb2008-12-09 16:56:01 +010021
Robert Richterbd2172f2008-12-16 16:19:54 +010022unsigned long oprofile_buffer_size;
23unsigned long oprofile_cpu_buffer_size;
24unsigned long oprofile_buffer_watershed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Jason Yeh4d4036e2009-07-08 13:49:38 +020026#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
27
28static ssize_t timeout_read(struct file *file, char __user *buf,
29 size_t count, loff_t *offset)
30{
31 return oprofilefs_ulong_to_user(jiffies_to_msecs(timeout_jiffies),
32 buf, count, offset);
33}
34
35
36static ssize_t timeout_write(struct file *file, char const __user *buf,
37 size_t count, loff_t *offset)
38{
39 unsigned long val;
40 int retval;
41
42 if (*offset)
43 return -EINVAL;
44
45 retval = oprofilefs_ulong_from_user(&val, buf, count);
46 if (retval)
47 return retval;
48
49 retval = oprofile_set_timeout(val);
50
51 if (retval)
52 return retval;
53 return count;
54}
55
56
57static const struct file_operations timeout_fops = {
58 .read = timeout_read,
59 .write = timeout_write,
60};
61
62#endif
63
64
Robert Richter25ad2912008-09-05 17:12:36 +020065static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Robert Richterbd2172f2008-12-16 16:19:54 +010067 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
68 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71
Robert Richter25ad2912008-09-05 17:12:36 +020072static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 unsigned long val;
75 int retval;
76
77 if (*offset)
78 return -EINVAL;
79
80 retval = oprofilefs_ulong_from_user(&val, buf, count);
81 if (retval)
82 return retval;
83
84 retval = oprofile_set_backtrace(val);
85
86 if (retval)
87 return retval;
88 return count;
89}
90
91
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080092static const struct file_operations depth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .read = depth_read,
94 .write = depth_write
95};
96
Robert Richter6a180372008-10-16 15:01:40 +020097
Robert Richter25ad2912008-09-05 17:12:36 +020098static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
100 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
101}
102
103
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800104static const struct file_operations pointer_size_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .read = pointer_size_read,
106};
107
108
Robert Richter25ad2912008-09-05 17:12:36 +0200109static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
112}
Robert Richter6a180372008-10-16 15:01:40 +0200113
114
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800115static const struct file_operations cpu_type_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .read = cpu_type_read,
117};
Robert Richter6a180372008-10-16 15:01:40 +0200118
119
Robert Richter25ad2912008-09-05 17:12:36 +0200120static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
123}
124
125
Robert Richter25ad2912008-09-05 17:12:36 +0200126static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 unsigned long val;
129 int retval;
130
131 if (*offset)
132 return -EINVAL;
Robert Richter4c168ea2008-09-24 11:08:52 +0200133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 retval = oprofilefs_ulong_from_user(&val, buf, count);
135 if (retval)
136 return retval;
Robert Richter6a180372008-10-16 15:01:40 +0200137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (val)
139 retval = oprofile_start();
140 else
141 oprofile_stop();
142
143 if (retval)
144 return retval;
145 return count;
146}
147
Robert Richter6a180372008-10-16 15:01:40 +0200148
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800149static const struct file_operations enable_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 .read = enable_read,
151 .write = enable_write,
152};
153
154
Robert Richter25ad2912008-09-05 17:12:36 +0200155static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 wake_up_buffer_waiter();
158 return count;
159}
160
161
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800162static const struct file_operations dump_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 .write = dump_write,
164};
Robert Richter6a180372008-10-16 15:01:40 +0200165
Robert Richter25ad2912008-09-05 17:12:36 +0200166void oprofile_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Robert Richter37ca5eb2008-12-09 16:56:01 +0100168 /* reinitialize default values */
Robert Richterbd2172f2008-12-16 16:19:54 +0100169 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
170 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
171 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
Robert Richter37ca5eb2008-12-09 16:56:01 +0100172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 oprofilefs_create_file(sb, root, "enable", &enable_fops);
174 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
175 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
Robert Richterbd2172f2008-12-16 16:19:54 +0100176 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
177 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
178 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
Robert Richter6a180372008-10-16 15:01:40 +0200179 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
181 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
Jason Yeh4d4036e2009-07-08 13:49:38 +0200182#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
183 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
184#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 oprofile_create_stats_files(sb, root);
186 if (oprofile_ops.create_files)
187 oprofile_ops.create_files(sb, root);
188}