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