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