Merge branch 'cpus4096-for-linus-3' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.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>
12
13#include "event_buffer.h"
14#include "oprofile_stats.h"
15#include "oprof.h"
6a18037d 16
37ca5eb3
RR
17#define FS_BUFFER_SIZE_DEFAULT 131072
18#define FS_CPU_BUFFER_SIZE_DEFAULT 8192
19#define FS_BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
20
21unsigned long fs_buffer_size;
22unsigned long fs_cpu_buffer_size;
23unsigned long fs_buffer_watershed;
1da177e4 24
25ad2913 25static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
26{
27 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
28}
29
30
25ad2913 31static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
1da177e4
LT
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_backtrace(val);
44
45 if (retval)
46 return retval;
47 return count;
48}
49
50
d54b1fdb 51static const struct file_operations depth_fops = {
1da177e4
LT
52 .read = depth_read,
53 .write = depth_write
54};
55
6a18037d 56
25ad2913 57static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
58{
59 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
60}
61
62
d54b1fdb 63static const struct file_operations pointer_size_fops = {
1da177e4
LT
64 .read = pointer_size_read,
65};
66
67
25ad2913 68static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
69{
70 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
71}
6a18037d
RR
72
73
d54b1fdb 74static const struct file_operations cpu_type_fops = {
1da177e4
LT
75 .read = cpu_type_read,
76};
6a18037d
RR
77
78
25ad2913 79static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
1da177e4
LT
80{
81 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
82}
83
84
25ad2913 85static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
1da177e4
LT
86{
87 unsigned long val;
88 int retval;
89
90 if (*offset)
91 return -EINVAL;
4c168eaf 92
1da177e4
LT
93 retval = oprofilefs_ulong_from_user(&val, buf, count);
94 if (retval)
95 return retval;
6a18037d 96
1da177e4
LT
97 if (val)
98 retval = oprofile_start();
99 else
100 oprofile_stop();
101
102 if (retval)
103 return retval;
104 return count;
105}
106
6a18037d 107
d54b1fdb 108static const struct file_operations enable_fops = {
1da177e4
LT
109 .read = enable_read,
110 .write = enable_write,
111};
112
113
25ad2913 114static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
1da177e4
LT
115{
116 wake_up_buffer_waiter();
117 return count;
118}
119
120
d54b1fdb 121static const struct file_operations dump_fops = {
1da177e4
LT
122 .write = dump_write,
123};
6a18037d 124
25ad2913 125void oprofile_create_files(struct super_block *sb, struct dentry *root)
1da177e4 126{
37ca5eb3
RR
127 /* reinitialize default values */
128 fs_buffer_size = FS_BUFFER_SIZE_DEFAULT;
129 fs_cpu_buffer_size = FS_CPU_BUFFER_SIZE_DEFAULT;
130 fs_buffer_watershed = FS_BUFFER_WATERSHED_DEFAULT;
131
1da177e4
LT
132 oprofilefs_create_file(sb, root, "enable", &enable_fops);
133 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
134 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
135 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
136 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
137 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
6a18037d 138 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
1da177e4
LT
139 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
140 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
141 oprofile_create_stats_files(sb, root);
142 if (oprofile_ops.create_files)
143 oprofile_ops.create_files(sb, root);
144}
This page took 0.374185 seconds and 5 git commands to generate.