blob: bbd7516e0869461c141659004580d509ec5e97a5 [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,
62};
63
64#endif
65
66
Robert Richter25ad29132008-09-05 17:12:36 +020067static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Robert Richterbd2172f2008-12-16 16:19:54 +010069 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
70 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73
Robert Richter25ad29132008-09-05 17:12:36 +020074static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 unsigned long val;
77 int retval;
78
79 if (*offset)
80 return -EINVAL;
81
82 retval = oprofilefs_ulong_from_user(&val, buf, count);
83 if (retval)
84 return retval;
85
86 retval = oprofile_set_backtrace(val);
87
88 if (retval)
89 return retval;
90 return count;
91}
92
93
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080094static const struct file_operations depth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 .read = depth_read,
96 .write = depth_write
97};
98
Robert Richter6a180372008-10-16 15:01:40 +020099
Robert Richter25ad29132008-09-05 17:12:36 +0200100static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
103}
104
105
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800106static const struct file_operations pointer_size_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 .read = pointer_size_read,
108};
109
110
Robert Richter25ad29132008-09-05 17:12:36 +0200111static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
114}
Robert Richter6a180372008-10-16 15:01:40 +0200115
116
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800117static const struct file_operations cpu_type_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .read = cpu_type_read,
119};
Robert Richter6a180372008-10-16 15:01:40 +0200120
121
Robert Richter25ad29132008-09-05 17:12:36 +0200122static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
125}
126
127
Robert Richter25ad29132008-09-05 17:12:36 +0200128static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 unsigned long val;
131 int retval;
132
133 if (*offset)
134 return -EINVAL;
Robert Richter4c168ea2008-09-24 11:08:52 +0200135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 retval = oprofilefs_ulong_from_user(&val, buf, count);
137 if (retval)
138 return retval;
Robert Richter6a180372008-10-16 15:01:40 +0200139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (val)
141 retval = oprofile_start();
142 else
143 oprofile_stop();
144
145 if (retval)
146 return retval;
147 return count;
148}
149
Robert Richter6a180372008-10-16 15:01:40 +0200150
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800151static const struct file_operations enable_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 .read = enable_read,
153 .write = enable_write,
154};
155
156
Robert Richter25ad29132008-09-05 17:12:36 +0200157static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 wake_up_buffer_waiter();
160 return count;
161}
162
163
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800164static const struct file_operations dump_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 .write = dump_write,
166};
Robert Richter6a180372008-10-16 15:01:40 +0200167
Robert Richter25ad29132008-09-05 17:12:36 +0200168void oprofile_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Robert Richter37ca5eb2008-12-09 16:56:01 +0100170 /* reinitialize default values */
Robert Richterbd2172f2008-12-16 16:19:54 +0100171 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
172 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
173 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
Robert Richter16422a62009-07-15 15:44:18 +0200174 oprofile_time_slice = msecs_to_jiffies(TIME_SLICE_DEFAULT);
Robert Richter37ca5eb2008-12-09 16:56:01 +0100175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 oprofilefs_create_file(sb, root, "enable", &enable_fops);
177 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
178 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
Robert Richterbd2172f2008-12-16 16:19:54 +0100179 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
180 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
181 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
Robert Richter6a180372008-10-16 15:01:40 +0200182 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
184 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
Jason Yeh4d4036e2009-07-08 13:49:38 +0200185#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
186 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
187#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 oprofile_create_stats_files(sb, root);
189 if (oprofile_ops.create_files)
190 oprofile_ops.create_files(sb, root);
191}