blob: 4c5b9477584441c4e23315de24e95242a911e968 [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;
Robert Richterafe1b50f2009-07-15 15:19:29 +020025unsigned long oprofile_time_slice;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Jason Yeh4d4036e2009-07-08 13:49:38 +020027#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
28
29static ssize_t timeout_read(struct file *file, char __user *buf,
30 size_t count, loff_t *offset)
31{
Robert Richterafe1b50f2009-07-15 15:19:29 +020032 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
33 buf, count, offset);
Jason Yeh4d4036e2009-07-08 13:49:38 +020034}
35
36
37static ssize_t timeout_write(struct file *file, char const __user *buf,
38 size_t count, loff_t *offset)
39{
40 unsigned long val;
41 int retval;
42
43 if (*offset)
44 return -EINVAL;
45
46 retval = oprofilefs_ulong_from_user(&val, buf, count);
47 if (retval)
48 return retval;
49
50 retval = oprofile_set_timeout(val);
51
52 if (retval)
53 return retval;
54 return count;
55}
56
57
58static const struct file_operations timeout_fops = {
59 .read = timeout_read,
60 .write = timeout_write,
61};
62
63#endif
64
65
Robert Richter25ad2912008-09-05 17:12:36 +020066static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Robert Richterbd2172f2008-12-16 16:19:54 +010068 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
69 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
72
Robert Richter25ad2912008-09-05 17:12:36 +020073static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 unsigned long val;
76 int retval;
77
78 if (*offset)
79 return -EINVAL;
80
81 retval = oprofilefs_ulong_from_user(&val, buf, count);
82 if (retval)
83 return retval;
84
85 retval = oprofile_set_backtrace(val);
86
87 if (retval)
88 return retval;
89 return count;
90}
91
92
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080093static const struct file_operations depth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 .read = depth_read,
95 .write = depth_write
96};
97
Robert Richter6a180372008-10-16 15:01:40 +020098
Robert Richter25ad2912008-09-05 17:12:36 +020099static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
102}
103
104
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800105static const struct file_operations pointer_size_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .read = pointer_size_read,
107};
108
109
Robert Richter25ad2912008-09-05 17:12:36 +0200110static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
113}
Robert Richter6a180372008-10-16 15:01:40 +0200114
115
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800116static const struct file_operations cpu_type_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .read = cpu_type_read,
118};
Robert Richter6a180372008-10-16 15:01:40 +0200119
120
Robert Richter25ad2912008-09-05 17:12:36 +0200121static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
124}
125
126
Robert Richter25ad2912008-09-05 17:12:36 +0200127static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 unsigned long val;
130 int retval;
131
132 if (*offset)
133 return -EINVAL;
Robert Richter4c168ea2008-09-24 11:08:52 +0200134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 retval = oprofilefs_ulong_from_user(&val, buf, count);
136 if (retval)
137 return retval;
Robert Richter6a180372008-10-16 15:01:40 +0200138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (val)
140 retval = oprofile_start();
141 else
142 oprofile_stop();
143
144 if (retval)
145 return retval;
146 return count;
147}
148
Robert Richter6a180372008-10-16 15:01:40 +0200149
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800150static const struct file_operations enable_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 .read = enable_read,
152 .write = enable_write,
153};
154
155
Robert Richter25ad2912008-09-05 17:12:36 +0200156static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 wake_up_buffer_waiter();
159 return count;
160}
161
162
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800163static const struct file_operations dump_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 .write = dump_write,
165};
Robert Richter6a180372008-10-16 15:01:40 +0200166
Robert Richter25ad2912008-09-05 17:12:36 +0200167void oprofile_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Robert Richter37ca5eb2008-12-09 16:56:01 +0100169 /* reinitialize default values */
Robert Richterbd2172f2008-12-16 16:19:54 +0100170 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
171 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
172 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
Robert Richter37ca5eb2008-12-09 16:56:01 +0100173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 oprofilefs_create_file(sb, root, "enable", &enable_fops);
175 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
176 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
Robert Richterbd2172f2008-12-16 16:19:54 +0100177 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
178 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
179 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
Robert Richter6a180372008-10-16 15:01:40 +0200180 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
182 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
Jason Yeh4d4036e2009-07-08 13:49:38 +0200183#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
184 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
185#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 oprofile_create_stats_files(sb, root);
187 if (oprofile_ops.create_files)
188 oprofile_ops.create_files(sb, root);
189}