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