blob: d8201998b0b7f8d93b5b7f1a654851374256dff9 [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
Robert Richter37ca5eb2008-12-09 16:56:01 +010017#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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Robert Richter25ad2912008-09-05 17:12:36 +020025static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
27 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
28}
29
30
Robert Richter25ad2912008-09-05 17:12:36 +020031static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
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
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080051static const struct file_operations depth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 .read = depth_read,
53 .write = depth_write
54};
55
Robert Richter6a180372008-10-16 15:01:40 +020056
Robert Richter25ad2912008-09-05 17:12:36 +020057static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
60}
61
62
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080063static const struct file_operations pointer_size_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 .read = pointer_size_read,
65};
66
67
Robert Richter25ad2912008-09-05 17:12:36 +020068static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
71}
Robert Richter6a180372008-10-16 15:01:40 +020072
73
Arjan van de Vend54b1fd2007-02-12 00:55:34 -080074static const struct file_operations cpu_type_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 .read = cpu_type_read,
76};
Robert Richter6a180372008-10-16 15:01:40 +020077
78
Robert Richter25ad2912008-09-05 17:12:36 +020079static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
82}
83
84
Robert Richter25ad2912008-09-05 17:12:36 +020085static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 unsigned long val;
88 int retval;
89
90 if (*offset)
91 return -EINVAL;
Robert Richter4c168ea2008-09-24 11:08:52 +020092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 retval = oprofilefs_ulong_from_user(&val, buf, count);
94 if (retval)
95 return retval;
Robert Richter6a180372008-10-16 15:01:40 +020096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 if (val)
98 retval = oprofile_start();
99 else
100 oprofile_stop();
101
102 if (retval)
103 return retval;
104 return count;
105}
106
Robert Richter6a180372008-10-16 15:01:40 +0200107
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800108static const struct file_operations enable_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .read = enable_read,
110 .write = enable_write,
111};
112
113
Robert Richter25ad2912008-09-05 17:12:36 +0200114static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 wake_up_buffer_waiter();
117 return count;
118}
119
120
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800121static const struct file_operations dump_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .write = dump_write,
123};
Robert Richter6a180372008-10-16 15:01:40 +0200124
Robert Richter25ad2912008-09-05 17:12:36 +0200125void oprofile_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Robert Richter37ca5eb2008-12-09 16:56:01 +0100127 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 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);
Robert Richter6a180372008-10-16 15:01:40 +0200138 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
140 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 oprofile_create_stats_files(sb, root);
142 if (oprofile_ops.create_files)
143 oprofile_ops.create_files(sb, root);
144}