patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / oprofile / oprofile_files.c
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"
16  
17 unsigned long fs_buffer_size = 131072;
18 unsigned long fs_cpu_buffer_size = 8192;
19 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
20
21  
22 static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
23 {
24         return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
25 }
26
27
28 static struct file_operations pointer_size_fops = {
29         .read           = pointer_size_read,
30 };
31
32
33 static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
34 {
35         return oprofilefs_str_to_user(oprofile_ops->cpu_type, buf, count, offset);
36 }
37  
38  
39 static struct file_operations cpu_type_fops = {
40         .read           = cpu_type_read,
41 };
42  
43  
44 static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
45 {
46         return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
47 }
48
49
50 static ssize_t enable_write(struct file *file, char const __user * buf, size_t count, loff_t * offset)
51 {
52         unsigned long val;
53         int retval;
54
55         if (*offset)
56                 return -EINVAL;
57
58         retval = oprofilefs_ulong_from_user(&val, buf, count);
59         if (retval)
60                 return retval;
61  
62         if (val)
63                 retval = oprofile_start();
64         else
65                 oprofile_stop();
66
67         if (retval)
68                 return retval;
69         return count;
70 }
71
72  
73 static struct file_operations enable_fops = {
74         .read           = enable_read,
75         .write          = enable_write,
76 };
77
78
79 static ssize_t dump_write(struct file *file, char const __user * buf, size_t count, loff_t * offset)
80 {
81         wake_up_buffer_waiter();
82         return count;
83 }
84
85
86 static struct file_operations dump_fops = {
87         .write          = dump_write,
88 };
89  
90 void oprofile_create_files(struct super_block * sb, struct dentry * root)
91 {
92         oprofilefs_create_file(sb, root, "enable", &enable_fops);
93         oprofilefs_create_file(sb, root, "dump", &dump_fops);
94         oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
95         oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
96         oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
97         oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
98         oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); 
99         oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
100         oprofile_create_stats_files(sb, root);
101         if (oprofile_ops->create_files)
102                 oprofile_ops->create_files(sb, root);
103 }