Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1 | /* |
| 2 | * event tracer |
| 3 | * |
| 4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 5 | * |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 6 | * - Added format output of fields of the trace point. |
| 7 | * This was based off of work by Tom Zanussi <tzanussi@gmail.com>. |
| 8 | * |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 11 | #include <linux/workqueue.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/kthread.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/uaccess.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 19 | #include <linux/delay.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 20 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 21 | #include <asm/setup.h> |
| 22 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 23 | #include "trace_output.h" |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 24 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 25 | #undef TRACE_SYSTEM |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 26 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| 27 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 28 | DEFINE_MUTEX(event_mutex); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 29 | |
Steven Rostedt | 0429578 | 2010-11-12 22:32:11 -0500 | [diff] [blame] | 30 | DEFINE_MUTEX(event_storage_mutex); |
| 31 | EXPORT_SYMBOL_GPL(event_storage_mutex); |
| 32 | |
| 33 | char event_storage[EVENT_STORAGE_SIZE]; |
| 34 | EXPORT_SYMBOL_GPL(event_storage); |
| 35 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 36 | LIST_HEAD(ftrace_events); |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 37 | static LIST_HEAD(ftrace_common_fields); |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 38 | |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 39 | #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO) |
| 40 | |
| 41 | static struct kmem_cache *field_cachep; |
| 42 | static struct kmem_cache *file_cachep; |
| 43 | |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 44 | #define SYSTEM_FL_FREE_NAME (1 << 31) |
| 45 | |
| 46 | static inline int system_refcount(struct event_subsystem *system) |
| 47 | { |
| 48 | return system->ref_count & ~SYSTEM_FL_FREE_NAME; |
| 49 | } |
| 50 | |
| 51 | static int system_refcount_inc(struct event_subsystem *system) |
| 52 | { |
| 53 | return (system->ref_count++) & ~SYSTEM_FL_FREE_NAME; |
| 54 | } |
| 55 | |
| 56 | static int system_refcount_dec(struct event_subsystem *system) |
| 57 | { |
| 58 | return (--system->ref_count) & ~SYSTEM_FL_FREE_NAME; |
| 59 | } |
| 60 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 61 | /* Double loops, do not use break, only goto's work */ |
| 62 | #define do_for_each_event_file(tr, file) \ |
| 63 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ |
| 64 | list_for_each_entry(file, &tr->events, list) |
| 65 | |
| 66 | #define do_for_each_event_file_safe(tr, file) \ |
| 67 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ |
| 68 | struct ftrace_event_file *___n; \ |
| 69 | list_for_each_entry_safe(file, ___n, &tr->events, list) |
| 70 | |
| 71 | #define while_for_each_event_file() \ |
| 72 | } |
| 73 | |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 74 | static struct list_head * |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 75 | trace_get_fields(struct ftrace_event_call *event_call) |
| 76 | { |
| 77 | if (!event_call->class->get_fields) |
| 78 | return &event_call->class->fields; |
| 79 | return event_call->class->get_fields(event_call); |
| 80 | } |
| 81 | |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 82 | static struct ftrace_event_field * |
| 83 | __find_event_field(struct list_head *head, char *name) |
| 84 | { |
| 85 | struct ftrace_event_field *field; |
| 86 | |
| 87 | list_for_each_entry(field, head, link) { |
| 88 | if (!strcmp(field->name, name)) |
| 89 | return field; |
| 90 | } |
| 91 | |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | struct ftrace_event_field * |
| 96 | trace_find_event_field(struct ftrace_event_call *call, char *name) |
| 97 | { |
| 98 | struct ftrace_event_field *field; |
| 99 | struct list_head *head; |
| 100 | |
| 101 | field = __find_event_field(&ftrace_common_fields, name); |
| 102 | if (field) |
| 103 | return field; |
| 104 | |
| 105 | head = trace_get_fields(call); |
| 106 | return __find_event_field(head, name); |
| 107 | } |
| 108 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 109 | static int __trace_define_field(struct list_head *head, const char *type, |
| 110 | const char *name, int offset, int size, |
| 111 | int is_signed, int filter_type) |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 112 | { |
| 113 | struct ftrace_event_field *field; |
| 114 | |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 115 | field = kmem_cache_alloc(field_cachep, GFP_TRACE); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 116 | if (!field) |
Namhyung Kim | aaf6ac0 | 2013-06-07 15:07:48 +0900 | [diff] [blame] | 117 | return -ENOMEM; |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 118 | |
Steven Rostedt | 92edca0 | 2013-02-27 20:41:37 -0500 | [diff] [blame] | 119 | field->name = name; |
| 120 | field->type = type; |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 121 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 122 | if (filter_type == FILTER_OTHER) |
| 123 | field->filter_type = filter_assign_type(type); |
| 124 | else |
| 125 | field->filter_type = filter_type; |
| 126 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 127 | field->offset = offset; |
| 128 | field->size = size; |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 129 | field->is_signed = is_signed; |
Li Zefan | aa38e9f | 2009-08-07 10:33:02 +0800 | [diff] [blame] | 130 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 131 | list_add(&field->link, head); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 132 | |
| 133 | return 0; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 134 | } |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 135 | |
| 136 | int trace_define_field(struct ftrace_event_call *call, const char *type, |
| 137 | const char *name, int offset, int size, int is_signed, |
| 138 | int filter_type) |
| 139 | { |
| 140 | struct list_head *head; |
| 141 | |
| 142 | if (WARN_ON(!call->class)) |
| 143 | return 0; |
| 144 | |
| 145 | head = trace_get_fields(call); |
| 146 | return __trace_define_field(head, type, name, offset, size, |
| 147 | is_signed, filter_type); |
| 148 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 149 | EXPORT_SYMBOL_GPL(trace_define_field); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 150 | |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 151 | #define __common_field(type, item) \ |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 152 | ret = __trace_define_field(&ftrace_common_fields, #type, \ |
| 153 | "common_" #item, \ |
| 154 | offsetof(typeof(ent), item), \ |
| 155 | sizeof(ent.item), \ |
| 156 | is_signed_type(type), FILTER_OTHER); \ |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 157 | if (ret) \ |
| 158 | return ret; |
| 159 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 160 | static int trace_define_common_fields(void) |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 161 | { |
| 162 | int ret; |
| 163 | struct trace_entry ent; |
| 164 | |
| 165 | __common_field(unsigned short, type); |
| 166 | __common_field(unsigned char, flags); |
| 167 | __common_field(unsigned char, preempt_count); |
| 168 | __common_field(int, pid); |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 169 | |
| 170 | return ret; |
| 171 | } |
| 172 | |
zhangwei(Jovi) | ad7067c | 2013-03-11 15:13:46 +0800 | [diff] [blame] | 173 | static void trace_destroy_fields(struct ftrace_event_call *call) |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 174 | { |
| 175 | struct ftrace_event_field *field, *next; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 176 | struct list_head *head; |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 177 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 178 | head = trace_get_fields(call); |
| 179 | list_for_each_entry_safe(field, next, head, link) { |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 180 | list_del(&field->link); |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 181 | kmem_cache_free(field_cachep, field); |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 185 | int trace_event_raw_init(struct ftrace_event_call *call) |
| 186 | { |
| 187 | int id; |
| 188 | |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 189 | id = register_ftrace_event(&call->event); |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 190 | if (!id) |
| 191 | return -ENODEV; |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | EXPORT_SYMBOL_GPL(trace_event_raw_init); |
| 196 | |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 197 | int ftrace_event_reg(struct ftrace_event_call *call, |
| 198 | enum trace_reg type, void *data) |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 199 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 200 | struct ftrace_event_file *file = data; |
| 201 | |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 202 | switch (type) { |
| 203 | case TRACE_REG_REGISTER: |
| 204 | return tracepoint_probe_register(call->name, |
| 205 | call->class->probe, |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 206 | file); |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 207 | case TRACE_REG_UNREGISTER: |
| 208 | tracepoint_probe_unregister(call->name, |
| 209 | call->class->probe, |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 210 | file); |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 211 | return 0; |
| 212 | |
| 213 | #ifdef CONFIG_PERF_EVENTS |
| 214 | case TRACE_REG_PERF_REGISTER: |
| 215 | return tracepoint_probe_register(call->name, |
| 216 | call->class->perf_probe, |
| 217 | call); |
| 218 | case TRACE_REG_PERF_UNREGISTER: |
| 219 | tracepoint_probe_unregister(call->name, |
| 220 | call->class->perf_probe, |
| 221 | call); |
| 222 | return 0; |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 223 | case TRACE_REG_PERF_OPEN: |
| 224 | case TRACE_REG_PERF_CLOSE: |
Jiri Olsa | 489c75c | 2012-02-15 15:51:50 +0100 | [diff] [blame] | 225 | case TRACE_REG_PERF_ADD: |
| 226 | case TRACE_REG_PERF_DEL: |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 227 | return 0; |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 228 | #endif |
| 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | EXPORT_SYMBOL_GPL(ftrace_event_reg); |
| 233 | |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 234 | void trace_event_enable_cmd_record(bool enable) |
| 235 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 236 | struct ftrace_event_file *file; |
| 237 | struct trace_array *tr; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 238 | |
| 239 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 240 | do_for_each_event_file(tr, file) { |
| 241 | |
| 242 | if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 243 | continue; |
| 244 | |
| 245 | if (enable) { |
| 246 | tracing_start_cmdline_record(); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 247 | set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 248 | } else { |
| 249 | tracing_stop_cmdline_record(); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 250 | clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 251 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 252 | } while_for_each_event_file(); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 253 | mutex_unlock(&event_mutex); |
| 254 | } |
| 255 | |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 256 | static int __ftrace_event_enable_disable(struct ftrace_event_file *file, |
| 257 | int enable, int soft_disable) |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 258 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 259 | struct ftrace_event_call *call = file->event_call; |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 260 | int ret = 0; |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 261 | int disable; |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 262 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 263 | switch (enable) { |
| 264 | case 0: |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 265 | /* |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 266 | * When soft_disable is set and enable is cleared, the sm_ref |
| 267 | * reference counter is decremented. If it reaches 0, we want |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 268 | * to clear the SOFT_DISABLED flag but leave the event in the |
| 269 | * state that it was. That is, if the event was enabled and |
| 270 | * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED |
| 271 | * is set we do not want the event to be enabled before we |
| 272 | * clear the bit. |
| 273 | * |
| 274 | * When soft_disable is not set but the SOFT_MODE flag is, |
| 275 | * we do nothing. Do not disable the tracepoint, otherwise |
| 276 | * "soft enable"s (clearing the SOFT_DISABLED bit) wont work. |
| 277 | */ |
| 278 | if (soft_disable) { |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 279 | if (atomic_dec_return(&file->sm_ref) > 0) |
| 280 | break; |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 281 | disable = file->flags & FTRACE_EVENT_FL_SOFT_DISABLED; |
| 282 | clear_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags); |
| 283 | } else |
| 284 | disable = !(file->flags & FTRACE_EVENT_FL_SOFT_MODE); |
| 285 | |
| 286 | if (disable && (file->flags & FTRACE_EVENT_FL_ENABLED)) { |
| 287 | clear_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 288 | if (file->flags & FTRACE_EVENT_FL_RECORDED_CMD) { |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 289 | tracing_stop_cmdline_record(); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 290 | clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 291 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 292 | call->class->reg(call, TRACE_REG_UNREGISTER, file); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 293 | } |
Tom Zanussi | 3baa5e4 | 2013-06-29 00:08:07 -0500 | [diff] [blame] | 294 | /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */ |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 295 | if (file->flags & FTRACE_EVENT_FL_SOFT_MODE) |
| 296 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); |
Tom Zanussi | 3baa5e4 | 2013-06-29 00:08:07 -0500 | [diff] [blame] | 297 | else |
| 298 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 299 | break; |
| 300 | case 1: |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 301 | /* |
| 302 | * When soft_disable is set and enable is set, we want to |
| 303 | * register the tracepoint for the event, but leave the event |
| 304 | * as is. That means, if the event was already enabled, we do |
| 305 | * nothing (but set SOFT_MODE). If the event is disabled, we |
| 306 | * set SOFT_DISABLED before enabling the event tracepoint, so |
| 307 | * it still seems to be disabled. |
| 308 | */ |
| 309 | if (!soft_disable) |
| 310 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 311 | else { |
| 312 | if (atomic_inc_return(&file->sm_ref) > 1) |
| 313 | break; |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 314 | set_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags); |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 315 | } |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 316 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 317 | if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) { |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 318 | |
| 319 | /* Keep the event disabled, when going to SOFT_MODE. */ |
| 320 | if (soft_disable) |
| 321 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); |
| 322 | |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 323 | if (trace_flags & TRACE_ITER_RECORD_CMD) { |
| 324 | tracing_start_cmdline_record(); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 325 | set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 326 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 327 | ret = call->class->reg(call, TRACE_REG_REGISTER, file); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 328 | if (ret) { |
| 329 | tracing_stop_cmdline_record(); |
| 330 | pr_info("event trace: Could not enable event " |
| 331 | "%s\n", call->name); |
| 332 | break; |
| 333 | } |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 334 | set_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags); |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 335 | |
| 336 | /* WAS_ENABLED gets set but never cleared. */ |
| 337 | call->flags |= TRACE_EVENT_FL_WAS_ENABLED; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 338 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 339 | break; |
| 340 | } |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 341 | |
| 342 | return ret; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 343 | } |
| 344 | |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 345 | static int ftrace_event_enable_disable(struct ftrace_event_file *file, |
| 346 | int enable) |
| 347 | { |
| 348 | return __ftrace_event_enable_disable(file, enable, 0); |
| 349 | } |
| 350 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 351 | static void ftrace_clear_events(struct trace_array *tr) |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 352 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 353 | struct ftrace_event_file *file; |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 354 | |
| 355 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 356 | list_for_each_entry(file, &tr->events, list) { |
| 357 | ftrace_event_enable_disable(file, 0); |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 358 | } |
| 359 | mutex_unlock(&event_mutex); |
| 360 | } |
| 361 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 362 | static void __put_system(struct event_subsystem *system) |
| 363 | { |
| 364 | struct event_filter *filter = system->filter; |
| 365 | |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 366 | WARN_ON_ONCE(system_refcount(system) == 0); |
| 367 | if (system_refcount_dec(system)) |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 368 | return; |
| 369 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 370 | list_del(&system->list); |
| 371 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 372 | if (filter) { |
| 373 | kfree(filter->filter_string); |
| 374 | kfree(filter); |
| 375 | } |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 376 | if (system->ref_count & SYSTEM_FL_FREE_NAME) |
| 377 | kfree(system->name); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 378 | kfree(system); |
| 379 | } |
| 380 | |
| 381 | static void __get_system(struct event_subsystem *system) |
| 382 | { |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 383 | WARN_ON_ONCE(system_refcount(system) == 0); |
| 384 | system_refcount_inc(system); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 385 | } |
| 386 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 387 | static void __get_system_dir(struct ftrace_subsystem_dir *dir) |
| 388 | { |
| 389 | WARN_ON_ONCE(dir->ref_count == 0); |
| 390 | dir->ref_count++; |
| 391 | __get_system(dir->subsystem); |
| 392 | } |
| 393 | |
| 394 | static void __put_system_dir(struct ftrace_subsystem_dir *dir) |
| 395 | { |
| 396 | WARN_ON_ONCE(dir->ref_count == 0); |
| 397 | /* If the subsystem is about to be freed, the dir must be too */ |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 398 | WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 399 | |
| 400 | __put_system(dir->subsystem); |
| 401 | if (!--dir->ref_count) |
| 402 | kfree(dir); |
| 403 | } |
| 404 | |
| 405 | static void put_system(struct ftrace_subsystem_dir *dir) |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 406 | { |
| 407 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 408 | __put_system_dir(dir); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 409 | mutex_unlock(&event_mutex); |
| 410 | } |
| 411 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 412 | /* |
| 413 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. |
| 414 | */ |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 415 | static int __ftrace_set_clr_event(struct trace_array *tr, const char *match, |
| 416 | const char *sub, const char *event, int set) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 417 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 418 | struct ftrace_event_file *file; |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 419 | struct ftrace_event_call *call; |
Steven Rostedt | 29f9394 | 2009-05-08 16:06:47 -0400 | [diff] [blame] | 420 | int ret = -EINVAL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 421 | |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 422 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 423 | list_for_each_entry(file, &tr->events, list) { |
| 424 | |
| 425 | call = file->event_call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 426 | |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 427 | if (!call->name || !call->class || !call->class->reg) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 428 | continue; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 429 | |
Steven Rostedt | 9b63776 | 2012-05-10 15:55:43 -0400 | [diff] [blame] | 430 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) |
| 431 | continue; |
| 432 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 433 | if (match && |
| 434 | strcmp(match, call->name) != 0 && |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 435 | strcmp(match, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 436 | continue; |
| 437 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 438 | if (sub && strcmp(sub, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 439 | continue; |
| 440 | |
| 441 | if (event && strcmp(event, call->name) != 0) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 442 | continue; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 443 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 444 | ftrace_event_enable_disable(file, set); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 445 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 446 | ret = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 447 | } |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 448 | mutex_unlock(&event_mutex); |
| 449 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 450 | return ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 451 | } |
| 452 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 453 | static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set) |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 454 | { |
| 455 | char *event = NULL, *sub = NULL, *match; |
| 456 | |
| 457 | /* |
| 458 | * The buf format can be <subsystem>:<event-name> |
| 459 | * *:<event-name> means any event by that name. |
| 460 | * :<event-name> is the same. |
| 461 | * |
| 462 | * <subsystem>:* means all events in that subsystem |
| 463 | * <subsystem>: means the same. |
| 464 | * |
| 465 | * <name> (no ':') means all events in a subsystem with |
| 466 | * the name <name> or any event that matches <name> |
| 467 | */ |
| 468 | |
| 469 | match = strsep(&buf, ":"); |
| 470 | if (buf) { |
| 471 | sub = match; |
| 472 | event = buf; |
| 473 | match = NULL; |
| 474 | |
| 475 | if (!strlen(sub) || strcmp(sub, "*") == 0) |
| 476 | sub = NULL; |
| 477 | if (!strlen(event) || strcmp(event, "*") == 0) |
| 478 | event = NULL; |
| 479 | } |
| 480 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 481 | return __ftrace_set_clr_event(tr, match, sub, event, set); |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 482 | } |
| 483 | |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 484 | /** |
| 485 | * trace_set_clr_event - enable or disable an event |
| 486 | * @system: system name to match (NULL for any system) |
| 487 | * @event: event name to match (NULL for all events, within system) |
| 488 | * @set: 1 to enable, 0 to disable |
| 489 | * |
| 490 | * This is a way for other parts of the kernel to enable or disable |
| 491 | * event recording. |
| 492 | * |
| 493 | * Returns 0 on success, -EINVAL if the parameters do not match any |
| 494 | * registered events. |
| 495 | */ |
| 496 | int trace_set_clr_event(const char *system, const char *event, int set) |
| 497 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 498 | struct trace_array *tr = top_trace_array(); |
| 499 | |
| 500 | return __ftrace_set_clr_event(tr, NULL, system, event, set); |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 501 | } |
Yuanhan Liu | 56355b8 | 2010-11-08 14:05:12 +0800 | [diff] [blame] | 502 | EXPORT_SYMBOL_GPL(trace_set_clr_event); |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 503 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 504 | /* 128 should be much more than enough */ |
| 505 | #define EVENT_BUF_SIZE 127 |
| 506 | |
| 507 | static ssize_t |
| 508 | ftrace_event_write(struct file *file, const char __user *ubuf, |
| 509 | size_t cnt, loff_t *ppos) |
| 510 | { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 511 | struct trace_parser parser; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 512 | struct seq_file *m = file->private_data; |
| 513 | struct trace_array *tr = m->private; |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 514 | ssize_t read, ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 515 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 516 | if (!cnt) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 517 | return 0; |
| 518 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 519 | ret = tracing_update_buffers(); |
| 520 | if (ret < 0) |
| 521 | return ret; |
| 522 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 523 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 524 | return -ENOMEM; |
| 525 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 526 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 527 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 528 | if (read >= 0 && trace_parser_loaded((&parser))) { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 529 | int set = 1; |
| 530 | |
| 531 | if (*parser.buffer == '!') |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 532 | set = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 533 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 534 | parser.buffer[parser.idx] = 0; |
| 535 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 536 | ret = ftrace_set_clr_event(tr, parser.buffer + !set, set); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 537 | if (ret) |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 538 | goto out_put; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 539 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 540 | |
| 541 | ret = read; |
| 542 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 543 | out_put: |
| 544 | trace_parser_put(&parser); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 545 | |
| 546 | return ret; |
| 547 | } |
| 548 | |
| 549 | static void * |
| 550 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 551 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 552 | struct ftrace_event_file *file = v; |
| 553 | struct ftrace_event_call *call; |
| 554 | struct trace_array *tr = m->private; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 555 | |
| 556 | (*pos)++; |
| 557 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 558 | list_for_each_entry_continue(file, &tr->events, list) { |
| 559 | call = file->event_call; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 560 | /* |
| 561 | * The ftrace subsystem is for showing formats only. |
| 562 | * They can not be enabled or disabled via the event files. |
| 563 | */ |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 564 | if (call->class && call->class->reg) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 565 | return file; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 566 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 567 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 568 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 572 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 573 | struct ftrace_event_file *file; |
| 574 | struct trace_array *tr = m->private; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 575 | loff_t l; |
| 576 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 577 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 578 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 579 | file = list_entry(&tr->events, struct ftrace_event_file, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 580 | for (l = 0; l <= *pos; ) { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 581 | file = t_next(m, file, &l); |
| 582 | if (!file) |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 583 | break; |
| 584 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 585 | return file; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | static void * |
| 589 | s_next(struct seq_file *m, void *v, loff_t *pos) |
| 590 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 591 | struct ftrace_event_file *file = v; |
| 592 | struct trace_array *tr = m->private; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 593 | |
| 594 | (*pos)++; |
| 595 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 596 | list_for_each_entry_continue(file, &tr->events, list) { |
| 597 | if (file->flags & FTRACE_EVENT_FL_ENABLED) |
| 598 | return file; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 599 | } |
| 600 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 601 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 605 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 606 | struct ftrace_event_file *file; |
| 607 | struct trace_array *tr = m->private; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 608 | loff_t l; |
| 609 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 610 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 611 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 612 | file = list_entry(&tr->events, struct ftrace_event_file, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 613 | for (l = 0; l <= *pos; ) { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 614 | file = s_next(m, file, &l); |
| 615 | if (!file) |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 616 | break; |
| 617 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 618 | return file; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static int t_show(struct seq_file *m, void *v) |
| 622 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 623 | struct ftrace_event_file *file = v; |
| 624 | struct ftrace_event_call *call = file->event_call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 625 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 626 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
| 627 | seq_printf(m, "%s:", call->class->system); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 628 | seq_printf(m, "%s\n", call->name); |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static void t_stop(struct seq_file *m, void *p) |
| 634 | { |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 635 | mutex_unlock(&event_mutex); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 636 | } |
| 637 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 638 | static ssize_t |
| 639 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 640 | loff_t *ppos) |
| 641 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 642 | struct ftrace_event_file *file = filp->private_data; |
Tom Zanussi | a439059 | 2013-06-29 00:08:04 -0500 | [diff] [blame] | 643 | char buf[4] = "0"; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 644 | |
Tom Zanussi | a439059 | 2013-06-29 00:08:04 -0500 | [diff] [blame] | 645 | if (file->flags & FTRACE_EVENT_FL_ENABLED && |
| 646 | !(file->flags & FTRACE_EVENT_FL_SOFT_DISABLED)) |
| 647 | strcpy(buf, "1"); |
| 648 | |
| 649 | if (file->flags & FTRACE_EVENT_FL_SOFT_DISABLED || |
| 650 | file->flags & FTRACE_EVENT_FL_SOFT_MODE) |
| 651 | strcat(buf, "*"); |
| 652 | |
| 653 | strcat(buf, "\n"); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 654 | |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 655 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf)); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | static ssize_t |
| 659 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 660 | loff_t *ppos) |
| 661 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 662 | struct ftrace_event_file *file = filp->private_data; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 663 | unsigned long val; |
| 664 | int ret; |
| 665 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 666 | if (!file) |
| 667 | return -EINVAL; |
| 668 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 669 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 670 | if (ret) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 671 | return ret; |
| 672 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 673 | ret = tracing_update_buffers(); |
| 674 | if (ret < 0) |
| 675 | return ret; |
| 676 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 677 | switch (val) { |
| 678 | case 0: |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 679 | case 1: |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 680 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 681 | ret = ftrace_event_enable_disable(file, val); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 682 | mutex_unlock(&event_mutex); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | default: |
| 686 | return -EINVAL; |
| 687 | } |
| 688 | |
| 689 | *ppos += cnt; |
| 690 | |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 691 | return ret ? ret : cnt; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 692 | } |
| 693 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 694 | static ssize_t |
| 695 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 696 | loff_t *ppos) |
| 697 | { |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 698 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 699 | struct ftrace_subsystem_dir *dir = filp->private_data; |
| 700 | struct event_subsystem *system = dir->subsystem; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 701 | struct ftrace_event_call *call; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 702 | struct ftrace_event_file *file; |
| 703 | struct trace_array *tr = dir->tr; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 704 | char buf[2]; |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 705 | int set = 0; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 706 | int ret; |
| 707 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 708 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 709 | list_for_each_entry(file, &tr->events, list) { |
| 710 | call = file->event_call; |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 711 | if (!call->name || !call->class || !call->class->reg) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 712 | continue; |
| 713 | |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 714 | if (system && strcmp(call->class->system, system->name) != 0) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 715 | continue; |
| 716 | |
| 717 | /* |
| 718 | * We need to find out if all the events are set |
| 719 | * or if all events or cleared, or if we have |
| 720 | * a mixture. |
| 721 | */ |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 722 | set |= (1 << !!(file->flags & FTRACE_EVENT_FL_ENABLED)); |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 723 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 724 | /* |
| 725 | * If we have a mixture, no need to look further. |
| 726 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 727 | if (set == 3) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 728 | break; |
| 729 | } |
| 730 | mutex_unlock(&event_mutex); |
| 731 | |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 732 | buf[0] = set_to_char[set]; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 733 | buf[1] = '\n'; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 734 | |
| 735 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 736 | |
| 737 | return ret; |
| 738 | } |
| 739 | |
| 740 | static ssize_t |
| 741 | system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 742 | loff_t *ppos) |
| 743 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 744 | struct ftrace_subsystem_dir *dir = filp->private_data; |
| 745 | struct event_subsystem *system = dir->subsystem; |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 746 | const char *name = NULL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 747 | unsigned long val; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 748 | ssize_t ret; |
| 749 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 750 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 751 | if (ret) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 752 | return ret; |
| 753 | |
| 754 | ret = tracing_update_buffers(); |
| 755 | if (ret < 0) |
| 756 | return ret; |
| 757 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 758 | if (val != 0 && val != 1) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 759 | return -EINVAL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 760 | |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 761 | /* |
| 762 | * Opening of "enable" adds a ref count to system, |
| 763 | * so the name is safe to use. |
| 764 | */ |
| 765 | if (system) |
| 766 | name = system->name; |
| 767 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 768 | ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 769 | if (ret) |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 770 | goto out; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 771 | |
| 772 | ret = cnt; |
| 773 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 774 | out: |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 775 | *ppos += cnt; |
| 776 | |
| 777 | return ret; |
| 778 | } |
| 779 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 780 | enum { |
| 781 | FORMAT_HEADER = 1, |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 782 | FORMAT_FIELD_SEPERATOR = 2, |
| 783 | FORMAT_PRINTFMT = 3, |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 784 | }; |
| 785 | |
| 786 | static void *f_next(struct seq_file *m, void *v, loff_t *pos) |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 787 | { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 788 | struct ftrace_event_call *call = m->private; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 789 | struct ftrace_event_field *field; |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 790 | struct list_head *common_head = &ftrace_common_fields; |
| 791 | struct list_head *head = trace_get_fields(call); |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 792 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 793 | (*pos)++; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 794 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 795 | switch ((unsigned long)v) { |
| 796 | case FORMAT_HEADER: |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 797 | if (unlikely(list_empty(common_head))) |
| 798 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 799 | |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 800 | field = list_entry(common_head->prev, |
| 801 | struct ftrace_event_field, link); |
| 802 | return field; |
| 803 | |
| 804 | case FORMAT_FIELD_SEPERATOR: |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 805 | if (unlikely(list_empty(head))) |
| 806 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 807 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 808 | field = list_entry(head->prev, struct ftrace_event_field, link); |
| 809 | return field; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 810 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 811 | case FORMAT_PRINTFMT: |
| 812 | /* all done */ |
| 813 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 814 | } |
| 815 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 816 | field = v; |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 817 | if (field->link.prev == common_head) |
| 818 | return (void *)FORMAT_FIELD_SEPERATOR; |
| 819 | else if (field->link.prev == head) |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 820 | return (void *)FORMAT_PRINTFMT; |
| 821 | |
| 822 | field = list_entry(field->link.prev, struct ftrace_event_field, link); |
| 823 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 824 | return field; |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 825 | } |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 826 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 827 | static void *f_start(struct seq_file *m, loff_t *pos) |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 828 | { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 829 | loff_t l = 0; |
| 830 | void *p; |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 831 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 832 | /* Start by showing the header */ |
| 833 | if (!*pos) |
| 834 | return (void *)FORMAT_HEADER; |
| 835 | |
| 836 | p = (void *)FORMAT_HEADER; |
| 837 | do { |
| 838 | p = f_next(m, p, &l); |
| 839 | } while (p && l < *pos); |
| 840 | |
| 841 | return p; |
| 842 | } |
| 843 | |
| 844 | static int f_show(struct seq_file *m, void *v) |
| 845 | { |
| 846 | struct ftrace_event_call *call = m->private; |
| 847 | struct ftrace_event_field *field; |
| 848 | const char *array_descriptor; |
| 849 | |
| 850 | switch ((unsigned long)v) { |
| 851 | case FORMAT_HEADER: |
| 852 | seq_printf(m, "name: %s\n", call->name); |
| 853 | seq_printf(m, "ID: %d\n", call->event.type); |
| 854 | seq_printf(m, "format:\n"); |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 855 | return 0; |
| 856 | |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 857 | case FORMAT_FIELD_SEPERATOR: |
| 858 | seq_putc(m, '\n'); |
| 859 | return 0; |
| 860 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 861 | case FORMAT_PRINTFMT: |
| 862 | seq_printf(m, "\nprint fmt: %s\n", |
| 863 | call->print_fmt); |
| 864 | return 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 865 | } |
| 866 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 867 | field = v; |
| 868 | |
| 869 | /* |
| 870 | * Smartly shows the array type(except dynamic array). |
| 871 | * Normal: |
| 872 | * field:TYPE VAR |
| 873 | * If TYPE := TYPE[LEN], it is shown: |
| 874 | * field:TYPE VAR[LEN] |
| 875 | */ |
| 876 | array_descriptor = strchr(field->type, '['); |
| 877 | |
| 878 | if (!strncmp(field->type, "__data_loc", 10)) |
| 879 | array_descriptor = NULL; |
| 880 | |
| 881 | if (!array_descriptor) |
| 882 | seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", |
| 883 | field->type, field->name, field->offset, |
| 884 | field->size, !!field->is_signed); |
| 885 | else |
| 886 | seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", |
| 887 | (int)(array_descriptor - field->type), |
| 888 | field->type, field->name, |
| 889 | array_descriptor, field->offset, |
| 890 | field->size, !!field->is_signed); |
| 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | static void f_stop(struct seq_file *m, void *p) |
| 896 | { |
| 897 | } |
| 898 | |
| 899 | static const struct seq_operations trace_format_seq_ops = { |
| 900 | .start = f_start, |
| 901 | .next = f_next, |
| 902 | .stop = f_stop, |
| 903 | .show = f_show, |
| 904 | }; |
| 905 | |
| 906 | static int trace_format_open(struct inode *inode, struct file *file) |
| 907 | { |
| 908 | struct ftrace_event_call *call = inode->i_private; |
| 909 | struct seq_file *m; |
| 910 | int ret; |
| 911 | |
| 912 | ret = seq_open(file, &trace_format_seq_ops); |
| 913 | if (ret < 0) |
| 914 | return ret; |
| 915 | |
| 916 | m = file->private_data; |
| 917 | m->private = call; |
| 918 | |
| 919 | return 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 920 | } |
| 921 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 922 | static ssize_t |
| 923 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 924 | { |
| 925 | struct ftrace_event_call *call = filp->private_data; |
| 926 | struct trace_seq *s; |
| 927 | int r; |
| 928 | |
| 929 | if (*ppos) |
| 930 | return 0; |
| 931 | |
| 932 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 933 | if (!s) |
| 934 | return -ENOMEM; |
| 935 | |
| 936 | trace_seq_init(s); |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 937 | trace_seq_printf(s, "%d\n", call->event.type); |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 938 | |
| 939 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 940 | s->buffer, s->len); |
| 941 | kfree(s); |
| 942 | return r; |
| 943 | } |
| 944 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 945 | static ssize_t |
| 946 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 947 | loff_t *ppos) |
| 948 | { |
| 949 | struct ftrace_event_call *call = filp->private_data; |
| 950 | struct trace_seq *s; |
| 951 | int r; |
| 952 | |
| 953 | if (*ppos) |
| 954 | return 0; |
| 955 | |
| 956 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 957 | if (!s) |
| 958 | return -ENOMEM; |
| 959 | |
| 960 | trace_seq_init(s); |
| 961 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 962 | print_event_filter(call, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 963 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 964 | |
| 965 | kfree(s); |
| 966 | |
| 967 | return r; |
| 968 | } |
| 969 | |
| 970 | static ssize_t |
| 971 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 972 | loff_t *ppos) |
| 973 | { |
| 974 | struct ftrace_event_call *call = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 975 | char *buf; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 976 | int err; |
| 977 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 978 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 979 | return -EINVAL; |
| 980 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 981 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 982 | if (!buf) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 983 | return -ENOMEM; |
| 984 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 985 | if (copy_from_user(buf, ubuf, cnt)) { |
| 986 | free_page((unsigned long) buf); |
| 987 | return -EFAULT; |
| 988 | } |
| 989 | buf[cnt] = '\0'; |
| 990 | |
| 991 | err = apply_event_filter(call, buf); |
| 992 | free_page((unsigned long) buf); |
| 993 | if (err < 0) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 994 | return err; |
Tom Zanussi | 0a19e53 | 2009-04-13 03:17:50 -0500 | [diff] [blame] | 995 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 996 | *ppos += cnt; |
| 997 | |
| 998 | return cnt; |
| 999 | } |
| 1000 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1001 | static LIST_HEAD(event_subsystems); |
| 1002 | |
| 1003 | static int subsystem_open(struct inode *inode, struct file *filp) |
| 1004 | { |
| 1005 | struct event_subsystem *system = NULL; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1006 | struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */ |
| 1007 | struct trace_array *tr; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1008 | int ret; |
| 1009 | |
| 1010 | /* Make sure the system still exists */ |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1011 | mutex_lock(&trace_types_lock); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1012 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1013 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 1014 | list_for_each_entry(dir, &tr->systems, list) { |
| 1015 | if (dir == inode->i_private) { |
| 1016 | /* Don't open systems with no events */ |
| 1017 | if (dir->nr_events) { |
| 1018 | __get_system_dir(dir); |
| 1019 | system = dir->subsystem; |
| 1020 | } |
| 1021 | goto exit_loop; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1022 | } |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1023 | } |
| 1024 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1025 | exit_loop: |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1026 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1027 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1028 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1029 | if (!system) |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1030 | return -ENODEV; |
| 1031 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1032 | /* Some versions of gcc think dir can be uninitialized here */ |
| 1033 | WARN_ON(!dir); |
| 1034 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1035 | ret = tracing_open_generic(inode, filp); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1036 | if (ret < 0) |
| 1037 | put_system(dir); |
| 1038 | |
| 1039 | return ret; |
| 1040 | } |
| 1041 | |
| 1042 | static int system_tr_open(struct inode *inode, struct file *filp) |
| 1043 | { |
| 1044 | struct ftrace_subsystem_dir *dir; |
| 1045 | struct trace_array *tr = inode->i_private; |
| 1046 | int ret; |
| 1047 | |
| 1048 | /* Make a temporary dir that has no system but points to tr */ |
| 1049 | dir = kzalloc(sizeof(*dir), GFP_KERNEL); |
| 1050 | if (!dir) |
| 1051 | return -ENOMEM; |
| 1052 | |
| 1053 | dir->tr = tr; |
| 1054 | |
| 1055 | ret = tracing_open_generic(inode, filp); |
| 1056 | if (ret < 0) |
| 1057 | kfree(dir); |
| 1058 | |
| 1059 | filp->private_data = dir; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1060 | |
| 1061 | return ret; |
| 1062 | } |
| 1063 | |
| 1064 | static int subsystem_release(struct inode *inode, struct file *file) |
| 1065 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1066 | struct ftrace_subsystem_dir *dir = file->private_data; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1067 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1068 | /* |
| 1069 | * If dir->subsystem is NULL, then this is a temporary |
| 1070 | * descriptor that was made for a trace_array to enable |
| 1071 | * all subsystems. |
| 1072 | */ |
| 1073 | if (dir->subsystem) |
| 1074 | put_system(dir); |
| 1075 | else |
| 1076 | kfree(dir); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1077 | |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1081 | static ssize_t |
| 1082 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 1083 | loff_t *ppos) |
| 1084 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1085 | struct ftrace_subsystem_dir *dir = filp->private_data; |
| 1086 | struct event_subsystem *system = dir->subsystem; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1087 | struct trace_seq *s; |
| 1088 | int r; |
| 1089 | |
| 1090 | if (*ppos) |
| 1091 | return 0; |
| 1092 | |
| 1093 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 1094 | if (!s) |
| 1095 | return -ENOMEM; |
| 1096 | |
| 1097 | trace_seq_init(s); |
| 1098 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1099 | print_subsystem_event_filter(system, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 1100 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1101 | |
| 1102 | kfree(s); |
| 1103 | |
| 1104 | return r; |
| 1105 | } |
| 1106 | |
| 1107 | static ssize_t |
| 1108 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 1109 | loff_t *ppos) |
| 1110 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1111 | struct ftrace_subsystem_dir *dir = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1112 | char *buf; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1113 | int err; |
| 1114 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1115 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1116 | return -EINVAL; |
| 1117 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1118 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 1119 | if (!buf) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1120 | return -ENOMEM; |
| 1121 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1122 | if (copy_from_user(buf, ubuf, cnt)) { |
| 1123 | free_page((unsigned long) buf); |
| 1124 | return -EFAULT; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1125 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1126 | buf[cnt] = '\0'; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1127 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1128 | err = apply_subsystem_event_filter(dir, buf); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1129 | free_page((unsigned long) buf); |
| 1130 | if (err < 0) |
Li Zefan | 44e9c8b | 2009-04-11 15:55:28 +0800 | [diff] [blame] | 1131 | return err; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1132 | |
| 1133 | *ppos += cnt; |
| 1134 | |
| 1135 | return cnt; |
| 1136 | } |
| 1137 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1138 | static ssize_t |
| 1139 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 1140 | { |
| 1141 | int (*func)(struct trace_seq *s) = filp->private_data; |
| 1142 | struct trace_seq *s; |
| 1143 | int r; |
| 1144 | |
| 1145 | if (*ppos) |
| 1146 | return 0; |
| 1147 | |
| 1148 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 1149 | if (!s) |
| 1150 | return -ENOMEM; |
| 1151 | |
| 1152 | trace_seq_init(s); |
| 1153 | |
| 1154 | func(s); |
| 1155 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
| 1156 | |
| 1157 | kfree(s); |
| 1158 | |
| 1159 | return r; |
| 1160 | } |
| 1161 | |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1162 | static int ftrace_event_avail_open(struct inode *inode, struct file *file); |
| 1163 | static int ftrace_event_set_open(struct inode *inode, struct file *file); |
| 1164 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1165 | static const struct seq_operations show_event_seq_ops = { |
| 1166 | .start = t_start, |
| 1167 | .next = t_next, |
| 1168 | .show = t_show, |
| 1169 | .stop = t_stop, |
| 1170 | }; |
| 1171 | |
| 1172 | static const struct seq_operations show_set_event_seq_ops = { |
| 1173 | .start = s_start, |
| 1174 | .next = s_next, |
| 1175 | .show = t_show, |
| 1176 | .stop = t_stop, |
| 1177 | }; |
| 1178 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1179 | static const struct file_operations ftrace_avail_fops = { |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1180 | .open = ftrace_event_avail_open, |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1181 | .read = seq_read, |
| 1182 | .llseek = seq_lseek, |
| 1183 | .release = seq_release, |
| 1184 | }; |
| 1185 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1186 | static const struct file_operations ftrace_set_event_fops = { |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1187 | .open = ftrace_event_set_open, |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1188 | .read = seq_read, |
| 1189 | .write = ftrace_event_write, |
| 1190 | .llseek = seq_lseek, |
| 1191 | .release = seq_release, |
| 1192 | }; |
| 1193 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1194 | static const struct file_operations ftrace_enable_fops = { |
| 1195 | .open = tracing_open_generic, |
| 1196 | .read = event_enable_read, |
| 1197 | .write = event_enable_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1198 | .llseek = default_llseek, |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1199 | }; |
| 1200 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1201 | static const struct file_operations ftrace_event_format_fops = { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1202 | .open = trace_format_open, |
| 1203 | .read = seq_read, |
| 1204 | .llseek = seq_lseek, |
| 1205 | .release = seq_release, |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1206 | }; |
| 1207 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1208 | static const struct file_operations ftrace_event_id_fops = { |
| 1209 | .open = tracing_open_generic, |
| 1210 | .read = event_id_read, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1211 | .llseek = default_llseek, |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1212 | }; |
| 1213 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1214 | static const struct file_operations ftrace_event_filter_fops = { |
| 1215 | .open = tracing_open_generic, |
| 1216 | .read = event_filter_read, |
| 1217 | .write = event_filter_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1218 | .llseek = default_llseek, |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1219 | }; |
| 1220 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1221 | static const struct file_operations ftrace_subsystem_filter_fops = { |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1222 | .open = subsystem_open, |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1223 | .read = subsystem_filter_read, |
| 1224 | .write = subsystem_filter_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1225 | .llseek = default_llseek, |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1226 | .release = subsystem_release, |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1227 | }; |
| 1228 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1229 | static const struct file_operations ftrace_system_enable_fops = { |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1230 | .open = subsystem_open, |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1231 | .read = system_enable_read, |
| 1232 | .write = system_enable_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1233 | .llseek = default_llseek, |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1234 | .release = subsystem_release, |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1235 | }; |
| 1236 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1237 | static const struct file_operations ftrace_tr_enable_fops = { |
| 1238 | .open = system_tr_open, |
| 1239 | .read = system_enable_read, |
| 1240 | .write = system_enable_write, |
| 1241 | .llseek = default_llseek, |
| 1242 | .release = subsystem_release, |
| 1243 | }; |
| 1244 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1245 | static const struct file_operations ftrace_show_header_fops = { |
| 1246 | .open = tracing_open_generic, |
| 1247 | .read = show_header, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1248 | .llseek = default_llseek, |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1249 | }; |
| 1250 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1251 | static int |
| 1252 | ftrace_event_open(struct inode *inode, struct file *file, |
| 1253 | const struct seq_operations *seq_ops) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1254 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1255 | struct seq_file *m; |
| 1256 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1257 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1258 | ret = seq_open(file, seq_ops); |
| 1259 | if (ret < 0) |
| 1260 | return ret; |
| 1261 | m = file->private_data; |
| 1262 | /* copy tr over to seq ops */ |
| 1263 | m->private = inode->i_private; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1264 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1265 | return ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1266 | } |
| 1267 | |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1268 | static int |
| 1269 | ftrace_event_avail_open(struct inode *inode, struct file *file) |
| 1270 | { |
| 1271 | const struct seq_operations *seq_ops = &show_event_seq_ops; |
| 1272 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1273 | return ftrace_event_open(inode, file, seq_ops); |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static int |
| 1277 | ftrace_event_set_open(struct inode *inode, struct file *file) |
| 1278 | { |
| 1279 | const struct seq_operations *seq_ops = &show_set_event_seq_ops; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1280 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1281 | |
| 1282 | if ((file->f_mode & FMODE_WRITE) && |
| 1283 | (file->f_flags & O_TRUNC)) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1284 | ftrace_clear_events(tr); |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1285 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1286 | return ftrace_event_open(inode, file, seq_ops); |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1289 | static struct event_subsystem * |
| 1290 | create_new_subsystem(const char *name) |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1291 | { |
| 1292 | struct event_subsystem *system; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1293 | |
| 1294 | /* need to create new entry */ |
| 1295 | system = kmalloc(sizeof(*system), GFP_KERNEL); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1296 | if (!system) |
| 1297 | return NULL; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1298 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1299 | system->ref_count = 1; |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 1300 | |
| 1301 | /* Only allocate if dynamic (kprobes and modules) */ |
| 1302 | if (!core_kernel_data((unsigned long)name)) { |
| 1303 | system->ref_count |= SYSTEM_FL_FREE_NAME; |
| 1304 | system->name = kstrdup(name, GFP_KERNEL); |
| 1305 | if (!system->name) |
| 1306 | goto out_free; |
| 1307 | } else |
| 1308 | system->name = name; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1309 | |
Tom Zanussi | 30e673b | 2009-04-28 03:04:47 -0500 | [diff] [blame] | 1310 | system->filter = NULL; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1311 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1312 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1313 | if (!system->filter) |
| 1314 | goto out_free; |
| 1315 | |
| 1316 | list_add(&system->list, &event_subsystems); |
| 1317 | |
| 1318 | return system; |
| 1319 | |
| 1320 | out_free: |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 1321 | if (system->ref_count & SYSTEM_FL_FREE_NAME) |
| 1322 | kfree(system->name); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1323 | kfree(system); |
| 1324 | return NULL; |
| 1325 | } |
| 1326 | |
| 1327 | static struct dentry * |
| 1328 | event_subsystem_dir(struct trace_array *tr, const char *name, |
| 1329 | struct ftrace_event_file *file, struct dentry *parent) |
| 1330 | { |
| 1331 | struct ftrace_subsystem_dir *dir; |
| 1332 | struct event_subsystem *system; |
| 1333 | struct dentry *entry; |
| 1334 | |
| 1335 | /* First see if we did not already create this dir */ |
| 1336 | list_for_each_entry(dir, &tr->systems, list) { |
| 1337 | system = dir->subsystem; |
| 1338 | if (strcmp(system->name, name) == 0) { |
| 1339 | dir->nr_events++; |
| 1340 | file->system = dir; |
| 1341 | return dir->entry; |
| 1342 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1343 | } |
| 1344 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1345 | /* Now see if the system itself exists. */ |
| 1346 | list_for_each_entry(system, &event_subsystems, list) { |
| 1347 | if (strcmp(system->name, name) == 0) |
| 1348 | break; |
| 1349 | } |
| 1350 | /* Reset system variable when not found */ |
| 1351 | if (&system->list == &event_subsystems) |
| 1352 | system = NULL; |
| 1353 | |
| 1354 | dir = kmalloc(sizeof(*dir), GFP_KERNEL); |
| 1355 | if (!dir) |
| 1356 | goto out_fail; |
| 1357 | |
| 1358 | if (!system) { |
| 1359 | system = create_new_subsystem(name); |
| 1360 | if (!system) |
| 1361 | goto out_free; |
| 1362 | } else |
| 1363 | __get_system(system); |
| 1364 | |
| 1365 | dir->entry = debugfs_create_dir(name, parent); |
| 1366 | if (!dir->entry) { |
| 1367 | pr_warning("Failed to create system directory %s\n", name); |
| 1368 | __put_system(system); |
| 1369 | goto out_free; |
| 1370 | } |
| 1371 | |
| 1372 | dir->tr = tr; |
| 1373 | dir->ref_count = 1; |
| 1374 | dir->nr_events = 1; |
| 1375 | dir->subsystem = system; |
| 1376 | file->system = dir; |
| 1377 | |
| 1378 | entry = debugfs_create_file("filter", 0644, dir->entry, dir, |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1379 | &ftrace_subsystem_filter_fops); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1380 | if (!entry) { |
| 1381 | kfree(system->filter); |
| 1382 | system->filter = NULL; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1383 | pr_warning("Could not create debugfs '%s/filter' entry\n", name); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1384 | } |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1385 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1386 | trace_create_file("enable", 0644, dir->entry, dir, |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1387 | &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1388 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1389 | list_add(&dir->list, &tr->systems); |
| 1390 | |
| 1391 | return dir->entry; |
| 1392 | |
| 1393 | out_free: |
| 1394 | kfree(dir); |
| 1395 | out_fail: |
| 1396 | /* Only print this message if failed on memory allocation */ |
| 1397 | if (!dir || !system) |
| 1398 | pr_warning("No memory to create event subsystem %s\n", |
| 1399 | name); |
| 1400 | return NULL; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1401 | } |
| 1402 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1403 | static int |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1404 | event_create_dir(struct dentry *parent, |
| 1405 | struct ftrace_event_file *file, |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1406 | const struct file_operations *id, |
| 1407 | const struct file_operations *enable, |
| 1408 | const struct file_operations *filter, |
| 1409 | const struct file_operations *format) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1410 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1411 | struct ftrace_event_call *call = file->event_call; |
| 1412 | struct trace_array *tr = file->tr; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 1413 | struct list_head *head; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1414 | struct dentry *d_events; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 1415 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1416 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1417 | /* |
| 1418 | * If the trace point header did not define TRACE_SYSTEM |
| 1419 | * then the system would be called "TRACE_SYSTEM". |
| 1420 | */ |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1421 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) { |
| 1422 | d_events = event_subsystem_dir(tr, call->class->system, file, parent); |
| 1423 | if (!d_events) |
| 1424 | return -ENOMEM; |
| 1425 | } else |
| 1426 | d_events = parent; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1427 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1428 | file->dir = debugfs_create_dir(call->name, d_events); |
| 1429 | if (!file->dir) { |
| 1430 | pr_warning("Could not create debugfs '%s' directory\n", |
| 1431 | call->name); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1432 | return -1; |
| 1433 | } |
| 1434 | |
Steven Rostedt | 9b63776 | 2012-05-10 15:55:43 -0400 | [diff] [blame] | 1435 | if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1436 | trace_create_file("enable", 0644, file->dir, file, |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1437 | enable); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1438 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1439 | #ifdef CONFIG_PERF_EVENTS |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 1440 | if (call->event.type && call->class->reg) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1441 | trace_create_file("id", 0444, file->dir, call, |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1442 | id); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1443 | #endif |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1444 | |
Li Zefan | c9d932c | 2010-05-24 16:24:28 +0800 | [diff] [blame] | 1445 | /* |
| 1446 | * Other events may have the same class. Only update |
| 1447 | * the fields if they are not already defined. |
| 1448 | */ |
| 1449 | head = trace_get_fields(call); |
| 1450 | if (list_empty(head)) { |
| 1451 | ret = call->class->define_fields(call); |
| 1452 | if (ret < 0) { |
| 1453 | pr_warning("Could not initialize trace point" |
| 1454 | " events/%s\n", call->name); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1455 | return -1; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 1456 | } |
| 1457 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1458 | trace_create_file("filter", 0644, file->dir, call, |
Li Zefan | c9d932c | 2010-05-24 16:24:28 +0800 | [diff] [blame] | 1459 | filter); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 1460 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1461 | trace_create_file("format", 0444, file->dir, call, |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1462 | format); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 1463 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1464 | return 0; |
| 1465 | } |
| 1466 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1467 | static void remove_subsystem(struct ftrace_subsystem_dir *dir) |
| 1468 | { |
| 1469 | if (!dir) |
| 1470 | return; |
| 1471 | |
| 1472 | if (!--dir->nr_events) { |
| 1473 | debugfs_remove_recursive(dir->entry); |
| 1474 | list_del(&dir->list); |
| 1475 | __put_system_dir(dir); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | static void remove_event_from_tracers(struct ftrace_event_call *call) |
| 1480 | { |
| 1481 | struct ftrace_event_file *file; |
| 1482 | struct trace_array *tr; |
| 1483 | |
| 1484 | do_for_each_event_file_safe(tr, file) { |
| 1485 | |
| 1486 | if (file->event_call != call) |
| 1487 | continue; |
| 1488 | |
| 1489 | list_del(&file->list); |
| 1490 | debugfs_remove_recursive(file->dir); |
| 1491 | remove_subsystem(file->system); |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 1492 | kmem_cache_free(file_cachep, file); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1493 | |
| 1494 | /* |
| 1495 | * The do_for_each_event_file_safe() is |
| 1496 | * a double loop. After finding the call for this |
| 1497 | * trace_array, we use break to jump to the next |
| 1498 | * trace_array. |
| 1499 | */ |
| 1500 | break; |
| 1501 | } while_for_each_event_file(); |
| 1502 | } |
| 1503 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 1504 | static void event_remove(struct ftrace_event_call *call) |
| 1505 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1506 | struct trace_array *tr; |
| 1507 | struct ftrace_event_file *file; |
| 1508 | |
| 1509 | do_for_each_event_file(tr, file) { |
| 1510 | if (file->event_call != call) |
| 1511 | continue; |
| 1512 | ftrace_event_enable_disable(file, 0); |
| 1513 | /* |
| 1514 | * The do_for_each_event_file() is |
| 1515 | * a double loop. After finding the call for this |
| 1516 | * trace_array, we use break to jump to the next |
| 1517 | * trace_array. |
| 1518 | */ |
| 1519 | break; |
| 1520 | } while_for_each_event_file(); |
| 1521 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 1522 | if (call->event.funcs) |
| 1523 | __unregister_ftrace_event(&call->event); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1524 | remove_event_from_tracers(call); |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 1525 | list_del(&call->list); |
| 1526 | } |
| 1527 | |
| 1528 | static int event_init(struct ftrace_event_call *call) |
| 1529 | { |
| 1530 | int ret = 0; |
| 1531 | |
| 1532 | if (WARN_ON(!call->name)) |
| 1533 | return -EINVAL; |
| 1534 | |
| 1535 | if (call->class->raw_init) { |
| 1536 | ret = call->class->raw_init(call); |
| 1537 | if (ret < 0 && ret != -ENOSYS) |
| 1538 | pr_warn("Could not initialize trace events/%s\n", |
| 1539 | call->name); |
| 1540 | } |
| 1541 | |
| 1542 | return ret; |
| 1543 | } |
| 1544 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1545 | static int |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1546 | __register_event(struct ftrace_event_call *call, struct module *mod) |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1547 | { |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1548 | int ret; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1549 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 1550 | ret = event_init(call); |
| 1551 | if (ret < 0) |
| 1552 | return ret; |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1553 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1554 | list_add(&call->list, &ftrace_events); |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1555 | call->mod = mod; |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1556 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1557 | return 0; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 1560 | static struct ftrace_event_file * |
| 1561 | trace_create_new_event(struct ftrace_event_call *call, |
| 1562 | struct trace_array *tr) |
| 1563 | { |
| 1564 | struct ftrace_event_file *file; |
| 1565 | |
| 1566 | file = kmem_cache_alloc(file_cachep, GFP_TRACE); |
| 1567 | if (!file) |
| 1568 | return NULL; |
| 1569 | |
| 1570 | file->event_call = call; |
| 1571 | file->tr = tr; |
| 1572 | atomic_set(&file->sm_ref, 0); |
| 1573 | list_add(&file->list, &tr->events); |
| 1574 | |
| 1575 | return file; |
| 1576 | } |
| 1577 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1578 | /* Add an event to a trace directory */ |
| 1579 | static int |
| 1580 | __trace_add_new_event(struct ftrace_event_call *call, |
| 1581 | struct trace_array *tr, |
| 1582 | const struct file_operations *id, |
| 1583 | const struct file_operations *enable, |
| 1584 | const struct file_operations *filter, |
| 1585 | const struct file_operations *format) |
| 1586 | { |
| 1587 | struct ftrace_event_file *file; |
| 1588 | |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 1589 | file = trace_create_new_event(call, tr); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1590 | if (!file) |
| 1591 | return -ENOMEM; |
| 1592 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1593 | return event_create_dir(tr->event_dir, file, id, enable, filter, format); |
| 1594 | } |
| 1595 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 1596 | /* |
| 1597 | * Just create a decriptor for early init. A descriptor is required |
| 1598 | * for enabling events at boot. We want to enable events before |
| 1599 | * the filesystem is initialized. |
| 1600 | */ |
| 1601 | static __init int |
| 1602 | __trace_early_add_new_event(struct ftrace_event_call *call, |
| 1603 | struct trace_array *tr) |
| 1604 | { |
| 1605 | struct ftrace_event_file *file; |
| 1606 | |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 1607 | file = trace_create_new_event(call, tr); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 1608 | if (!file) |
| 1609 | return -ENOMEM; |
| 1610 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 1611 | return 0; |
| 1612 | } |
| 1613 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1614 | struct ftrace_module_file_ops; |
| 1615 | static void __add_event_to_tracers(struct ftrace_event_call *call, |
| 1616 | struct ftrace_module_file_ops *file_ops); |
| 1617 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1618 | /* Add an additional event_call dynamically */ |
| 1619 | int trace_add_event_call(struct ftrace_event_call *call) |
| 1620 | { |
| 1621 | int ret; |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1622 | mutex_lock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1623 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1624 | |
| 1625 | ret = __register_event(call, NULL); |
| 1626 | if (ret >= 0) |
| 1627 | __add_event_to_tracers(call, NULL); |
| 1628 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1629 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1630 | mutex_unlock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1631 | return ret; |
| 1632 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1633 | |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1634 | /* |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1635 | * Must be called under locking of trace_types_lock, event_mutex and |
| 1636 | * trace_event_sem. |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1637 | */ |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1638 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
| 1639 | { |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 1640 | event_remove(call); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1641 | trace_destroy_fields(call); |
| 1642 | destroy_preds(call); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /* Remove an event_call */ |
| 1646 | void trace_remove_event_call(struct ftrace_event_call *call) |
| 1647 | { |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1648 | mutex_lock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1649 | mutex_lock(&event_mutex); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 1650 | down_write(&trace_event_sem); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1651 | __trace_remove_event_call(call); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 1652 | up_write(&trace_event_sem); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1653 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1654 | mutex_unlock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | #define for_each_event(event, start, end) \ |
| 1658 | for (event = start; \ |
| 1659 | (unsigned long)event < (unsigned long)end; \ |
| 1660 | event++) |
| 1661 | |
| 1662 | #ifdef CONFIG_MODULES |
| 1663 | |
| 1664 | static LIST_HEAD(ftrace_module_file_list); |
| 1665 | |
| 1666 | /* |
| 1667 | * Modules must own their file_operations to keep up with |
| 1668 | * reference counting. |
| 1669 | */ |
| 1670 | struct ftrace_module_file_ops { |
| 1671 | struct list_head list; |
| 1672 | struct module *mod; |
| 1673 | struct file_operations id; |
| 1674 | struct file_operations enable; |
| 1675 | struct file_operations format; |
| 1676 | struct file_operations filter; |
| 1677 | }; |
| 1678 | |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1679 | static struct ftrace_module_file_ops * |
| 1680 | find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1681 | { |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1682 | /* |
| 1683 | * As event_calls are added in groups by module, |
| 1684 | * when we find one file_ops, we don't need to search for |
| 1685 | * each call in that module, as the rest should be the |
| 1686 | * same. Only search for a new one if the last one did |
| 1687 | * not match. |
| 1688 | */ |
| 1689 | if (file_ops && mod == file_ops->mod) |
| 1690 | return file_ops; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1691 | |
| 1692 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { |
| 1693 | if (file_ops->mod == mod) |
| 1694 | return file_ops; |
| 1695 | } |
| 1696 | return NULL; |
| 1697 | } |
| 1698 | |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1699 | static struct ftrace_module_file_ops * |
| 1700 | trace_create_file_ops(struct module *mod) |
| 1701 | { |
| 1702 | struct ftrace_module_file_ops *file_ops; |
| 1703 | |
| 1704 | /* |
| 1705 | * This is a bit of a PITA. To allow for correct reference |
| 1706 | * counting, modules must "own" their file_operations. |
| 1707 | * To do this, we allocate the file operations that will be |
| 1708 | * used in the event directory. |
| 1709 | */ |
| 1710 | |
| 1711 | file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL); |
| 1712 | if (!file_ops) |
| 1713 | return NULL; |
| 1714 | |
| 1715 | file_ops->mod = mod; |
| 1716 | |
| 1717 | file_ops->id = ftrace_event_id_fops; |
| 1718 | file_ops->id.owner = mod; |
| 1719 | |
| 1720 | file_ops->enable = ftrace_enable_fops; |
| 1721 | file_ops->enable.owner = mod; |
| 1722 | |
| 1723 | file_ops->filter = ftrace_event_filter_fops; |
| 1724 | file_ops->filter.owner = mod; |
| 1725 | |
| 1726 | file_ops->format = ftrace_event_format_fops; |
| 1727 | file_ops->format.owner = mod; |
| 1728 | |
| 1729 | list_add(&file_ops->list, &ftrace_module_file_list); |
| 1730 | |
| 1731 | return file_ops; |
| 1732 | } |
| 1733 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1734 | static void trace_module_add_events(struct module *mod) |
| 1735 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1736 | struct ftrace_module_file_ops *file_ops = NULL; |
Steven Rostedt | e4a9ea5 | 2011-01-27 09:15:30 -0500 | [diff] [blame] | 1737 | struct ftrace_event_call **call, **start, **end; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1738 | |
| 1739 | start = mod->trace_events; |
| 1740 | end = mod->trace_events + mod->num_trace_events; |
| 1741 | |
| 1742 | if (start == end) |
| 1743 | return; |
| 1744 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1745 | file_ops = trace_create_file_ops(mod); |
| 1746 | if (!file_ops) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1747 | return; |
| 1748 | |
| 1749 | for_each_event(call, start, end) { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1750 | __register_event(*call, mod); |
| 1751 | __add_event_to_tracers(*call, file_ops); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | static void trace_module_remove_events(struct module *mod) |
| 1756 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1757 | struct ftrace_module_file_ops *file_ops; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1758 | struct ftrace_event_call *call, *p; |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 1759 | bool clear_trace = false; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1760 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 1761 | down_write(&trace_event_sem); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1762 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
| 1763 | if (call->mod == mod) { |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 1764 | if (call->flags & TRACE_EVENT_FL_WAS_ENABLED) |
| 1765 | clear_trace = true; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1766 | __trace_remove_event_call(call); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1767 | } |
| 1768 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1769 | |
| 1770 | /* Now free the file_operations */ |
| 1771 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { |
| 1772 | if (file_ops->mod == mod) |
| 1773 | break; |
| 1774 | } |
| 1775 | if (&file_ops->list != &ftrace_module_file_list) { |
| 1776 | list_del(&file_ops->list); |
| 1777 | kfree(file_ops); |
| 1778 | } |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 1779 | up_write(&trace_event_sem); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1780 | |
| 1781 | /* |
| 1782 | * It is safest to reset the ring buffer if the module being unloaded |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1783 | * registered any events that were used. The only worry is if |
| 1784 | * a new module gets loaded, and takes on the same id as the events |
| 1785 | * of this module. When printing out the buffer, traced events left |
| 1786 | * over from this module may be passed to the new module events and |
| 1787 | * unexpected results may occur. |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1788 | */ |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 1789 | if (clear_trace) |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1790 | tracing_reset_all_online_cpus(); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1791 | } |
| 1792 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1793 | static int trace_module_notify(struct notifier_block *self, |
| 1794 | unsigned long val, void *data) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1795 | { |
| 1796 | struct module *mod = data; |
| 1797 | |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1798 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1799 | mutex_lock(&event_mutex); |
| 1800 | switch (val) { |
| 1801 | case MODULE_STATE_COMING: |
| 1802 | trace_module_add_events(mod); |
| 1803 | break; |
| 1804 | case MODULE_STATE_GOING: |
| 1805 | trace_module_remove_events(mod); |
| 1806 | break; |
| 1807 | } |
| 1808 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame^] | 1809 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1810 | |
| 1811 | return 0; |
| 1812 | } |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1813 | |
| 1814 | static int |
| 1815 | __trace_add_new_mod_event(struct ftrace_event_call *call, |
| 1816 | struct trace_array *tr, |
| 1817 | struct ftrace_module_file_ops *file_ops) |
| 1818 | { |
| 1819 | return __trace_add_new_event(call, tr, |
| 1820 | &file_ops->id, &file_ops->enable, |
| 1821 | &file_ops->filter, &file_ops->format); |
| 1822 | } |
| 1823 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1824 | #else |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1825 | static inline struct ftrace_module_file_ops * |
| 1826 | find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1827 | { |
| 1828 | return NULL; |
| 1829 | } |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1830 | static inline int trace_module_notify(struct notifier_block *self, |
| 1831 | unsigned long val, void *data) |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1832 | { |
| 1833 | return 0; |
| 1834 | } |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1835 | static inline int |
| 1836 | __trace_add_new_mod_event(struct ftrace_event_call *call, |
| 1837 | struct trace_array *tr, |
| 1838 | struct ftrace_module_file_ops *file_ops) |
| 1839 | { |
| 1840 | return -ENODEV; |
| 1841 | } |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1842 | #endif /* CONFIG_MODULES */ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1843 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1844 | /* Create a new event directory structure for a trace directory. */ |
| 1845 | static void |
| 1846 | __trace_add_event_dirs(struct trace_array *tr) |
| 1847 | { |
| 1848 | struct ftrace_module_file_ops *file_ops = NULL; |
| 1849 | struct ftrace_event_call *call; |
| 1850 | int ret; |
| 1851 | |
| 1852 | list_for_each_entry(call, &ftrace_events, list) { |
| 1853 | if (call->mod) { |
| 1854 | /* |
| 1855 | * Directories for events by modules need to |
| 1856 | * keep module ref counts when opened (as we don't |
| 1857 | * want the module to disappear when reading one |
| 1858 | * of these files). The file_ops keep account of |
| 1859 | * the module ref count. |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1860 | */ |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1861 | file_ops = find_ftrace_file_ops(file_ops, call->mod); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1862 | if (!file_ops) |
| 1863 | continue; /* Warn? */ |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 1864 | ret = __trace_add_new_mod_event(call, tr, file_ops); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1865 | if (ret < 0) |
| 1866 | pr_warning("Could not create directory for event %s\n", |
| 1867 | call->name); |
| 1868 | continue; |
| 1869 | } |
| 1870 | ret = __trace_add_new_event(call, tr, |
| 1871 | &ftrace_event_id_fops, |
| 1872 | &ftrace_enable_fops, |
| 1873 | &ftrace_event_filter_fops, |
| 1874 | &ftrace_event_format_fops); |
| 1875 | if (ret < 0) |
| 1876 | pr_warning("Could not create directory for event %s\n", |
| 1877 | call->name); |
| 1878 | } |
| 1879 | } |
| 1880 | |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 1881 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 1882 | |
| 1883 | /* Avoid typos */ |
| 1884 | #define ENABLE_EVENT_STR "enable_event" |
| 1885 | #define DISABLE_EVENT_STR "disable_event" |
| 1886 | |
| 1887 | struct event_probe_data { |
| 1888 | struct ftrace_event_file *file; |
| 1889 | unsigned long count; |
| 1890 | int ref; |
| 1891 | bool enable; |
| 1892 | }; |
| 1893 | |
| 1894 | static struct ftrace_event_file * |
| 1895 | find_event_file(struct trace_array *tr, const char *system, const char *event) |
| 1896 | { |
| 1897 | struct ftrace_event_file *file; |
| 1898 | struct ftrace_event_call *call; |
| 1899 | |
| 1900 | list_for_each_entry(file, &tr->events, list) { |
| 1901 | |
| 1902 | call = file->event_call; |
| 1903 | |
| 1904 | if (!call->name || !call->class || !call->class->reg) |
| 1905 | continue; |
| 1906 | |
| 1907 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) |
| 1908 | continue; |
| 1909 | |
| 1910 | if (strcmp(event, call->name) == 0 && |
| 1911 | strcmp(system, call->class->system) == 0) |
| 1912 | return file; |
| 1913 | } |
| 1914 | return NULL; |
| 1915 | } |
| 1916 | |
| 1917 | static void |
| 1918 | event_enable_probe(unsigned long ip, unsigned long parent_ip, void **_data) |
| 1919 | { |
| 1920 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 1921 | struct event_probe_data *data = *pdata; |
| 1922 | |
| 1923 | if (!data) |
| 1924 | return; |
| 1925 | |
| 1926 | if (data->enable) |
| 1927 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags); |
| 1928 | else |
| 1929 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags); |
| 1930 | } |
| 1931 | |
| 1932 | static void |
| 1933 | event_enable_count_probe(unsigned long ip, unsigned long parent_ip, void **_data) |
| 1934 | { |
| 1935 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 1936 | struct event_probe_data *data = *pdata; |
| 1937 | |
| 1938 | if (!data) |
| 1939 | return; |
| 1940 | |
| 1941 | if (!data->count) |
| 1942 | return; |
| 1943 | |
| 1944 | /* Skip if the event is in a state we want to switch to */ |
| 1945 | if (data->enable == !(data->file->flags & FTRACE_EVENT_FL_SOFT_DISABLED)) |
| 1946 | return; |
| 1947 | |
| 1948 | if (data->count != -1) |
| 1949 | (data->count)--; |
| 1950 | |
| 1951 | event_enable_probe(ip, parent_ip, _data); |
| 1952 | } |
| 1953 | |
| 1954 | static int |
| 1955 | event_enable_print(struct seq_file *m, unsigned long ip, |
| 1956 | struct ftrace_probe_ops *ops, void *_data) |
| 1957 | { |
| 1958 | struct event_probe_data *data = _data; |
| 1959 | |
| 1960 | seq_printf(m, "%ps:", (void *)ip); |
| 1961 | |
| 1962 | seq_printf(m, "%s:%s:%s", |
| 1963 | data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR, |
| 1964 | data->file->event_call->class->system, |
| 1965 | data->file->event_call->name); |
| 1966 | |
| 1967 | if (data->count == -1) |
| 1968 | seq_printf(m, ":unlimited\n"); |
| 1969 | else |
| 1970 | seq_printf(m, ":count=%ld\n", data->count); |
| 1971 | |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
| 1975 | static int |
| 1976 | event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip, |
| 1977 | void **_data) |
| 1978 | { |
| 1979 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 1980 | struct event_probe_data *data = *pdata; |
| 1981 | |
| 1982 | data->ref++; |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | static void |
| 1987 | event_enable_free(struct ftrace_probe_ops *ops, unsigned long ip, |
| 1988 | void **_data) |
| 1989 | { |
| 1990 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 1991 | struct event_probe_data *data = *pdata; |
| 1992 | |
| 1993 | if (WARN_ON_ONCE(data->ref <= 0)) |
| 1994 | return; |
| 1995 | |
| 1996 | data->ref--; |
| 1997 | if (!data->ref) { |
| 1998 | /* Remove the SOFT_MODE flag */ |
| 1999 | __ftrace_event_enable_disable(data->file, 0, 1); |
| 2000 | module_put(data->file->event_call->mod); |
| 2001 | kfree(data); |
| 2002 | } |
| 2003 | *pdata = NULL; |
| 2004 | } |
| 2005 | |
| 2006 | static struct ftrace_probe_ops event_enable_probe_ops = { |
| 2007 | .func = event_enable_probe, |
| 2008 | .print = event_enable_print, |
| 2009 | .init = event_enable_init, |
| 2010 | .free = event_enable_free, |
| 2011 | }; |
| 2012 | |
| 2013 | static struct ftrace_probe_ops event_enable_count_probe_ops = { |
| 2014 | .func = event_enable_count_probe, |
| 2015 | .print = event_enable_print, |
| 2016 | .init = event_enable_init, |
| 2017 | .free = event_enable_free, |
| 2018 | }; |
| 2019 | |
| 2020 | static struct ftrace_probe_ops event_disable_probe_ops = { |
| 2021 | .func = event_enable_probe, |
| 2022 | .print = event_enable_print, |
| 2023 | .init = event_enable_init, |
| 2024 | .free = event_enable_free, |
| 2025 | }; |
| 2026 | |
| 2027 | static struct ftrace_probe_ops event_disable_count_probe_ops = { |
| 2028 | .func = event_enable_count_probe, |
| 2029 | .print = event_enable_print, |
| 2030 | .init = event_enable_init, |
| 2031 | .free = event_enable_free, |
| 2032 | }; |
| 2033 | |
| 2034 | static int |
| 2035 | event_enable_func(struct ftrace_hash *hash, |
| 2036 | char *glob, char *cmd, char *param, int enabled) |
| 2037 | { |
| 2038 | struct trace_array *tr = top_trace_array(); |
| 2039 | struct ftrace_event_file *file; |
| 2040 | struct ftrace_probe_ops *ops; |
| 2041 | struct event_probe_data *data; |
| 2042 | const char *system; |
| 2043 | const char *event; |
| 2044 | char *number; |
| 2045 | bool enable; |
| 2046 | int ret; |
| 2047 | |
| 2048 | /* hash funcs only work with set_ftrace_filter */ |
Harsh Prateek Bora | 8092e80 | 2013-05-24 12:52:17 +0530 | [diff] [blame] | 2049 | if (!enabled || !param) |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2050 | return -EINVAL; |
| 2051 | |
| 2052 | system = strsep(¶m, ":"); |
| 2053 | if (!param) |
| 2054 | return -EINVAL; |
| 2055 | |
| 2056 | event = strsep(¶m, ":"); |
| 2057 | |
| 2058 | mutex_lock(&event_mutex); |
| 2059 | |
| 2060 | ret = -EINVAL; |
| 2061 | file = find_event_file(tr, system, event); |
| 2062 | if (!file) |
| 2063 | goto out; |
| 2064 | |
| 2065 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; |
| 2066 | |
| 2067 | if (enable) |
| 2068 | ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops; |
| 2069 | else |
| 2070 | ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops; |
| 2071 | |
| 2072 | if (glob[0] == '!') { |
| 2073 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 2074 | ret = 0; |
| 2075 | goto out; |
| 2076 | } |
| 2077 | |
| 2078 | ret = -ENOMEM; |
| 2079 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2080 | if (!data) |
| 2081 | goto out; |
| 2082 | |
| 2083 | data->enable = enable; |
| 2084 | data->count = -1; |
| 2085 | data->file = file; |
| 2086 | |
| 2087 | if (!param) |
| 2088 | goto out_reg; |
| 2089 | |
| 2090 | number = strsep(¶m, ":"); |
| 2091 | |
| 2092 | ret = -EINVAL; |
| 2093 | if (!strlen(number)) |
| 2094 | goto out_free; |
| 2095 | |
| 2096 | /* |
| 2097 | * We use the callback data field (which is a pointer) |
| 2098 | * as our counter. |
| 2099 | */ |
| 2100 | ret = kstrtoul(number, 0, &data->count); |
| 2101 | if (ret) |
| 2102 | goto out_free; |
| 2103 | |
| 2104 | out_reg: |
| 2105 | /* Don't let event modules unload while probe registered */ |
| 2106 | ret = try_module_get(file->event_call->mod); |
Masami Hiramatsu | 6ed0106 | 2013-05-16 20:48:49 +0900 | [diff] [blame] | 2107 | if (!ret) { |
| 2108 | ret = -EBUSY; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2109 | goto out_free; |
Masami Hiramatsu | 6ed0106 | 2013-05-16 20:48:49 +0900 | [diff] [blame] | 2110 | } |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2111 | |
| 2112 | ret = __ftrace_event_enable_disable(file, 1, 1); |
| 2113 | if (ret < 0) |
| 2114 | goto out_put; |
| 2115 | ret = register_ftrace_function_probe(glob, ops, data); |
Steven Rostedt (Red Hat) | ff305de | 2013-05-09 11:30:26 -0400 | [diff] [blame] | 2116 | /* |
| 2117 | * The above returns on success the # of functions enabled, |
| 2118 | * but if it didn't find any functions it returns zero. |
| 2119 | * Consider no functions a failure too. |
| 2120 | */ |
Masami Hiramatsu | a5b85bd | 2013-05-09 14:44:14 +0900 | [diff] [blame] | 2121 | if (!ret) { |
| 2122 | ret = -ENOENT; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2123 | goto out_disable; |
Steven Rostedt (Red Hat) | ff305de | 2013-05-09 11:30:26 -0400 | [diff] [blame] | 2124 | } else if (ret < 0) |
| 2125 | goto out_disable; |
| 2126 | /* Just return zero, not the number of enabled functions */ |
| 2127 | ret = 0; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2128 | out: |
| 2129 | mutex_unlock(&event_mutex); |
| 2130 | return ret; |
| 2131 | |
| 2132 | out_disable: |
| 2133 | __ftrace_event_enable_disable(file, 0, 1); |
| 2134 | out_put: |
| 2135 | module_put(file->event_call->mod); |
| 2136 | out_free: |
| 2137 | kfree(data); |
| 2138 | goto out; |
| 2139 | } |
| 2140 | |
| 2141 | static struct ftrace_func_command event_enable_cmd = { |
| 2142 | .name = ENABLE_EVENT_STR, |
| 2143 | .func = event_enable_func, |
| 2144 | }; |
| 2145 | |
| 2146 | static struct ftrace_func_command event_disable_cmd = { |
| 2147 | .name = DISABLE_EVENT_STR, |
| 2148 | .func = event_enable_func, |
| 2149 | }; |
| 2150 | |
| 2151 | static __init int register_event_cmds(void) |
| 2152 | { |
| 2153 | int ret; |
| 2154 | |
| 2155 | ret = register_ftrace_command(&event_enable_cmd); |
| 2156 | if (WARN_ON(ret < 0)) |
| 2157 | return ret; |
| 2158 | ret = register_ftrace_command(&event_disable_cmd); |
| 2159 | if (WARN_ON(ret < 0)) |
| 2160 | unregister_ftrace_command(&event_enable_cmd); |
| 2161 | return ret; |
| 2162 | } |
| 2163 | #else |
| 2164 | static inline int register_event_cmds(void) { return 0; } |
| 2165 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 2166 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2167 | /* |
| 2168 | * The top level array has already had its ftrace_event_file |
| 2169 | * descriptors created in order to allow for early events to |
| 2170 | * be recorded. This function is called after the debugfs has been |
| 2171 | * initialized, and we now have to create the files associated |
| 2172 | * to the events. |
| 2173 | */ |
| 2174 | static __init void |
| 2175 | __trace_early_add_event_dirs(struct trace_array *tr) |
| 2176 | { |
| 2177 | struct ftrace_event_file *file; |
| 2178 | int ret; |
| 2179 | |
| 2180 | |
| 2181 | list_for_each_entry(file, &tr->events, list) { |
| 2182 | ret = event_create_dir(tr->event_dir, file, |
| 2183 | &ftrace_event_id_fops, |
| 2184 | &ftrace_enable_fops, |
| 2185 | &ftrace_event_filter_fops, |
| 2186 | &ftrace_event_format_fops); |
| 2187 | if (ret < 0) |
| 2188 | pr_warning("Could not create directory for event %s\n", |
| 2189 | file->event_call->name); |
| 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | /* |
| 2194 | * For early boot up, the top trace array requires to have |
| 2195 | * a list of events that can be enabled. This must be done before |
| 2196 | * the filesystem is set up in order to allow events to be traced |
| 2197 | * early. |
| 2198 | */ |
| 2199 | static __init void |
| 2200 | __trace_early_add_events(struct trace_array *tr) |
| 2201 | { |
| 2202 | struct ftrace_event_call *call; |
| 2203 | int ret; |
| 2204 | |
| 2205 | list_for_each_entry(call, &ftrace_events, list) { |
| 2206 | /* Early boot up should not have any modules loaded */ |
| 2207 | if (WARN_ON_ONCE(call->mod)) |
| 2208 | continue; |
| 2209 | |
| 2210 | ret = __trace_early_add_new_event(call, tr); |
| 2211 | if (ret < 0) |
| 2212 | pr_warning("Could not create early event %s\n", |
| 2213 | call->name); |
| 2214 | } |
| 2215 | } |
| 2216 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2217 | /* Remove the event directory structure for a trace directory. */ |
| 2218 | static void |
| 2219 | __trace_remove_event_dirs(struct trace_array *tr) |
| 2220 | { |
| 2221 | struct ftrace_event_file *file, *next; |
| 2222 | |
| 2223 | list_for_each_entry_safe(file, next, &tr->events, list) { |
| 2224 | list_del(&file->list); |
| 2225 | debugfs_remove_recursive(file->dir); |
| 2226 | remove_subsystem(file->system); |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 2227 | kmem_cache_free(file_cachep, file); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2231 | static void |
| 2232 | __add_event_to_tracers(struct ftrace_event_call *call, |
| 2233 | struct ftrace_module_file_ops *file_ops) |
| 2234 | { |
| 2235 | struct trace_array *tr; |
| 2236 | |
| 2237 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 2238 | if (file_ops) |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 2239 | __trace_add_new_mod_event(call, tr, file_ops); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2240 | else |
| 2241 | __trace_add_new_event(call, tr, |
| 2242 | &ftrace_event_id_fops, |
| 2243 | &ftrace_enable_fops, |
| 2244 | &ftrace_event_filter_fops, |
| 2245 | &ftrace_event_format_fops); |
| 2246 | } |
| 2247 | } |
| 2248 | |
Steven Rostedt | ec827c7 | 2009-09-14 10:50:23 -0400 | [diff] [blame] | 2249 | static struct notifier_block trace_module_nb = { |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2250 | .notifier_call = trace_module_notify, |
| 2251 | .priority = 0, |
| 2252 | }; |
| 2253 | |
Steven Rostedt | e4a9ea5 | 2011-01-27 09:15:30 -0500 | [diff] [blame] | 2254 | extern struct ftrace_event_call *__start_ftrace_events[]; |
| 2255 | extern struct ftrace_event_call *__stop_ftrace_events[]; |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 2256 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 2257 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
| 2258 | |
| 2259 | static __init int setup_trace_event(char *str) |
| 2260 | { |
| 2261 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 2262 | ring_buffer_expanded = true; |
| 2263 | tracing_selftest_disabled = true; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 2264 | |
| 2265 | return 1; |
| 2266 | } |
| 2267 | __setup("trace_event=", setup_trace_event); |
| 2268 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2269 | /* Expects to have event_mutex held when called */ |
| 2270 | static int |
| 2271 | create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2272 | { |
| 2273 | struct dentry *d_events; |
| 2274 | struct dentry *entry; |
| 2275 | |
| 2276 | entry = debugfs_create_file("set_event", 0644, parent, |
| 2277 | tr, &ftrace_set_event_fops); |
| 2278 | if (!entry) { |
| 2279 | pr_warning("Could not create debugfs 'set_event' entry\n"); |
| 2280 | return -ENOMEM; |
| 2281 | } |
| 2282 | |
| 2283 | d_events = debugfs_create_dir("events", parent); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2284 | if (!d_events) { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2285 | pr_warning("Could not create debugfs 'events' directory\n"); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2286 | return -ENOMEM; |
| 2287 | } |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2288 | |
| 2289 | /* ring buffer internal formats */ |
| 2290 | trace_create_file("header_page", 0444, d_events, |
| 2291 | ring_buffer_print_page_header, |
| 2292 | &ftrace_show_header_fops); |
| 2293 | |
| 2294 | trace_create_file("header_event", 0444, d_events, |
| 2295 | ring_buffer_print_entry_header, |
| 2296 | &ftrace_show_header_fops); |
| 2297 | |
| 2298 | trace_create_file("enable", 0644, d_events, |
| 2299 | tr, &ftrace_tr_enable_fops); |
| 2300 | |
| 2301 | tr->event_dir = d_events; |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2302 | |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * event_trace_add_tracer - add a instance of a trace_array to events |
| 2308 | * @parent: The parent dentry to place the files/directories for events in |
| 2309 | * @tr: The trace array associated with these events |
| 2310 | * |
| 2311 | * When a new instance is created, it needs to set up its events |
| 2312 | * directory, as well as other files associated with events. It also |
| 2313 | * creates the event hierachry in the @parent/events directory. |
| 2314 | * |
| 2315 | * Returns 0 on success. |
| 2316 | */ |
| 2317 | int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr) |
| 2318 | { |
| 2319 | int ret; |
| 2320 | |
| 2321 | mutex_lock(&event_mutex); |
| 2322 | |
| 2323 | ret = create_event_toplevel_files(parent, tr); |
| 2324 | if (ret) |
| 2325 | goto out_unlock; |
| 2326 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2327 | down_write(&trace_event_sem); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2328 | __trace_add_event_dirs(tr); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2329 | up_write(&trace_event_sem); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2330 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2331 | out_unlock: |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2332 | mutex_unlock(&event_mutex); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2333 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2334 | return ret; |
| 2335 | } |
| 2336 | |
| 2337 | /* |
| 2338 | * The top trace array already had its file descriptors created. |
| 2339 | * Now the files themselves need to be created. |
| 2340 | */ |
| 2341 | static __init int |
| 2342 | early_event_add_tracer(struct dentry *parent, struct trace_array *tr) |
| 2343 | { |
| 2344 | int ret; |
| 2345 | |
| 2346 | mutex_lock(&event_mutex); |
| 2347 | |
| 2348 | ret = create_event_toplevel_files(parent, tr); |
| 2349 | if (ret) |
| 2350 | goto out_unlock; |
| 2351 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2352 | down_write(&trace_event_sem); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2353 | __trace_early_add_event_dirs(tr); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2354 | up_write(&trace_event_sem); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2355 | |
| 2356 | out_unlock: |
| 2357 | mutex_unlock(&event_mutex); |
| 2358 | |
| 2359 | return ret; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2360 | } |
| 2361 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2362 | int event_trace_del_tracer(struct trace_array *tr) |
| 2363 | { |
| 2364 | /* Disable any running events */ |
| 2365 | __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0); |
| 2366 | |
| 2367 | mutex_lock(&event_mutex); |
| 2368 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2369 | down_write(&trace_event_sem); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2370 | __trace_remove_event_dirs(tr); |
| 2371 | debugfs_remove_recursive(tr->event_dir); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2372 | up_write(&trace_event_sem); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2373 | |
| 2374 | tr->event_dir = NULL; |
| 2375 | |
| 2376 | mutex_unlock(&event_mutex); |
| 2377 | |
| 2378 | return 0; |
| 2379 | } |
| 2380 | |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 2381 | static __init int event_trace_memsetup(void) |
| 2382 | { |
| 2383 | field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC); |
| 2384 | file_cachep = KMEM_CACHE(ftrace_event_file, SLAB_PANIC); |
| 2385 | return 0; |
| 2386 | } |
| 2387 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2388 | static __init int event_trace_enable(void) |
| 2389 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2390 | struct trace_array *tr = top_trace_array(); |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2391 | struct ftrace_event_call **iter, *call; |
| 2392 | char *buf = bootup_event_buf; |
| 2393 | char *token; |
| 2394 | int ret; |
| 2395 | |
| 2396 | for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) { |
| 2397 | |
| 2398 | call = *iter; |
| 2399 | ret = event_init(call); |
| 2400 | if (!ret) |
| 2401 | list_add(&call->list, &ftrace_events); |
| 2402 | } |
| 2403 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2404 | /* |
| 2405 | * We need the top trace array to have a working set of trace |
| 2406 | * points at early init, before the debug files and directories |
| 2407 | * are created. Create the file entries now, and attach them |
| 2408 | * to the actual file dentries later. |
| 2409 | */ |
| 2410 | __trace_early_add_events(tr); |
| 2411 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2412 | while (true) { |
| 2413 | token = strsep(&buf, ","); |
| 2414 | |
| 2415 | if (!token) |
| 2416 | break; |
| 2417 | if (!*token) |
| 2418 | continue; |
| 2419 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2420 | ret = ftrace_set_clr_event(tr, token, 1); |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2421 | if (ret) |
| 2422 | pr_warn("Failed to enable trace event: %s\n", token); |
| 2423 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2424 | |
| 2425 | trace_printk_start_comm(); |
| 2426 | |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2427 | register_event_cmds(); |
| 2428 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2429 | return 0; |
| 2430 | } |
| 2431 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 2432 | static __init int event_trace_init(void) |
| 2433 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2434 | struct trace_array *tr; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 2435 | struct dentry *d_tracer; |
| 2436 | struct dentry *entry; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2437 | int ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 2438 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2439 | tr = top_trace_array(); |
| 2440 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 2441 | d_tracer = tracing_init_dentry(); |
| 2442 | if (!d_tracer) |
| 2443 | return 0; |
| 2444 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 2445 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2446 | tr, &ftrace_avail_fops); |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 2447 | if (!entry) |
| 2448 | pr_warning("Could not create debugfs " |
| 2449 | "'available_events' entry\n"); |
| 2450 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 2451 | if (trace_define_common_fields()) |
| 2452 | pr_warning("tracing: Failed to allocate common fields"); |
| 2453 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2454 | ret = early_event_add_tracer(d_tracer, tr); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2455 | if (ret) |
| 2456 | return ret; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 2457 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2458 | ret = register_module_notifier(&trace_module_nb); |
Ming Lei | 5537937 | 2009-05-18 23:04:46 +0800 | [diff] [blame] | 2459 | if (ret) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2460 | pr_warning("Failed to register trace events module notifier\n"); |
| 2461 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 2462 | return 0; |
| 2463 | } |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 2464 | early_initcall(event_trace_memsetup); |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2465 | core_initcall(event_trace_enable); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 2466 | fs_initcall(event_trace_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2467 | |
| 2468 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 2469 | |
| 2470 | static DEFINE_SPINLOCK(test_spinlock); |
| 2471 | static DEFINE_SPINLOCK(test_spinlock_irq); |
| 2472 | static DEFINE_MUTEX(test_mutex); |
| 2473 | |
| 2474 | static __init void test_work(struct work_struct *dummy) |
| 2475 | { |
| 2476 | spin_lock(&test_spinlock); |
| 2477 | spin_lock_irq(&test_spinlock_irq); |
| 2478 | udelay(1); |
| 2479 | spin_unlock_irq(&test_spinlock_irq); |
| 2480 | spin_unlock(&test_spinlock); |
| 2481 | |
| 2482 | mutex_lock(&test_mutex); |
| 2483 | msleep(1); |
| 2484 | mutex_unlock(&test_mutex); |
| 2485 | } |
| 2486 | |
| 2487 | static __init int event_test_thread(void *unused) |
| 2488 | { |
| 2489 | void *test_malloc; |
| 2490 | |
| 2491 | test_malloc = kmalloc(1234, GFP_KERNEL); |
| 2492 | if (!test_malloc) |
| 2493 | pr_info("failed to kmalloc\n"); |
| 2494 | |
| 2495 | schedule_on_each_cpu(test_work); |
| 2496 | |
| 2497 | kfree(test_malloc); |
| 2498 | |
| 2499 | set_current_state(TASK_INTERRUPTIBLE); |
| 2500 | while (!kthread_should_stop()) |
| 2501 | schedule(); |
| 2502 | |
| 2503 | return 0; |
| 2504 | } |
| 2505 | |
| 2506 | /* |
| 2507 | * Do various things that may trigger events. |
| 2508 | */ |
| 2509 | static __init void event_test_stuff(void) |
| 2510 | { |
| 2511 | struct task_struct *test_thread; |
| 2512 | |
| 2513 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); |
| 2514 | msleep(1); |
| 2515 | kthread_stop(test_thread); |
| 2516 | } |
| 2517 | |
| 2518 | /* |
| 2519 | * For every trace event defined, we will test each trace point separately, |
| 2520 | * and then by groups, and finally all trace points. |
| 2521 | */ |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2522 | static __init void event_trace_self_tests(void) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2523 | { |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2524 | struct ftrace_subsystem_dir *dir; |
| 2525 | struct ftrace_event_file *file; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2526 | struct ftrace_event_call *call; |
| 2527 | struct event_subsystem *system; |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2528 | struct trace_array *tr; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2529 | int ret; |
| 2530 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2531 | tr = top_trace_array(); |
| 2532 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2533 | pr_info("Running tests on trace events:\n"); |
| 2534 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2535 | list_for_each_entry(file, &tr->events, list) { |
| 2536 | |
| 2537 | call = file->event_call; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2538 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 2539 | /* Only test those that have a probe */ |
| 2540 | if (!call->class || !call->class->probe) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2541 | continue; |
| 2542 | |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 2543 | /* |
| 2544 | * Testing syscall events here is pretty useless, but |
| 2545 | * we still do it if configured. But this is time consuming. |
| 2546 | * What we really need is a user thread to perform the |
| 2547 | * syscalls as we test. |
| 2548 | */ |
| 2549 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 2550 | if (call->class->system && |
| 2551 | strcmp(call->class->system, "syscalls") == 0) |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 2552 | continue; |
| 2553 | #endif |
| 2554 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2555 | pr_info("Testing event %s: ", call->name); |
| 2556 | |
| 2557 | /* |
| 2558 | * If an event is already enabled, someone is using |
| 2559 | * it and the self test should not be on. |
| 2560 | */ |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2561 | if (file->flags & FTRACE_EVENT_FL_ENABLED) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2562 | pr_warning("Enabled event during self test!\n"); |
| 2563 | WARN_ON_ONCE(1); |
| 2564 | continue; |
| 2565 | } |
| 2566 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2567 | ftrace_event_enable_disable(file, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2568 | event_test_stuff(); |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2569 | ftrace_event_enable_disable(file, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2570 | |
| 2571 | pr_cont("OK\n"); |
| 2572 | } |
| 2573 | |
| 2574 | /* Now test at the sub system level */ |
| 2575 | |
| 2576 | pr_info("Running tests on trace event systems:\n"); |
| 2577 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2578 | list_for_each_entry(dir, &tr->systems, list) { |
| 2579 | |
| 2580 | system = dir->subsystem; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2581 | |
| 2582 | /* the ftrace system is special, skip it */ |
| 2583 | if (strcmp(system->name, "ftrace") == 0) |
| 2584 | continue; |
| 2585 | |
| 2586 | pr_info("Testing event system %s: ", system->name); |
| 2587 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2588 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2589 | if (WARN_ON_ONCE(ret)) { |
| 2590 | pr_warning("error enabling system %s\n", |
| 2591 | system->name); |
| 2592 | continue; |
| 2593 | } |
| 2594 | |
| 2595 | event_test_stuff(); |
| 2596 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2597 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0); |
Yuanhan Liu | 76bab1b | 2012-08-27 15:13:45 +0800 | [diff] [blame] | 2598 | if (WARN_ON_ONCE(ret)) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2599 | pr_warning("error disabling system %s\n", |
| 2600 | system->name); |
Yuanhan Liu | 76bab1b | 2012-08-27 15:13:45 +0800 | [diff] [blame] | 2601 | continue; |
| 2602 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2603 | |
| 2604 | pr_cont("OK\n"); |
| 2605 | } |
| 2606 | |
| 2607 | /* Test with all events enabled */ |
| 2608 | |
| 2609 | pr_info("Running tests on all trace events:\n"); |
| 2610 | pr_info("Testing all events: "); |
| 2611 | |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2612 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2613 | if (WARN_ON_ONCE(ret)) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2614 | pr_warning("error enabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2615 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | event_test_stuff(); |
| 2619 | |
| 2620 | /* reset sysname */ |
Steven Rostedt | ae63b31 | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2621 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2622 | if (WARN_ON_ONCE(ret)) { |
| 2623 | pr_warning("error disabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2624 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | pr_cont("OK\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | #ifdef CONFIG_FUNCTION_TRACER |
| 2631 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 2632 | static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2633 | |
| 2634 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 2635 | function_test_events_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame] | 2636 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2637 | { |
| 2638 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2639 | struct ring_buffer *buffer; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2640 | struct ftrace_entry *entry; |
| 2641 | unsigned long flags; |
| 2642 | long disabled; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2643 | int cpu; |
| 2644 | int pc; |
| 2645 | |
| 2646 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2647 | preempt_disable_notrace(); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2648 | cpu = raw_smp_processor_id(); |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 2649 | disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2650 | |
| 2651 | if (disabled != 1) |
| 2652 | goto out; |
| 2653 | |
| 2654 | local_save_flags(flags); |
| 2655 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2656 | event = trace_current_buffer_lock_reserve(&buffer, |
| 2657 | TRACE_FN, sizeof(*entry), |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2658 | flags, pc); |
| 2659 | if (!event) |
| 2660 | goto out; |
| 2661 | entry = ring_buffer_event_data(event); |
| 2662 | entry->ip = ip; |
| 2663 | entry->parent_ip = parent_ip; |
| 2664 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 2665 | trace_buffer_unlock_commit(buffer, event, flags, pc); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2666 | |
| 2667 | out: |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 2668 | atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2669 | preempt_enable_notrace(); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | static struct ftrace_ops trace_ops __initdata = |
| 2673 | { |
| 2674 | .func = function_test_events_call, |
Steven Rostedt | 4740974 | 2012-07-20 11:04:44 -0400 | [diff] [blame] | 2675 | .flags = FTRACE_OPS_FL_RECURSION_SAFE, |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2676 | }; |
| 2677 | |
| 2678 | static __init void event_trace_self_test_with_function(void) |
| 2679 | { |
Steven Rostedt | 17bb615 | 2011-05-23 15:27:46 -0400 | [diff] [blame] | 2680 | int ret; |
| 2681 | ret = register_ftrace_function(&trace_ops); |
| 2682 | if (WARN_ON(ret < 0)) { |
| 2683 | pr_info("Failed to enable function tracer for event tests\n"); |
| 2684 | return; |
| 2685 | } |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 2686 | pr_info("Running tests again, along with the function tracer\n"); |
| 2687 | event_trace_self_tests(); |
| 2688 | unregister_ftrace_function(&trace_ops); |
| 2689 | } |
| 2690 | #else |
| 2691 | static __init void event_trace_self_test_with_function(void) |
| 2692 | { |
| 2693 | } |
| 2694 | #endif |
| 2695 | |
| 2696 | static __init int event_trace_self_tests_init(void) |
| 2697 | { |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 2698 | if (!tracing_selftest_disabled) { |
| 2699 | event_trace_self_tests(); |
| 2700 | event_trace_self_test_with_function(); |
| 2701 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2702 | |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
Steven Rostedt | 28d20e2 | 2009-04-20 12:12:44 -0400 | [diff] [blame] | 2706 | late_initcall(event_trace_self_tests_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 2707 | |
| 2708 | #endif |