]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/oprofile/oprofile_files.c
Oprofile Multiplexing Patch
[mirror_ubuntu-bionic-kernel.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>
1a960b40 12#include <linux/jiffies.h>
1da177e4
LT
13
14#include "event_buffer.h"
15#include "oprofile_stats.h"
16#include "oprof.h"
17
18unsigned long fs_buffer_size = 131072;
19unsigned long fs_cpu_buffer_size = 8192;
20unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
21
1a960b40
JY
22static ssize_t timeout_read(struct file *file, char __user *buf,
23 size_t count, loff_t *offset)
24{
25 return oprofilefs_ulong_to_user(jiffies_to_msecs(timeout_jiffies),
26 buf, count, offset);
27}
28
29
30static ssize_t timeout_write(struct file *file, char const __user *buf,
31 size_t count, loff_t *offset)
32{
33 unsigned long val;
34 int retval;
35
36 if (*offset)
37 return -EINVAL;
38
39 retval = oprofilefs_ulong_from_user(&val, buf, count);
40 if (retval)
41 return retval;
42
43 retval = oprofile_set_timeout(val);
44
45 if (retval)
46 return retval;
47 return count;
48}
49
50static const struct file_operations timeout_fops = {
51 .read = timeout_read,
52 .write = timeout_write,
53};
54
55
9be80c0f 56static ssize_t depth_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
1da177e4
LT
57{
58 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
59}
60
61
9be80c0f 62static ssize_t depth_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
1da177e4
LT
63{
64 unsigned long val;
65 int retval;
66
67 if (*offset)
68 return -EINVAL;
69
70 retval = oprofilefs_ulong_from_user(&val, buf, count);
71 if (retval)
72 return retval;
73
74 retval = oprofile_set_backtrace(val);
75
76 if (retval)
77 return retval;
78 return count;
79}
80
81
d54b1fdb 82static const struct file_operations depth_fops = {
1da177e4
LT
83 .read = depth_read,
84 .write = depth_write
85};
86
87
88static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
89{
90 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
91}
92
93
d54b1fdb 94static const struct file_operations pointer_size_fops = {
1da177e4
LT
95 .read = pointer_size_read,
96};
97
98
99static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
100{
101 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
102}
103
104
d54b1fdb 105static const struct file_operations cpu_type_fops = {
1da177e4
LT
106 .read = cpu_type_read,
107};
108
109
110static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
111{
112 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
113}
114
115
116static ssize_t enable_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
117{
118 unsigned long val;
119 int retval;
120
121 if (*offset)
122 return -EINVAL;
1da177e4
LT
123 retval = oprofilefs_ulong_from_user(&val, buf, count);
124 if (retval)
125 return retval;
1a960b40 126
1da177e4
LT
127 if (val)
128 retval = oprofile_start();
129 else
130 oprofile_stop();
131
132 if (retval)
133 return retval;
134 return count;
135}
136
137
d54b1fdb 138static const struct file_operations enable_fops = {
1da177e4
LT
139 .read = enable_read,
140 .write = enable_write,
141};
142
143
144static ssize_t dump_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
145{
146 wake_up_buffer_waiter();
147 return count;
148}
149
150
d54b1fdb 151static const struct file_operations dump_fops = {
1da177e4
LT
152 .write = dump_write,
153};
154
155void oprofile_create_files(struct super_block * sb, struct dentry * root)
156{
157 oprofilefs_create_file(sb, root, "enable", &enable_fops);
158 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
159 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
160 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
161 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
162 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
163 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
164 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
165 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
1a960b40 166 oprofilefs_create_file(sb, root, "timeout_ms", &timeout_fops);
1da177e4
LT
167 oprofile_create_stats_files(sb, root);
168 if (oprofile_ops.create_files)
169 oprofile_ops.create_files(sb, root);
170}