Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame^] | 12 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "event_buffer.h" |
| 15 | #include "oprofile_stats.h" |
| 16 | #include "oprof.h" |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 17 | |
Robert Richter | bd2172f | 2008-12-16 16:19:54 +0100 | [diff] [blame] | 18 | #define BUFFER_SIZE_DEFAULT 131072 |
| 19 | #define CPU_BUFFER_SIZE_DEFAULT 8192 |
| 20 | #define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */ |
Robert Richter | 37ca5eb | 2008-12-09 16:56:01 +0100 | [diff] [blame] | 21 | |
Robert Richter | bd2172f | 2008-12-16 16:19:54 +0100 | [diff] [blame] | 22 | unsigned long oprofile_buffer_size; |
| 23 | unsigned long oprofile_cpu_buffer_size; |
| 24 | unsigned long oprofile_buffer_watershed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame^] | 26 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
| 27 | |
| 28 | static ssize_t timeout_read(struct file *file, char __user *buf, |
| 29 | size_t count, loff_t *offset) |
| 30 | { |
| 31 | return oprofilefs_ulong_to_user(jiffies_to_msecs(timeout_jiffies), |
| 32 | buf, count, offset); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | static ssize_t timeout_write(struct file *file, char const __user *buf, |
| 37 | size_t count, loff_t *offset) |
| 38 | { |
| 39 | unsigned long val; |
| 40 | int retval; |
| 41 | |
| 42 | if (*offset) |
| 43 | return -EINVAL; |
| 44 | |
| 45 | retval = oprofilefs_ulong_from_user(&val, buf, count); |
| 46 | if (retval) |
| 47 | return retval; |
| 48 | |
| 49 | retval = oprofile_set_timeout(val); |
| 50 | |
| 51 | if (retval) |
| 52 | return retval; |
| 53 | return count; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static const struct file_operations timeout_fops = { |
| 58 | .read = timeout_read, |
| 59 | .write = timeout_write, |
| 60 | }; |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 65 | static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Robert Richter | bd2172f | 2008-12-16 16:19:54 +0100 | [diff] [blame] | 67 | return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count, |
| 68 | offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 72 | static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | unsigned long val; |
| 75 | int retval; |
| 76 | |
| 77 | if (*offset) |
| 78 | return -EINVAL; |
| 79 | |
| 80 | retval = oprofilefs_ulong_from_user(&val, buf, count); |
| 81 | if (retval) |
| 82 | return retval; |
| 83 | |
| 84 | retval = oprofile_set_backtrace(val); |
| 85 | |
| 86 | if (retval) |
| 87 | return retval; |
| 88 | return count; |
| 89 | } |
| 90 | |
| 91 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 92 | static const struct file_operations depth_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | .read = depth_read, |
| 94 | .write = depth_write |
| 95 | }; |
| 96 | |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 97 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 98 | static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
| 100 | return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset); |
| 101 | } |
| 102 | |
| 103 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 104 | static const struct file_operations pointer_size_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .read = pointer_size_read, |
| 106 | }; |
| 107 | |
| 108 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 109 | static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset); |
| 112 | } |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 113 | |
| 114 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 115 | static const struct file_operations cpu_type_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | .read = cpu_type_read, |
| 117 | }; |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 118 | |
| 119 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 120 | static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
| 122 | return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset); |
| 123 | } |
| 124 | |
| 125 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 126 | static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
| 128 | unsigned long val; |
| 129 | int retval; |
| 130 | |
| 131 | if (*offset) |
| 132 | return -EINVAL; |
Robert Richter | 4c168ea | 2008-09-24 11:08:52 +0200 | [diff] [blame] | 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | retval = oprofilefs_ulong_from_user(&val, buf, count); |
| 135 | if (retval) |
| 136 | return retval; |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | if (val) |
| 139 | retval = oprofile_start(); |
| 140 | else |
| 141 | oprofile_stop(); |
| 142 | |
| 143 | if (retval) |
| 144 | return retval; |
| 145 | return count; |
| 146 | } |
| 147 | |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 148 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 149 | static const struct file_operations enable_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | .read = enable_read, |
| 151 | .write = enable_write, |
| 152 | }; |
| 153 | |
| 154 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 155 | static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
| 157 | wake_up_buffer_waiter(); |
| 158 | return count; |
| 159 | } |
| 160 | |
| 161 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 162 | static const struct file_operations dump_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | .write = dump_write, |
| 164 | }; |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 165 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 166 | void oprofile_create_files(struct super_block *sb, struct dentry *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Robert Richter | 37ca5eb | 2008-12-09 16:56:01 +0100 | [diff] [blame] | 168 | /* reinitialize default values */ |
Robert Richter | bd2172f | 2008-12-16 16:19:54 +0100 | [diff] [blame] | 169 | oprofile_buffer_size = BUFFER_SIZE_DEFAULT; |
| 170 | oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT; |
| 171 | oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT; |
Robert Richter | 37ca5eb | 2008-12-09 16:56:01 +0100 | [diff] [blame] | 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | oprofilefs_create_file(sb, root, "enable", &enable_fops); |
| 174 | oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666); |
| 175 | oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); |
Robert Richter | bd2172f | 2008-12-16 16:19:54 +0100 | [diff] [blame] | 176 | oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size); |
| 177 | oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed); |
| 178 | oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size); |
Robert Richter | 6a18037 | 2008-10-16 15:01:40 +0200 | [diff] [blame] | 179 | oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops); |
| 181 | oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops); |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame^] | 182 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
| 183 | oprofilefs_create_file(sb, root, "time_slice", &timeout_fops); |
| 184 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | oprofile_create_stats_files(sb, root); |
| 186 | if (oprofile_ops.create_files) |
| 187 | oprofile_ops.create_files(sb, root); |
| 188 | } |