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