blob: cc106d503acec3cdb2917ba0ea316e267474f724 [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>
12
13#include "event_buffer.h"
14#include "oprofile_stats.h"
15#include "oprof.h"
Robert Richter6a180372008-10-16 15:01:40 +020016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017unsigned long fs_buffer_size = 131072;
18unsigned long fs_cpu_buffer_size = 8192;
19unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
20
Robert Richter25ad29132008-09-05 17:12:36 +020021static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
23 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
24}
25
26
Robert Richter25ad29132008-09-05 17:12:36 +020027static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
29 unsigned long val;
30 int retval;
31
32 if (*offset)
33 return -EINVAL;
34
35 retval = oprofilefs_ulong_from_user(&val, buf, count);
36 if (retval)
37 return retval;
38
39 retval = oprofile_set_backtrace(val);
40
41 if (retval)
42 return retval;
43 return count;
44}
45
46
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080047static const struct file_operations depth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 .read = depth_read,
49 .write = depth_write
50};
51
Robert Richter6a180372008-10-16 15:01:40 +020052
Robert Richter25ad29132008-09-05 17:12:36 +020053static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
56}
57
58
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080059static const struct file_operations pointer_size_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .read = pointer_size_read,
61};
62
63
Robert Richter25ad29132008-09-05 17:12:36 +020064static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
67}
Robert Richter6a180372008-10-16 15:01:40 +020068
69
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080070static const struct file_operations cpu_type_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 .read = cpu_type_read,
72};
Robert Richter6a180372008-10-16 15:01:40 +020073
74
Robert Richter25ad29132008-09-05 17:12:36 +020075static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
78}
79
80
Robert Richter25ad29132008-09-05 17:12:36 +020081static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 unsigned long val;
84 int retval;
85
86 if (*offset)
87 return -EINVAL;
Robert Richter4c168ea2008-09-24 11:08:52 +020088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 retval = oprofilefs_ulong_from_user(&val, buf, count);
90 if (retval)
91 return retval;
Robert Richter6a180372008-10-16 15:01:40 +020092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (val)
94 retval = oprofile_start();
95 else
96 oprofile_stop();
97
98 if (retval)
99 return retval;
100 return count;
101}
102
Robert Richter6a180372008-10-16 15:01:40 +0200103
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800104static const struct file_operations enable_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .read = enable_read,
106 .write = enable_write,
107};
108
109
Robert Richter25ad29132008-09-05 17:12:36 +0200110static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 wake_up_buffer_waiter();
113 return count;
114}
115
116
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800117static const struct file_operations dump_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .write = dump_write,
119};
Robert Richter6a180372008-10-16 15:01:40 +0200120
Robert Richter25ad29132008-09-05 17:12:36 +0200121void oprofile_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 oprofilefs_create_file(sb, root, "enable", &enable_fops);
124 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
125 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
126 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
127 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
128 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
Robert Richter6a180372008-10-16 15:01:40 +0200129 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
131 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 oprofile_create_stats_files(sb, root);
133 if (oprofile_ops.create_files)
134 oprofile_ops.create_files(sb, root);
135}