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