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 | |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 11 | #define pr_fmt(fmt) fmt |
| 12 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 13 | #include <linux/workqueue.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/kthread.h> |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 16 | #include <linux/tracefs.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 17 | #include <linux/uaccess.h> |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 18 | #include <linux/bsearch.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/ctype.h> |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 21 | #include <linux/sort.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 23 | #include <linux/delay.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 24 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 25 | #include <trace/events/sched.h> |
| 26 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 27 | #include <asm/setup.h> |
| 28 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 29 | #include "trace_output.h" |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 30 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 31 | #undef TRACE_SYSTEM |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 32 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| 33 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 34 | DEFINE_MUTEX(event_mutex); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 35 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 36 | LIST_HEAD(ftrace_events); |
Daniel Wagner | 9f61668 | 2015-08-10 14:35:46 +0200 | [diff] [blame] | 37 | static LIST_HEAD(ftrace_generic_fields); |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 38 | static LIST_HEAD(ftrace_common_fields); |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 39 | |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 40 | #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO) |
| 41 | |
| 42 | static struct kmem_cache *field_cachep; |
| 43 | static struct kmem_cache *file_cachep; |
| 44 | |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 45 | static inline int system_refcount(struct event_subsystem *system) |
| 46 | { |
Rasmus Villemoes | 79ac6ef | 2015-09-09 23:24:01 +0200 | [diff] [blame] | 47 | return system->ref_count; |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static int system_refcount_inc(struct event_subsystem *system) |
| 51 | { |
Rasmus Villemoes | 79ac6ef | 2015-09-09 23:24:01 +0200 | [diff] [blame] | 52 | return system->ref_count++; |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static int system_refcount_dec(struct event_subsystem *system) |
| 56 | { |
Rasmus Villemoes | 79ac6ef | 2015-09-09 23:24:01 +0200 | [diff] [blame] | 57 | return --system->ref_count; |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 60 | /* Double loops, do not use break, only goto's work */ |
| 61 | #define do_for_each_event_file(tr, file) \ |
| 62 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ |
| 63 | list_for_each_entry(file, &tr->events, list) |
| 64 | |
| 65 | #define do_for_each_event_file_safe(tr, file) \ |
| 66 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 67 | struct trace_event_file *___n; \ |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 68 | list_for_each_entry_safe(file, ___n, &tr->events, list) |
| 69 | |
| 70 | #define while_for_each_event_file() \ |
| 71 | } |
| 72 | |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 73 | static struct list_head * |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 74 | trace_get_fields(struct trace_event_call *event_call) |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 75 | { |
| 76 | if (!event_call->class->get_fields) |
| 77 | return &event_call->class->fields; |
| 78 | return event_call->class->get_fields(event_call); |
| 79 | } |
| 80 | |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 81 | static struct ftrace_event_field * |
| 82 | __find_event_field(struct list_head *head, char *name) |
| 83 | { |
| 84 | struct ftrace_event_field *field; |
| 85 | |
| 86 | list_for_each_entry(field, head, link) { |
| 87 | if (!strcmp(field->name, name)) |
| 88 | return field; |
| 89 | } |
| 90 | |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | struct ftrace_event_field * |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 95 | trace_find_event_field(struct trace_event_call *call, char *name) |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 96 | { |
| 97 | struct ftrace_event_field *field; |
| 98 | struct list_head *head; |
| 99 | |
Daniel Wagner | 9f61668 | 2015-08-10 14:35:46 +0200 | [diff] [blame] | 100 | field = __find_event_field(&ftrace_generic_fields, name); |
| 101 | if (field) |
| 102 | return field; |
| 103 | |
zhangwei(Jovi) | b3a8c6f | 2013-03-11 15:13:42 +0800 | [diff] [blame] | 104 | field = __find_event_field(&ftrace_common_fields, name); |
| 105 | if (field) |
| 106 | return field; |
| 107 | |
| 108 | head = trace_get_fields(call); |
| 109 | return __find_event_field(head, name); |
| 110 | } |
| 111 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 112 | static int __trace_define_field(struct list_head *head, const char *type, |
| 113 | const char *name, int offset, int size, |
| 114 | int is_signed, int filter_type) |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 115 | { |
| 116 | struct ftrace_event_field *field; |
| 117 | |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 118 | field = kmem_cache_alloc(field_cachep, GFP_TRACE); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 119 | if (!field) |
Namhyung Kim | aaf6ac0 | 2013-06-07 15:07:48 +0900 | [diff] [blame] | 120 | return -ENOMEM; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 121 | |
Steven Rostedt | 92edca0 | 2013-02-27 20:41:37 -0500 | [diff] [blame] | 122 | field->name = name; |
| 123 | field->type = type; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 124 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 125 | if (filter_type == FILTER_OTHER) |
| 126 | field->filter_type = filter_assign_type(type); |
| 127 | else |
| 128 | field->filter_type = filter_type; |
| 129 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 130 | field->offset = offset; |
| 131 | field->size = size; |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 132 | field->is_signed = is_signed; |
Li Zefan | aa38e9f | 2009-08-07 10:33:02 +0800 | [diff] [blame] | 133 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 134 | list_add(&field->link, head); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 135 | |
| 136 | return 0; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 137 | } |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 138 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 139 | int trace_define_field(struct trace_event_call *call, const char *type, |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 140 | const char *name, int offset, int size, int is_signed, |
| 141 | int filter_type) |
| 142 | { |
| 143 | struct list_head *head; |
| 144 | |
| 145 | if (WARN_ON(!call->class)) |
| 146 | return 0; |
| 147 | |
| 148 | head = trace_get_fields(call); |
| 149 | return __trace_define_field(head, type, name, offset, size, |
| 150 | is_signed, filter_type); |
| 151 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 152 | EXPORT_SYMBOL_GPL(trace_define_field); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 153 | |
Daniel Wagner | 9f61668 | 2015-08-10 14:35:46 +0200 | [diff] [blame] | 154 | #define __generic_field(type, item, filter_type) \ |
| 155 | ret = __trace_define_field(&ftrace_generic_fields, #type, \ |
| 156 | #item, 0, 0, is_signed_type(type), \ |
| 157 | filter_type); \ |
| 158 | if (ret) \ |
| 159 | return ret; |
| 160 | |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 161 | #define __common_field(type, item) \ |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 162 | ret = __trace_define_field(&ftrace_common_fields, #type, \ |
| 163 | "common_" #item, \ |
| 164 | offsetof(typeof(ent), item), \ |
| 165 | sizeof(ent.item), \ |
| 166 | is_signed_type(type), FILTER_OTHER); \ |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 167 | if (ret) \ |
| 168 | return ret; |
| 169 | |
Daniel Wagner | 9f61668 | 2015-08-10 14:35:46 +0200 | [diff] [blame] | 170 | static int trace_define_generic_fields(void) |
| 171 | { |
| 172 | int ret; |
| 173 | |
| 174 | __generic_field(int, cpu, FILTER_OTHER); |
| 175 | __generic_field(char *, comm, FILTER_PTR_STRING); |
| 176 | |
| 177 | return ret; |
| 178 | } |
| 179 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 180 | static int trace_define_common_fields(void) |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 181 | { |
| 182 | int ret; |
| 183 | struct trace_entry ent; |
| 184 | |
| 185 | __common_field(unsigned short, type); |
| 186 | __common_field(unsigned char, flags); |
| 187 | __common_field(unsigned char, preempt_count); |
| 188 | __common_field(int, pid); |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 189 | |
| 190 | return ret; |
| 191 | } |
| 192 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 193 | static void trace_destroy_fields(struct trace_event_call *call) |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 194 | { |
| 195 | struct ftrace_event_field *field, *next; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 196 | struct list_head *head; |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 197 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 198 | head = trace_get_fields(call); |
| 199 | list_for_each_entry_safe(field, next, head, link) { |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 200 | list_del(&field->link); |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 201 | kmem_cache_free(field_cachep, field); |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 205 | int trace_event_raw_init(struct trace_event_call *call) |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 206 | { |
| 207 | int id; |
| 208 | |
Steven Rostedt (Red Hat) | 9023c93 | 2015-05-05 09:39:12 -0400 | [diff] [blame] | 209 | id = register_trace_event(&call->event); |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 210 | if (!id) |
| 211 | return -ENODEV; |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | EXPORT_SYMBOL_GPL(trace_event_raw_init); |
| 216 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 217 | bool trace_event_ignore_this_pid(struct trace_event_file *trace_file) |
| 218 | { |
| 219 | struct trace_array *tr = trace_file->tr; |
| 220 | struct trace_array_cpu *data; |
| 221 | struct trace_pid_list *pid_list; |
| 222 | |
| 223 | pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 224 | if (!pid_list) |
| 225 | return false; |
| 226 | |
| 227 | data = this_cpu_ptr(tr->trace_buffer.data); |
| 228 | |
| 229 | return data->ignore_pid; |
| 230 | } |
| 231 | EXPORT_SYMBOL_GPL(trace_event_ignore_this_pid); |
| 232 | |
Steven Rostedt (Red Hat) | 3f795dc | 2015-05-05 13:18:46 -0400 | [diff] [blame] | 233 | void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer, |
| 234 | struct trace_event_file *trace_file, |
| 235 | unsigned long len) |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 236 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 237 | struct trace_event_call *event_call = trace_file->event_call; |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 238 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 239 | if ((trace_file->flags & EVENT_FILE_FL_PID_FILTER) && |
| 240 | trace_event_ignore_this_pid(trace_file)) |
| 241 | return NULL; |
| 242 | |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 243 | local_save_flags(fbuffer->flags); |
| 244 | fbuffer->pc = preempt_count(); |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 245 | fbuffer->trace_file = trace_file; |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 246 | |
| 247 | fbuffer->event = |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 248 | trace_event_buffer_lock_reserve(&fbuffer->buffer, trace_file, |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 249 | event_call->event.type, len, |
| 250 | fbuffer->flags, fbuffer->pc); |
| 251 | if (!fbuffer->event) |
| 252 | return NULL; |
| 253 | |
| 254 | fbuffer->entry = ring_buffer_event_data(fbuffer->event); |
| 255 | return fbuffer->entry; |
| 256 | } |
Steven Rostedt (Red Hat) | 3f795dc | 2015-05-05 13:18:46 -0400 | [diff] [blame] | 257 | EXPORT_SYMBOL_GPL(trace_event_buffer_reserve); |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 258 | |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 259 | static DEFINE_SPINLOCK(tracepoint_iter_lock); |
| 260 | |
Steven Rostedt (Red Hat) | 3f795dc | 2015-05-05 13:18:46 -0400 | [diff] [blame] | 261 | static void output_printk(struct trace_event_buffer *fbuffer) |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 262 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 263 | struct trace_event_call *event_call; |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 264 | struct trace_event *event; |
| 265 | unsigned long flags; |
| 266 | struct trace_iterator *iter = tracepoint_print_iter; |
| 267 | |
| 268 | if (!iter) |
| 269 | return; |
| 270 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 271 | event_call = fbuffer->trace_file->event_call; |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 272 | if (!event_call || !event_call->event.funcs || |
| 273 | !event_call->event.funcs->trace) |
| 274 | return; |
| 275 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 276 | event = &fbuffer->trace_file->event_call->event; |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 277 | |
| 278 | spin_lock_irqsave(&tracepoint_iter_lock, flags); |
| 279 | trace_seq_init(&iter->seq); |
| 280 | iter->ent = fbuffer->entry; |
| 281 | event_call->event.funcs->trace(iter, 0, event); |
| 282 | trace_seq_putc(&iter->seq, 0); |
| 283 | printk("%s", iter->seq.buffer); |
| 284 | |
| 285 | spin_unlock_irqrestore(&tracepoint_iter_lock, flags); |
| 286 | } |
| 287 | |
Steven Rostedt (Red Hat) | 3f795dc | 2015-05-05 13:18:46 -0400 | [diff] [blame] | 288 | void trace_event_buffer_commit(struct trace_event_buffer *fbuffer) |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 289 | { |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 290 | if (tracepoint_printk) |
| 291 | output_printk(fbuffer); |
| 292 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 293 | event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer, |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 294 | fbuffer->event, fbuffer->entry, |
| 295 | fbuffer->flags, fbuffer->pc); |
| 296 | } |
Steven Rostedt (Red Hat) | 3f795dc | 2015-05-05 13:18:46 -0400 | [diff] [blame] | 297 | EXPORT_SYMBOL_GPL(trace_event_buffer_commit); |
Steven Rostedt | 3fd40d1 | 2012-08-09 22:42:57 -0400 | [diff] [blame] | 298 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 299 | int trace_event_reg(struct trace_event_call *call, |
Steven Rostedt (Red Hat) | 9023c93 | 2015-05-05 09:39:12 -0400 | [diff] [blame] | 300 | enum trace_reg type, void *data) |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 301 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 302 | struct trace_event_file *file = data; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 303 | |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 304 | WARN_ON(!(call->flags & TRACE_EVENT_FL_TRACEPOINT)); |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 305 | switch (type) { |
| 306 | case TRACE_REG_REGISTER: |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 307 | return tracepoint_probe_register(call->tp, |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 308 | call->class->probe, |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 309 | file); |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 310 | case TRACE_REG_UNREGISTER: |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 311 | tracepoint_probe_unregister(call->tp, |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 312 | call->class->probe, |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 313 | file); |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 314 | return 0; |
| 315 | |
| 316 | #ifdef CONFIG_PERF_EVENTS |
| 317 | case TRACE_REG_PERF_REGISTER: |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 318 | return tracepoint_probe_register(call->tp, |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 319 | call->class->perf_probe, |
| 320 | call); |
| 321 | case TRACE_REG_PERF_UNREGISTER: |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 322 | tracepoint_probe_unregister(call->tp, |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 323 | call->class->perf_probe, |
| 324 | call); |
| 325 | return 0; |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 326 | case TRACE_REG_PERF_OPEN: |
| 327 | case TRACE_REG_PERF_CLOSE: |
Jiri Olsa | 489c75c | 2012-02-15 15:51:50 +0100 | [diff] [blame] | 328 | case TRACE_REG_PERF_ADD: |
| 329 | case TRACE_REG_PERF_DEL: |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 330 | return 0; |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 331 | #endif |
| 332 | } |
| 333 | return 0; |
| 334 | } |
Steven Rostedt (Red Hat) | 9023c93 | 2015-05-05 09:39:12 -0400 | [diff] [blame] | 335 | EXPORT_SYMBOL_GPL(trace_event_reg); |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 336 | |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 337 | void trace_event_enable_cmd_record(bool enable) |
| 338 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 339 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 340 | struct trace_array *tr; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 341 | |
| 342 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 343 | do_for_each_event_file(tr, file) { |
| 344 | |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 345 | if (!(file->flags & EVENT_FILE_FL_ENABLED)) |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 346 | continue; |
| 347 | |
| 348 | if (enable) { |
| 349 | tracing_start_cmdline_record(); |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 350 | set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 351 | } else { |
| 352 | tracing_stop_cmdline_record(); |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 353 | clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 354 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 355 | } while_for_each_event_file(); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 356 | mutex_unlock(&event_mutex); |
| 357 | } |
| 358 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 359 | static int __ftrace_event_enable_disable(struct trace_event_file *file, |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 360 | int enable, int soft_disable) |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 361 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 362 | struct trace_event_call *call = file->event_call; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 363 | struct trace_array *tr = file->tr; |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 364 | int ret = 0; |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 365 | int disable; |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 366 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 367 | switch (enable) { |
| 368 | case 0: |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 369 | /* |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 370 | * When soft_disable is set and enable is cleared, the sm_ref |
| 371 | * reference counter is decremented. If it reaches 0, we want |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 372 | * to clear the SOFT_DISABLED flag but leave the event in the |
| 373 | * state that it was. That is, if the event was enabled and |
| 374 | * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED |
| 375 | * is set we do not want the event to be enabled before we |
| 376 | * clear the bit. |
| 377 | * |
| 378 | * When soft_disable is not set but the SOFT_MODE flag is, |
| 379 | * we do nothing. Do not disable the tracepoint, otherwise |
| 380 | * "soft enable"s (clearing the SOFT_DISABLED bit) wont work. |
| 381 | */ |
| 382 | if (soft_disable) { |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 383 | if (atomic_dec_return(&file->sm_ref) > 0) |
| 384 | break; |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 385 | disable = file->flags & EVENT_FILE_FL_SOFT_DISABLED; |
| 386 | clear_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 387 | } else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 388 | disable = !(file->flags & EVENT_FILE_FL_SOFT_MODE); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 389 | |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 390 | if (disable && (file->flags & EVENT_FILE_FL_ENABLED)) { |
| 391 | clear_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags); |
| 392 | if (file->flags & EVENT_FILE_FL_RECORDED_CMD) { |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 393 | tracing_stop_cmdline_record(); |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 394 | clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 395 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 396 | call->class->reg(call, TRACE_REG_UNREGISTER, file); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 397 | } |
Tom Zanussi | 3baa5e4 | 2013-06-29 00:08:07 -0500 | [diff] [blame] | 398 | /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 399 | if (file->flags & EVENT_FILE_FL_SOFT_MODE) |
| 400 | set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); |
Tom Zanussi | 3baa5e4 | 2013-06-29 00:08:07 -0500 | [diff] [blame] | 401 | else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 402 | clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 403 | break; |
| 404 | case 1: |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 405 | /* |
| 406 | * When soft_disable is set and enable is set, we want to |
| 407 | * register the tracepoint for the event, but leave the event |
| 408 | * as is. That means, if the event was already enabled, we do |
| 409 | * nothing (but set SOFT_MODE). If the event is disabled, we |
| 410 | * set SOFT_DISABLED before enabling the event tracepoint, so |
| 411 | * it still seems to be disabled. |
| 412 | */ |
| 413 | if (!soft_disable) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 414 | clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 415 | else { |
| 416 | if (atomic_inc_return(&file->sm_ref) > 1) |
| 417 | break; |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 418 | set_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags); |
Masami Hiramatsu | 1cf4c07 | 2013-05-09 14:44:29 +0900 | [diff] [blame] | 419 | } |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 420 | |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 421 | if (!(file->flags & EVENT_FILE_FL_ENABLED)) { |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 422 | |
| 423 | /* Keep the event disabled, when going to SOFT_MODE. */ |
| 424 | if (soft_disable) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 425 | set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 426 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 427 | if (tr->trace_flags & TRACE_ITER_RECORD_CMD) { |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 428 | tracing_start_cmdline_record(); |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 429 | set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags); |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 430 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 431 | ret = call->class->reg(call, TRACE_REG_REGISTER, file); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 432 | if (ret) { |
| 433 | tracing_stop_cmdline_record(); |
| 434 | pr_info("event trace: Could not enable event " |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 435 | "%s\n", trace_event_name(call)); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 436 | break; |
| 437 | } |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 438 | set_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags); |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 439 | |
| 440 | /* WAS_ENABLED gets set but never cleared. */ |
| 441 | call->flags |= TRACE_EVENT_FL_WAS_ENABLED; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 442 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 443 | break; |
| 444 | } |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 445 | |
| 446 | return ret; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 447 | } |
| 448 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 449 | int trace_event_enable_disable(struct trace_event_file *file, |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 450 | int enable, int soft_disable) |
| 451 | { |
| 452 | return __ftrace_event_enable_disable(file, enable, soft_disable); |
| 453 | } |
| 454 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 455 | static int ftrace_event_enable_disable(struct trace_event_file *file, |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 456 | int enable) |
| 457 | { |
| 458 | return __ftrace_event_enable_disable(file, enable, 0); |
| 459 | } |
| 460 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 461 | static void ftrace_clear_events(struct trace_array *tr) |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 462 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 463 | struct trace_event_file *file; |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 464 | |
| 465 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 466 | list_for_each_entry(file, &tr->events, list) { |
| 467 | ftrace_event_enable_disable(file, 0); |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 468 | } |
| 469 | mutex_unlock(&event_mutex); |
| 470 | } |
| 471 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 472 | static int cmp_pid(const void *key, const void *elt) |
| 473 | { |
| 474 | const pid_t *search_pid = key; |
| 475 | const pid_t *pid = elt; |
| 476 | |
| 477 | if (*search_pid == *pid) |
| 478 | return 0; |
| 479 | if (*search_pid < *pid) |
| 480 | return -1; |
| 481 | return 1; |
| 482 | } |
| 483 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 484 | static bool |
| 485 | check_ignore_pid(struct trace_pid_list *filtered_pids, struct task_struct *task) |
| 486 | { |
| 487 | pid_t search_pid; |
| 488 | pid_t *pid; |
| 489 | |
| 490 | /* |
| 491 | * Return false, because if filtered_pids does not exist, |
| 492 | * all pids are good to trace. |
| 493 | */ |
| 494 | if (!filtered_pids) |
| 495 | return false; |
| 496 | |
| 497 | search_pid = task->pid; |
| 498 | |
| 499 | pid = bsearch(&search_pid, filtered_pids->pids, |
| 500 | filtered_pids->nr_pids, sizeof(pid_t), |
| 501 | cmp_pid); |
| 502 | if (!pid) |
| 503 | return true; |
| 504 | |
| 505 | return false; |
| 506 | } |
| 507 | |
| 508 | static void |
| 509 | event_filter_pid_sched_switch_probe_pre(void *data, |
| 510 | struct task_struct *prev, struct task_struct *next) |
| 511 | { |
| 512 | struct trace_array *tr = data; |
| 513 | struct trace_pid_list *pid_list; |
| 514 | |
| 515 | pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 516 | |
| 517 | this_cpu_write(tr->trace_buffer.data->ignore_pid, |
| 518 | check_ignore_pid(pid_list, prev) && |
| 519 | check_ignore_pid(pid_list, next)); |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | event_filter_pid_sched_switch_probe_post(void *data, |
| 524 | struct task_struct *prev, struct task_struct *next) |
| 525 | { |
| 526 | struct trace_array *tr = data; |
| 527 | struct trace_pid_list *pid_list; |
| 528 | |
| 529 | pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 530 | |
| 531 | this_cpu_write(tr->trace_buffer.data->ignore_pid, |
| 532 | check_ignore_pid(pid_list, next)); |
| 533 | } |
| 534 | |
| 535 | static void |
| 536 | event_filter_pid_sched_wakeup_probe_pre(void *data, struct task_struct *task) |
| 537 | { |
| 538 | struct trace_array *tr = data; |
| 539 | struct trace_pid_list *pid_list; |
| 540 | |
| 541 | /* Nothing to do if we are already tracing */ |
| 542 | if (!this_cpu_read(tr->trace_buffer.data->ignore_pid)) |
| 543 | return; |
| 544 | |
| 545 | pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 546 | |
| 547 | this_cpu_write(tr->trace_buffer.data->ignore_pid, |
| 548 | check_ignore_pid(pid_list, task)); |
| 549 | } |
| 550 | |
| 551 | static void |
| 552 | event_filter_pid_sched_wakeup_probe_post(void *data, struct task_struct *task) |
| 553 | { |
| 554 | struct trace_array *tr = data; |
| 555 | struct trace_pid_list *pid_list; |
| 556 | |
| 557 | /* Nothing to do if we are not tracing */ |
| 558 | if (this_cpu_read(tr->trace_buffer.data->ignore_pid)) |
| 559 | return; |
| 560 | |
| 561 | pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 562 | |
| 563 | /* Set tracing if current is enabled */ |
| 564 | this_cpu_write(tr->trace_buffer.data->ignore_pid, |
| 565 | check_ignore_pid(pid_list, current)); |
| 566 | } |
| 567 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 568 | static void __ftrace_clear_event_pids(struct trace_array *tr) |
| 569 | { |
| 570 | struct trace_pid_list *pid_list; |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 571 | struct trace_event_file *file; |
| 572 | int cpu; |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 573 | |
| 574 | pid_list = rcu_dereference_protected(tr->filtered_pids, |
| 575 | lockdep_is_held(&event_mutex)); |
| 576 | if (!pid_list) |
| 577 | return; |
| 578 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 579 | unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr); |
| 580 | unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr); |
| 581 | |
| 582 | unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr); |
| 583 | unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr); |
| 584 | |
| 585 | list_for_each_entry(file, &tr->events, list) { |
| 586 | clear_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags); |
| 587 | } |
| 588 | |
| 589 | for_each_possible_cpu(cpu) |
| 590 | per_cpu_ptr(tr->trace_buffer.data, cpu)->ignore_pid = false; |
| 591 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 592 | rcu_assign_pointer(tr->filtered_pids, NULL); |
| 593 | |
| 594 | /* Wait till all users are no longer using pid filtering */ |
| 595 | synchronize_sched(); |
| 596 | |
| 597 | free_pages((unsigned long)pid_list->pids, pid_list->order); |
| 598 | kfree(pid_list); |
| 599 | } |
| 600 | |
| 601 | static void ftrace_clear_event_pids(struct trace_array *tr) |
| 602 | { |
| 603 | mutex_lock(&event_mutex); |
| 604 | __ftrace_clear_event_pids(tr); |
| 605 | mutex_unlock(&event_mutex); |
| 606 | } |
| 607 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 608 | static void __put_system(struct event_subsystem *system) |
| 609 | { |
| 610 | struct event_filter *filter = system->filter; |
| 611 | |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 612 | WARN_ON_ONCE(system_refcount(system) == 0); |
| 613 | if (system_refcount_dec(system)) |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 614 | return; |
| 615 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 616 | list_del(&system->list); |
| 617 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 618 | if (filter) { |
| 619 | kfree(filter->filter_string); |
| 620 | kfree(filter); |
| 621 | } |
Rasmus Villemoes | 79ac6ef | 2015-09-09 23:24:01 +0200 | [diff] [blame] | 622 | kfree_const(system->name); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 623 | kfree(system); |
| 624 | } |
| 625 | |
| 626 | static void __get_system(struct event_subsystem *system) |
| 627 | { |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 628 | WARN_ON_ONCE(system_refcount(system) == 0); |
| 629 | system_refcount_inc(system); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 632 | static void __get_system_dir(struct trace_subsystem_dir *dir) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 633 | { |
| 634 | WARN_ON_ONCE(dir->ref_count == 0); |
| 635 | dir->ref_count++; |
| 636 | __get_system(dir->subsystem); |
| 637 | } |
| 638 | |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 639 | static void __put_system_dir(struct trace_subsystem_dir *dir) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 640 | { |
| 641 | WARN_ON_ONCE(dir->ref_count == 0); |
| 642 | /* If the subsystem is about to be freed, the dir must be too */ |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 643 | WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 644 | |
| 645 | __put_system(dir->subsystem); |
| 646 | if (!--dir->ref_count) |
| 647 | kfree(dir); |
| 648 | } |
| 649 | |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 650 | static void put_system(struct trace_subsystem_dir *dir) |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 651 | { |
| 652 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 653 | __put_system_dir(dir); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 654 | mutex_unlock(&event_mutex); |
| 655 | } |
| 656 | |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 657 | static void remove_subsystem(struct trace_subsystem_dir *dir) |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 658 | { |
| 659 | if (!dir) |
| 660 | return; |
| 661 | |
| 662 | if (!--dir->nr_events) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 663 | tracefs_remove_recursive(dir->entry); |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 664 | list_del(&dir->list); |
| 665 | __put_system_dir(dir); |
| 666 | } |
| 667 | } |
| 668 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 669 | static void remove_event_file_dir(struct trace_event_file *file) |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 670 | { |
Oleg Nesterov | bf682c3 | 2013-07-28 20:35:27 +0200 | [diff] [blame] | 671 | struct dentry *dir = file->dir; |
| 672 | struct dentry *child; |
| 673 | |
| 674 | if (dir) { |
| 675 | spin_lock(&dir->d_lock); /* probably unneeded */ |
Al Viro | 946e51f | 2014-10-26 19:19:16 -0400 | [diff] [blame] | 676 | list_for_each_entry(child, &dir->d_subdirs, d_child) { |
David Howells | 7682c91 | 2015-03-17 22:26:16 +0000 | [diff] [blame] | 677 | if (d_really_is_positive(child)) /* probably unneeded */ |
| 678 | d_inode(child)->i_private = NULL; |
Oleg Nesterov | bf682c3 | 2013-07-28 20:35:27 +0200 | [diff] [blame] | 679 | } |
| 680 | spin_unlock(&dir->d_lock); |
| 681 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 682 | tracefs_remove_recursive(dir); |
Oleg Nesterov | bf682c3 | 2013-07-28 20:35:27 +0200 | [diff] [blame] | 683 | } |
| 684 | |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 685 | list_del(&file->list); |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 686 | remove_subsystem(file->system); |
Oleg Nesterov | 2448e34 | 2014-07-11 21:06:38 +0200 | [diff] [blame] | 687 | free_event_filter(file->filter); |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 688 | kmem_cache_free(file_cachep, file); |
| 689 | } |
| 690 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 691 | /* |
| 692 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. |
| 693 | */ |
Steven Rostedt (Red Hat) | 2a6c24a | 2013-07-02 14:48:23 -0400 | [diff] [blame] | 694 | static int |
| 695 | __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, |
| 696 | const char *sub, const char *event, int set) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 697 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 698 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 699 | struct trace_event_call *call; |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 700 | const char *name; |
Steven Rostedt | 29f9394 | 2009-05-08 16:06:47 -0400 | [diff] [blame] | 701 | int ret = -EINVAL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 702 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 703 | list_for_each_entry(file, &tr->events, list) { |
| 704 | |
| 705 | call = file->event_call; |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 706 | name = trace_event_name(call); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 707 | |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 708 | if (!name || !call->class || !call->class->reg) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 709 | continue; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 710 | |
Steven Rostedt | 9b63776 | 2012-05-10 15:55:43 -0400 | [diff] [blame] | 711 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) |
| 712 | continue; |
| 713 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 714 | if (match && |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 715 | strcmp(match, name) != 0 && |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 716 | strcmp(match, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 717 | continue; |
| 718 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 719 | if (sub && strcmp(sub, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 720 | continue; |
| 721 | |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 722 | if (event && strcmp(event, name) != 0) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 723 | continue; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 724 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 725 | ftrace_event_enable_disable(file, set); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 726 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 727 | ret = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 728 | } |
Steven Rostedt (Red Hat) | 2a6c24a | 2013-07-02 14:48:23 -0400 | [diff] [blame] | 729 | |
| 730 | return ret; |
| 731 | } |
| 732 | |
| 733 | static int __ftrace_set_clr_event(struct trace_array *tr, const char *match, |
| 734 | const char *sub, const char *event, int set) |
| 735 | { |
| 736 | int ret; |
| 737 | |
| 738 | mutex_lock(&event_mutex); |
| 739 | ret = __ftrace_set_clr_event_nolock(tr, match, sub, event, set); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 740 | mutex_unlock(&event_mutex); |
| 741 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 742 | return ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 743 | } |
| 744 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 745 | 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] | 746 | { |
| 747 | char *event = NULL, *sub = NULL, *match; |
Joonsoo Kim | 84fce9d | 2015-04-16 13:44:44 +0900 | [diff] [blame] | 748 | int ret; |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 749 | |
| 750 | /* |
| 751 | * The buf format can be <subsystem>:<event-name> |
| 752 | * *:<event-name> means any event by that name. |
| 753 | * :<event-name> is the same. |
| 754 | * |
| 755 | * <subsystem>:* means all events in that subsystem |
| 756 | * <subsystem>: means the same. |
| 757 | * |
| 758 | * <name> (no ':') means all events in a subsystem with |
| 759 | * the name <name> or any event that matches <name> |
| 760 | */ |
| 761 | |
| 762 | match = strsep(&buf, ":"); |
| 763 | if (buf) { |
| 764 | sub = match; |
| 765 | event = buf; |
| 766 | match = NULL; |
| 767 | |
| 768 | if (!strlen(sub) || strcmp(sub, "*") == 0) |
| 769 | sub = NULL; |
| 770 | if (!strlen(event) || strcmp(event, "*") == 0) |
| 771 | event = NULL; |
| 772 | } |
| 773 | |
Joonsoo Kim | 84fce9d | 2015-04-16 13:44:44 +0900 | [diff] [blame] | 774 | ret = __ftrace_set_clr_event(tr, match, sub, event, set); |
| 775 | |
| 776 | /* Put back the colon to allow this to be called again */ |
| 777 | if (buf) |
| 778 | *(buf - 1) = ':'; |
| 779 | |
| 780 | return ret; |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 781 | } |
| 782 | |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 783 | /** |
| 784 | * trace_set_clr_event - enable or disable an event |
| 785 | * @system: system name to match (NULL for any system) |
| 786 | * @event: event name to match (NULL for all events, within system) |
| 787 | * @set: 1 to enable, 0 to disable |
| 788 | * |
| 789 | * This is a way for other parts of the kernel to enable or disable |
| 790 | * event recording. |
| 791 | * |
| 792 | * Returns 0 on success, -EINVAL if the parameters do not match any |
| 793 | * registered events. |
| 794 | */ |
| 795 | int trace_set_clr_event(const char *system, const char *event, int set) |
| 796 | { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 797 | struct trace_array *tr = top_trace_array(); |
| 798 | |
Yoshihiro YUNOMAE | dc81e5e | 2014-06-06 07:35:17 +0900 | [diff] [blame] | 799 | if (!tr) |
| 800 | return -ENODEV; |
| 801 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 802 | return __ftrace_set_clr_event(tr, NULL, system, event, set); |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 803 | } |
Yuanhan Liu | 56355b8 | 2010-11-08 14:05:12 +0800 | [diff] [blame] | 804 | EXPORT_SYMBOL_GPL(trace_set_clr_event); |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 805 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 806 | /* 128 should be much more than enough */ |
| 807 | #define EVENT_BUF_SIZE 127 |
| 808 | |
| 809 | static ssize_t |
| 810 | ftrace_event_write(struct file *file, const char __user *ubuf, |
| 811 | size_t cnt, loff_t *ppos) |
| 812 | { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 813 | struct trace_parser parser; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 814 | struct seq_file *m = file->private_data; |
| 815 | struct trace_array *tr = m->private; |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 816 | ssize_t read, ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 817 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 818 | if (!cnt) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 819 | return 0; |
| 820 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 821 | ret = tracing_update_buffers(); |
| 822 | if (ret < 0) |
| 823 | return ret; |
| 824 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 825 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 826 | return -ENOMEM; |
| 827 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 828 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 829 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 830 | if (read >= 0 && trace_parser_loaded((&parser))) { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 831 | int set = 1; |
| 832 | |
| 833 | if (*parser.buffer == '!') |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 834 | set = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 835 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 836 | parser.buffer[parser.idx] = 0; |
| 837 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 838 | ret = ftrace_set_clr_event(tr, parser.buffer + !set, set); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 839 | if (ret) |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 840 | goto out_put; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 841 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 842 | |
| 843 | ret = read; |
| 844 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 845 | out_put: |
| 846 | trace_parser_put(&parser); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 847 | |
| 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | static void * |
| 852 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 853 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 854 | struct trace_event_file *file = v; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 855 | struct trace_event_call *call; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 856 | struct trace_array *tr = m->private; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 857 | |
| 858 | (*pos)++; |
| 859 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 860 | list_for_each_entry_continue(file, &tr->events, list) { |
| 861 | call = file->event_call; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 862 | /* |
| 863 | * The ftrace subsystem is for showing formats only. |
| 864 | * They can not be enabled or disabled via the event files. |
| 865 | */ |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 866 | if (call->class && call->class->reg) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 867 | return file; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 868 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 869 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 870 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 874 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 875 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 876 | struct trace_array *tr = m->private; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 877 | loff_t l; |
| 878 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 879 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 880 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 881 | file = list_entry(&tr->events, struct trace_event_file, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 882 | for (l = 0; l <= *pos; ) { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 883 | file = t_next(m, file, &l); |
| 884 | if (!file) |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 885 | break; |
| 886 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 887 | return file; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | static void * |
| 891 | s_next(struct seq_file *m, void *v, loff_t *pos) |
| 892 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 893 | struct trace_event_file *file = v; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 894 | struct trace_array *tr = m->private; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 895 | |
| 896 | (*pos)++; |
| 897 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 898 | list_for_each_entry_continue(file, &tr->events, list) { |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 899 | if (file->flags & EVENT_FILE_FL_ENABLED) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 900 | return file; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 901 | } |
| 902 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 903 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 907 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 908 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 909 | struct trace_array *tr = m->private; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 910 | loff_t l; |
| 911 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 912 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 913 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 914 | file = list_entry(&tr->events, struct trace_event_file, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 915 | for (l = 0; l <= *pos; ) { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 916 | file = s_next(m, file, &l); |
| 917 | if (!file) |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 918 | break; |
| 919 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 920 | return file; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static int t_show(struct seq_file *m, void *v) |
| 924 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 925 | struct trace_event_file *file = v; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 926 | struct trace_event_call *call = file->event_call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 927 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 928 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
| 929 | seq_printf(m, "%s:", call->class->system); |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 930 | seq_printf(m, "%s\n", trace_event_name(call)); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | static void t_stop(struct seq_file *m, void *p) |
| 936 | { |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 937 | mutex_unlock(&event_mutex); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 938 | } |
| 939 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 940 | static void *p_start(struct seq_file *m, loff_t *pos) |
| 941 | { |
| 942 | struct trace_pid_list *pid_list; |
| 943 | struct trace_array *tr = m->private; |
| 944 | |
| 945 | /* |
| 946 | * Grab the mutex, to keep calls to p_next() having the same |
| 947 | * tr->filtered_pids as p_start() has. |
| 948 | * If we just passed the tr->filtered_pids around, then RCU would |
| 949 | * have been enough, but doing that makes things more complex. |
| 950 | */ |
| 951 | mutex_lock(&event_mutex); |
| 952 | rcu_read_lock_sched(); |
| 953 | |
| 954 | pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 955 | |
| 956 | if (!pid_list || *pos >= pid_list->nr_pids) |
| 957 | return NULL; |
| 958 | |
| 959 | return (void *)&pid_list->pids[*pos]; |
| 960 | } |
| 961 | |
| 962 | static void p_stop(struct seq_file *m, void *p) |
| 963 | { |
| 964 | rcu_read_unlock_sched(); |
| 965 | mutex_unlock(&event_mutex); |
| 966 | } |
| 967 | |
| 968 | static void * |
| 969 | p_next(struct seq_file *m, void *v, loff_t *pos) |
| 970 | { |
| 971 | struct trace_array *tr = m->private; |
| 972 | struct trace_pid_list *pid_list = rcu_dereference_sched(tr->filtered_pids); |
| 973 | |
| 974 | (*pos)++; |
| 975 | |
| 976 | if (*pos >= pid_list->nr_pids) |
| 977 | return NULL; |
| 978 | |
| 979 | return (void *)&pid_list->pids[*pos]; |
| 980 | } |
| 981 | |
| 982 | static int p_show(struct seq_file *m, void *v) |
| 983 | { |
| 984 | pid_t *pid = v; |
| 985 | |
| 986 | seq_printf(m, "%d\n", *pid); |
| 987 | return 0; |
| 988 | } |
| 989 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 990 | static ssize_t |
| 991 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 992 | loff_t *ppos) |
| 993 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 994 | struct trace_event_file *file; |
Oleg Nesterov | bc6f6b0 | 2013-07-26 19:25:36 +0200 | [diff] [blame] | 995 | unsigned long flags; |
Tom Zanussi | a439059 | 2013-06-29 00:08:04 -0500 | [diff] [blame] | 996 | char buf[4] = "0"; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 997 | |
Oleg Nesterov | bc6f6b0 | 2013-07-26 19:25:36 +0200 | [diff] [blame] | 998 | mutex_lock(&event_mutex); |
| 999 | file = event_file_data(filp); |
| 1000 | if (likely(file)) |
| 1001 | flags = file->flags; |
| 1002 | mutex_unlock(&event_mutex); |
| 1003 | |
| 1004 | if (!file) |
| 1005 | return -ENODEV; |
| 1006 | |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1007 | if (flags & EVENT_FILE_FL_ENABLED && |
| 1008 | !(flags & EVENT_FILE_FL_SOFT_DISABLED)) |
Tom Zanussi | a439059 | 2013-06-29 00:08:04 -0500 | [diff] [blame] | 1009 | strcpy(buf, "1"); |
| 1010 | |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1011 | if (flags & EVENT_FILE_FL_SOFT_DISABLED || |
| 1012 | flags & EVENT_FILE_FL_SOFT_MODE) |
Tom Zanussi | a439059 | 2013-06-29 00:08:04 -0500 | [diff] [blame] | 1013 | strcat(buf, "*"); |
| 1014 | |
| 1015 | strcat(buf, "\n"); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1016 | |
Steven Rostedt (Red Hat) | 417944c | 2013-03-12 13:26:18 -0400 | [diff] [blame] | 1017 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf)); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | static ssize_t |
| 1021 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 1022 | loff_t *ppos) |
| 1023 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1024 | struct trace_event_file *file; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1025 | unsigned long val; |
| 1026 | int ret; |
| 1027 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 1028 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 1029 | if (ret) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1030 | return ret; |
| 1031 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 1032 | ret = tracing_update_buffers(); |
| 1033 | if (ret < 0) |
| 1034 | return ret; |
| 1035 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1036 | switch (val) { |
| 1037 | case 0: |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1038 | case 1: |
Oleg Nesterov | bc6f6b0 | 2013-07-26 19:25:36 +0200 | [diff] [blame] | 1039 | ret = -ENODEV; |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 1040 | mutex_lock(&event_mutex); |
Oleg Nesterov | bc6f6b0 | 2013-07-26 19:25:36 +0200 | [diff] [blame] | 1041 | file = event_file_data(filp); |
| 1042 | if (likely(file)) |
| 1043 | ret = ftrace_event_enable_disable(file, val); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 1044 | mutex_unlock(&event_mutex); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1045 | break; |
| 1046 | |
| 1047 | default: |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | |
| 1051 | *ppos += cnt; |
| 1052 | |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 1053 | return ret ? ret : cnt; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1054 | } |
| 1055 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1056 | static ssize_t |
| 1057 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 1058 | loff_t *ppos) |
| 1059 | { |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 1060 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1061 | struct trace_subsystem_dir *dir = filp->private_data; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1062 | struct event_subsystem *system = dir->subsystem; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1063 | struct trace_event_call *call; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1064 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1065 | struct trace_array *tr = dir->tr; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1066 | char buf[2]; |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 1067 | int set = 0; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1068 | int ret; |
| 1069 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1070 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1071 | list_for_each_entry(file, &tr->events, list) { |
| 1072 | call = file->event_call; |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1073 | if (!trace_event_name(call) || !call->class || !call->class->reg) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1074 | continue; |
| 1075 | |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1076 | if (system && strcmp(call->class->system, system->name) != 0) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1077 | continue; |
| 1078 | |
| 1079 | /* |
| 1080 | * We need to find out if all the events are set |
| 1081 | * or if all events or cleared, or if we have |
| 1082 | * a mixture. |
| 1083 | */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1084 | set |= (1 << !!(file->flags & EVENT_FILE_FL_ENABLED)); |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 1085 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1086 | /* |
| 1087 | * If we have a mixture, no need to look further. |
| 1088 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 1089 | if (set == 3) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1090 | break; |
| 1091 | } |
| 1092 | mutex_unlock(&event_mutex); |
| 1093 | |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 1094 | buf[0] = set_to_char[set]; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1095 | buf[1] = '\n'; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1096 | |
| 1097 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 1098 | |
| 1099 | return ret; |
| 1100 | } |
| 1101 | |
| 1102 | static ssize_t |
| 1103 | system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 1104 | loff_t *ppos) |
| 1105 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1106 | struct trace_subsystem_dir *dir = filp->private_data; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1107 | struct event_subsystem *system = dir->subsystem; |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1108 | const char *name = NULL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1109 | unsigned long val; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1110 | ssize_t ret; |
| 1111 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 1112 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 1113 | if (ret) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1114 | return ret; |
| 1115 | |
| 1116 | ret = tracing_update_buffers(); |
| 1117 | if (ret < 0) |
| 1118 | return ret; |
| 1119 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1120 | if (val != 0 && val != 1) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1121 | return -EINVAL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1122 | |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1123 | /* |
| 1124 | * Opening of "enable" adds a ref count to system, |
| 1125 | * so the name is safe to use. |
| 1126 | */ |
| 1127 | if (system) |
| 1128 | name = system->name; |
| 1129 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1130 | ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1131 | if (ret) |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1132 | goto out; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1133 | |
| 1134 | ret = cnt; |
| 1135 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1136 | out: |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1137 | *ppos += cnt; |
| 1138 | |
| 1139 | return ret; |
| 1140 | } |
| 1141 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1142 | enum { |
| 1143 | FORMAT_HEADER = 1, |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 1144 | FORMAT_FIELD_SEPERATOR = 2, |
| 1145 | FORMAT_PRINTFMT = 3, |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1146 | }; |
| 1147 | |
| 1148 | 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] | 1149 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1150 | struct trace_event_call *call = event_file_data(m->private); |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 1151 | struct list_head *common_head = &ftrace_common_fields; |
| 1152 | struct list_head *head = trace_get_fields(call); |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1153 | struct list_head *node = v; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1154 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1155 | (*pos)++; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 1156 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1157 | switch ((unsigned long)v) { |
| 1158 | case FORMAT_HEADER: |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1159 | node = common_head; |
| 1160 | break; |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 1161 | |
| 1162 | case FORMAT_FIELD_SEPERATOR: |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1163 | node = head; |
| 1164 | break; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 1165 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1166 | case FORMAT_PRINTFMT: |
| 1167 | /* all done */ |
| 1168 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1171 | node = node->prev; |
| 1172 | if (node == common_head) |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 1173 | return (void *)FORMAT_FIELD_SEPERATOR; |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1174 | else if (node == head) |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1175 | return (void *)FORMAT_PRINTFMT; |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1176 | else |
| 1177 | return node; |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | static int f_show(struct seq_file *m, void *v) |
| 1181 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1182 | struct trace_event_call *call = event_file_data(m->private); |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1183 | struct ftrace_event_field *field; |
| 1184 | const char *array_descriptor; |
| 1185 | |
| 1186 | switch ((unsigned long)v) { |
| 1187 | case FORMAT_HEADER: |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1188 | seq_printf(m, "name: %s\n", trace_event_name(call)); |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1189 | seq_printf(m, "ID: %d\n", call->event.type); |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 1190 | seq_puts(m, "format:\n"); |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 1191 | return 0; |
| 1192 | |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame] | 1193 | case FORMAT_FIELD_SEPERATOR: |
| 1194 | seq_putc(m, '\n'); |
| 1195 | return 0; |
| 1196 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1197 | case FORMAT_PRINTFMT: |
| 1198 | seq_printf(m, "\nprint fmt: %s\n", |
| 1199 | call->print_fmt); |
| 1200 | return 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1201 | } |
| 1202 | |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1203 | field = list_entry(v, struct ftrace_event_field, link); |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1204 | /* |
| 1205 | * Smartly shows the array type(except dynamic array). |
| 1206 | * Normal: |
| 1207 | * field:TYPE VAR |
| 1208 | * If TYPE := TYPE[LEN], it is shown: |
| 1209 | * field:TYPE VAR[LEN] |
| 1210 | */ |
| 1211 | array_descriptor = strchr(field->type, '['); |
| 1212 | |
| 1213 | if (!strncmp(field->type, "__data_loc", 10)) |
| 1214 | array_descriptor = NULL; |
| 1215 | |
| 1216 | if (!array_descriptor) |
| 1217 | seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", |
| 1218 | field->type, field->name, field->offset, |
| 1219 | field->size, !!field->is_signed); |
| 1220 | else |
| 1221 | seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", |
| 1222 | (int)(array_descriptor - field->type), |
| 1223 | field->type, field->name, |
| 1224 | array_descriptor, field->offset, |
| 1225 | field->size, !!field->is_signed); |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1230 | static void *f_start(struct seq_file *m, loff_t *pos) |
| 1231 | { |
| 1232 | void *p = (void *)FORMAT_HEADER; |
| 1233 | loff_t l = 0; |
| 1234 | |
Oleg Nesterov | c5a44a1 | 2013-07-26 19:25:43 +0200 | [diff] [blame] | 1235 | /* ->stop() is called even if ->start() fails */ |
| 1236 | mutex_lock(&event_mutex); |
| 1237 | if (!event_file_data(m->private)) |
| 1238 | return ERR_PTR(-ENODEV); |
| 1239 | |
Oleg Nesterov | 7710b63 | 2013-07-18 20:47:10 +0200 | [diff] [blame] | 1240 | while (l < *pos && p) |
| 1241 | p = f_next(m, p, &l); |
| 1242 | |
| 1243 | return p; |
| 1244 | } |
| 1245 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1246 | static void f_stop(struct seq_file *m, void *p) |
| 1247 | { |
Oleg Nesterov | c5a44a1 | 2013-07-26 19:25:43 +0200 | [diff] [blame] | 1248 | mutex_unlock(&event_mutex); |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static const struct seq_operations trace_format_seq_ops = { |
| 1252 | .start = f_start, |
| 1253 | .next = f_next, |
| 1254 | .stop = f_stop, |
| 1255 | .show = f_show, |
| 1256 | }; |
| 1257 | |
| 1258 | static int trace_format_open(struct inode *inode, struct file *file) |
| 1259 | { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1260 | struct seq_file *m; |
| 1261 | int ret; |
| 1262 | |
| 1263 | ret = seq_open(file, &trace_format_seq_ops); |
| 1264 | if (ret < 0) |
| 1265 | return ret; |
| 1266 | |
| 1267 | m = file->private_data; |
Oleg Nesterov | c5a44a1 | 2013-07-26 19:25:43 +0200 | [diff] [blame] | 1268 | m->private = file; |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1269 | |
| 1270 | return 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1271 | } |
| 1272 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1273 | static ssize_t |
| 1274 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 1275 | { |
Oleg Nesterov | 1a11126 | 2013-07-26 19:25:32 +0200 | [diff] [blame] | 1276 | int id = (long)event_file_data(filp); |
Oleg Nesterov | cd458ba | 2013-07-18 20:47:12 +0200 | [diff] [blame] | 1277 | char buf[32]; |
| 1278 | int len; |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1279 | |
| 1280 | if (*ppos) |
| 1281 | return 0; |
| 1282 | |
Oleg Nesterov | 1a11126 | 2013-07-26 19:25:32 +0200 | [diff] [blame] | 1283 | if (unlikely(!id)) |
| 1284 | return -ENODEV; |
| 1285 | |
| 1286 | len = sprintf(buf, "%d\n", id); |
| 1287 | |
Oleg Nesterov | cd458ba | 2013-07-18 20:47:12 +0200 | [diff] [blame] | 1288 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, len); |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1291 | static ssize_t |
| 1292 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 1293 | loff_t *ppos) |
| 1294 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1295 | struct trace_event_file *file; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1296 | struct trace_seq *s; |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1297 | int r = -ENODEV; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1298 | |
| 1299 | if (*ppos) |
| 1300 | return 0; |
| 1301 | |
| 1302 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1303 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1304 | if (!s) |
| 1305 | return -ENOMEM; |
| 1306 | |
| 1307 | trace_seq_init(s); |
| 1308 | |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1309 | mutex_lock(&event_mutex); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1310 | file = event_file_data(filp); |
| 1311 | if (file) |
| 1312 | print_event_filter(file, s); |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1313 | mutex_unlock(&event_mutex); |
| 1314 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1315 | if (file) |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1316 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 1317 | s->buffer, trace_seq_used(s)); |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1318 | |
| 1319 | kfree(s); |
| 1320 | |
| 1321 | return r; |
| 1322 | } |
| 1323 | |
| 1324 | static ssize_t |
| 1325 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 1326 | loff_t *ppos) |
| 1327 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1328 | struct trace_event_file *file; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1329 | char *buf; |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1330 | int err = -ENODEV; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1331 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1332 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1333 | return -EINVAL; |
| 1334 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1335 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 1336 | if (!buf) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1337 | return -ENOMEM; |
| 1338 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1339 | if (copy_from_user(buf, ubuf, cnt)) { |
| 1340 | free_page((unsigned long) buf); |
| 1341 | return -EFAULT; |
| 1342 | } |
| 1343 | buf[cnt] = '\0'; |
| 1344 | |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1345 | mutex_lock(&event_mutex); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1346 | file = event_file_data(filp); |
| 1347 | if (file) |
| 1348 | err = apply_event_filter(file, buf); |
Oleg Nesterov | e2912b0 | 2013-07-26 19:25:40 +0200 | [diff] [blame] | 1349 | mutex_unlock(&event_mutex); |
| 1350 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1351 | free_page((unsigned long) buf); |
| 1352 | if (err < 0) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1353 | return err; |
Tom Zanussi | 0a19e53 | 2009-04-13 03:17:50 -0500 | [diff] [blame] | 1354 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1355 | *ppos += cnt; |
| 1356 | |
| 1357 | return cnt; |
| 1358 | } |
| 1359 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1360 | static LIST_HEAD(event_subsystems); |
| 1361 | |
| 1362 | static int subsystem_open(struct inode *inode, struct file *filp) |
| 1363 | { |
| 1364 | struct event_subsystem *system = NULL; |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1365 | struct trace_subsystem_dir *dir = NULL; /* Initialize for gcc */ |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1366 | struct trace_array *tr; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1367 | int ret; |
| 1368 | |
Geyslan G. Bem | d6d3523 | 2013-11-06 16:02:51 -0300 | [diff] [blame] | 1369 | if (tracing_is_disabled()) |
| 1370 | return -ENODEV; |
| 1371 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1372 | /* Make sure the system still exists */ |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 1373 | mutex_lock(&trace_types_lock); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1374 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1375 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 1376 | list_for_each_entry(dir, &tr->systems, list) { |
| 1377 | if (dir == inode->i_private) { |
| 1378 | /* Don't open systems with no events */ |
| 1379 | if (dir->nr_events) { |
| 1380 | __get_system_dir(dir); |
| 1381 | system = dir->subsystem; |
| 1382 | } |
| 1383 | goto exit_loop; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1384 | } |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1385 | } |
| 1386 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1387 | exit_loop: |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1388 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 1389 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1390 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1391 | if (!system) |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1392 | return -ENODEV; |
| 1393 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1394 | /* Some versions of gcc think dir can be uninitialized here */ |
| 1395 | WARN_ON(!dir); |
| 1396 | |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1397 | /* Still need to increment the ref count of the system */ |
| 1398 | if (trace_array_get(tr) < 0) { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1399 | put_system(dir); |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1400 | return -ENODEV; |
| 1401 | } |
| 1402 | |
| 1403 | ret = tracing_open_generic(inode, filp); |
| 1404 | if (ret < 0) { |
| 1405 | trace_array_put(tr); |
| 1406 | put_system(dir); |
| 1407 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1408 | |
| 1409 | return ret; |
| 1410 | } |
| 1411 | |
| 1412 | static int system_tr_open(struct inode *inode, struct file *filp) |
| 1413 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1414 | struct trace_subsystem_dir *dir; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1415 | struct trace_array *tr = inode->i_private; |
| 1416 | int ret; |
| 1417 | |
Geyslan G. Bem | d6d3523 | 2013-11-06 16:02:51 -0300 | [diff] [blame] | 1418 | if (tracing_is_disabled()) |
| 1419 | return -ENODEV; |
| 1420 | |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1421 | if (trace_array_get(tr) < 0) |
| 1422 | return -ENODEV; |
| 1423 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1424 | /* Make a temporary dir that has no system but points to tr */ |
| 1425 | dir = kzalloc(sizeof(*dir), GFP_KERNEL); |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1426 | if (!dir) { |
| 1427 | trace_array_put(tr); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1428 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1429 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1430 | |
| 1431 | dir->tr = tr; |
| 1432 | |
| 1433 | ret = tracing_open_generic(inode, filp); |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1434 | if (ret < 0) { |
| 1435 | trace_array_put(tr); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1436 | kfree(dir); |
Geyslan G. Bem | d6d3523 | 2013-11-06 16:02:51 -0300 | [diff] [blame] | 1437 | return ret; |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1438 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1439 | |
| 1440 | filp->private_data = dir; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1441 | |
Geyslan G. Bem | d6d3523 | 2013-11-06 16:02:51 -0300 | [diff] [blame] | 1442 | return 0; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | static int subsystem_release(struct inode *inode, struct file *file) |
| 1446 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1447 | struct trace_subsystem_dir *dir = file->private_data; |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1448 | |
Steven Rostedt (Red Hat) | 8e2e2fa | 2013-07-02 15:30:53 -0400 | [diff] [blame] | 1449 | trace_array_put(dir->tr); |
| 1450 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1451 | /* |
| 1452 | * If dir->subsystem is NULL, then this is a temporary |
| 1453 | * descriptor that was made for a trace_array to enable |
| 1454 | * all subsystems. |
| 1455 | */ |
| 1456 | if (dir->subsystem) |
| 1457 | put_system(dir); |
| 1458 | else |
| 1459 | kfree(dir); |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1460 | |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1464 | static ssize_t |
| 1465 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 1466 | loff_t *ppos) |
| 1467 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1468 | struct trace_subsystem_dir *dir = filp->private_data; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1469 | struct event_subsystem *system = dir->subsystem; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1470 | struct trace_seq *s; |
| 1471 | int r; |
| 1472 | |
| 1473 | if (*ppos) |
| 1474 | return 0; |
| 1475 | |
| 1476 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 1477 | if (!s) |
| 1478 | return -ENOMEM; |
| 1479 | |
| 1480 | trace_seq_init(s); |
| 1481 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1482 | print_subsystem_event_filter(system, s); |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1483 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 1484 | s->buffer, trace_seq_used(s)); |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1485 | |
| 1486 | kfree(s); |
| 1487 | |
| 1488 | return r; |
| 1489 | } |
| 1490 | |
| 1491 | static ssize_t |
| 1492 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 1493 | loff_t *ppos) |
| 1494 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1495 | struct trace_subsystem_dir *dir = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1496 | char *buf; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1497 | int err; |
| 1498 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1499 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1500 | return -EINVAL; |
| 1501 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1502 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 1503 | if (!buf) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1504 | return -ENOMEM; |
| 1505 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1506 | if (copy_from_user(buf, ubuf, cnt)) { |
| 1507 | free_page((unsigned long) buf); |
| 1508 | return -EFAULT; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1509 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1510 | buf[cnt] = '\0'; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1511 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1512 | err = apply_subsystem_event_filter(dir, buf); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1513 | free_page((unsigned long) buf); |
| 1514 | if (err < 0) |
Li Zefan | 44e9c8b | 2009-04-11 15:55:28 +0800 | [diff] [blame] | 1515 | return err; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1516 | |
| 1517 | *ppos += cnt; |
| 1518 | |
| 1519 | return cnt; |
| 1520 | } |
| 1521 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1522 | static ssize_t |
| 1523 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 1524 | { |
| 1525 | int (*func)(struct trace_seq *s) = filp->private_data; |
| 1526 | struct trace_seq *s; |
| 1527 | int r; |
| 1528 | |
| 1529 | if (*ppos) |
| 1530 | return 0; |
| 1531 | |
| 1532 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 1533 | if (!s) |
| 1534 | return -ENOMEM; |
| 1535 | |
| 1536 | trace_seq_init(s); |
| 1537 | |
| 1538 | func(s); |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1539 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 1540 | s->buffer, trace_seq_used(s)); |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1541 | |
| 1542 | kfree(s); |
| 1543 | |
| 1544 | return r; |
| 1545 | } |
| 1546 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1547 | static int max_pids(struct trace_pid_list *pid_list) |
| 1548 | { |
| 1549 | return (PAGE_SIZE << pid_list->order) / sizeof(pid_t); |
| 1550 | } |
| 1551 | |
| 1552 | static ssize_t |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 1553 | ftrace_event_pid_write(struct file *filp, const char __user *ubuf, |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1554 | size_t cnt, loff_t *ppos) |
| 1555 | { |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 1556 | struct seq_file *m = filp->private_data; |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1557 | struct trace_array *tr = m->private; |
| 1558 | struct trace_pid_list *filtered_pids = NULL; |
| 1559 | struct trace_pid_list *pid_list = NULL; |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 1560 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1561 | struct trace_parser parser; |
| 1562 | unsigned long val; |
| 1563 | loff_t this_pos; |
| 1564 | ssize_t read = 0; |
| 1565 | ssize_t ret = 0; |
| 1566 | pid_t pid; |
| 1567 | int i; |
| 1568 | |
| 1569 | if (!cnt) |
| 1570 | return 0; |
| 1571 | |
| 1572 | ret = tracing_update_buffers(); |
| 1573 | if (ret < 0) |
| 1574 | return ret; |
| 1575 | |
| 1576 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
| 1577 | return -ENOMEM; |
| 1578 | |
| 1579 | mutex_lock(&event_mutex); |
| 1580 | /* |
| 1581 | * Load as many pids into the array before doing a |
| 1582 | * swap from the tr->filtered_pids to the new list. |
| 1583 | */ |
| 1584 | while (cnt > 0) { |
| 1585 | |
| 1586 | this_pos = 0; |
| 1587 | |
| 1588 | ret = trace_get_user(&parser, ubuf, cnt, &this_pos); |
| 1589 | if (ret < 0 || !trace_parser_loaded(&parser)) |
| 1590 | break; |
| 1591 | |
| 1592 | read += ret; |
| 1593 | ubuf += ret; |
| 1594 | cnt -= ret; |
| 1595 | |
| 1596 | parser.buffer[parser.idx] = 0; |
| 1597 | |
| 1598 | ret = -EINVAL; |
| 1599 | if (kstrtoul(parser.buffer, 0, &val)) |
| 1600 | break; |
| 1601 | if (val > INT_MAX) |
| 1602 | break; |
| 1603 | |
| 1604 | pid = (pid_t)val; |
| 1605 | |
| 1606 | ret = -ENOMEM; |
| 1607 | if (!pid_list) { |
| 1608 | pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL); |
| 1609 | if (!pid_list) |
| 1610 | break; |
| 1611 | |
| 1612 | filtered_pids = rcu_dereference_protected(tr->filtered_pids, |
| 1613 | lockdep_is_held(&event_mutex)); |
| 1614 | if (filtered_pids) |
| 1615 | pid_list->order = filtered_pids->order; |
| 1616 | else |
| 1617 | pid_list->order = 0; |
| 1618 | |
| 1619 | pid_list->pids = (void *)__get_free_pages(GFP_KERNEL, |
| 1620 | pid_list->order); |
| 1621 | if (!pid_list->pids) |
| 1622 | break; |
| 1623 | |
| 1624 | if (filtered_pids) { |
| 1625 | pid_list->nr_pids = filtered_pids->nr_pids; |
| 1626 | memcpy(pid_list->pids, filtered_pids->pids, |
| 1627 | pid_list->nr_pids * sizeof(pid_t)); |
| 1628 | } else |
| 1629 | pid_list->nr_pids = 0; |
| 1630 | } |
| 1631 | |
| 1632 | if (pid_list->nr_pids >= max_pids(pid_list)) { |
| 1633 | pid_t *pid_page; |
| 1634 | |
| 1635 | pid_page = (void *)__get_free_pages(GFP_KERNEL, |
| 1636 | pid_list->order + 1); |
| 1637 | if (!pid_page) |
| 1638 | break; |
| 1639 | memcpy(pid_page, pid_list->pids, |
| 1640 | pid_list->nr_pids * sizeof(pid_t)); |
| 1641 | free_pages((unsigned long)pid_list->pids, pid_list->order); |
| 1642 | |
| 1643 | pid_list->order++; |
| 1644 | pid_list->pids = pid_page; |
| 1645 | } |
| 1646 | |
| 1647 | pid_list->pids[pid_list->nr_pids++] = pid; |
| 1648 | trace_parser_clear(&parser); |
| 1649 | ret = 0; |
| 1650 | } |
| 1651 | trace_parser_put(&parser); |
| 1652 | |
| 1653 | if (ret < 0) { |
| 1654 | if (pid_list) |
| 1655 | free_pages((unsigned long)pid_list->pids, pid_list->order); |
| 1656 | kfree(pid_list); |
| 1657 | mutex_unlock(&event_mutex); |
| 1658 | return ret; |
| 1659 | } |
| 1660 | |
| 1661 | if (!pid_list) { |
| 1662 | mutex_unlock(&event_mutex); |
| 1663 | return ret; |
| 1664 | } |
| 1665 | |
| 1666 | sort(pid_list->pids, pid_list->nr_pids, sizeof(pid_t), cmp_pid, NULL); |
| 1667 | |
| 1668 | /* Remove duplicates */ |
| 1669 | for (i = 1; i < pid_list->nr_pids; i++) { |
| 1670 | int start = i; |
| 1671 | |
| 1672 | while (i < pid_list->nr_pids && |
| 1673 | pid_list->pids[i - 1] == pid_list->pids[i]) |
| 1674 | i++; |
| 1675 | |
| 1676 | if (start != i) { |
| 1677 | if (i < pid_list->nr_pids) { |
| 1678 | memmove(&pid_list->pids[start], &pid_list->pids[i], |
| 1679 | (pid_list->nr_pids - i) * sizeof(pid_t)); |
| 1680 | pid_list->nr_pids -= i - start; |
| 1681 | i = start; |
| 1682 | } else |
| 1683 | pid_list->nr_pids = start; |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | rcu_assign_pointer(tr->filtered_pids, pid_list); |
| 1688 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 1689 | list_for_each_entry(file, &tr->events, list) { |
| 1690 | set_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags); |
| 1691 | } |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1692 | |
| 1693 | if (filtered_pids) { |
| 1694 | synchronize_sched(); |
| 1695 | |
| 1696 | free_pages((unsigned long)filtered_pids->pids, filtered_pids->order); |
| 1697 | kfree(filtered_pids); |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 1698 | } else { |
| 1699 | /* |
| 1700 | * Register a probe that is called before all other probes |
| 1701 | * to set ignore_pid if next or prev do not match. |
| 1702 | * Register a probe this is called after all other probes |
| 1703 | * to only keep ignore_pid set if next pid matches. |
| 1704 | */ |
| 1705 | register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre, |
| 1706 | tr, INT_MAX); |
| 1707 | register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post, |
| 1708 | tr, 0); |
| 1709 | |
| 1710 | register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, |
| 1711 | tr, INT_MAX); |
| 1712 | register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, |
| 1713 | tr, 0); |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1714 | } |
| 1715 | |
Steven Rostedt (Red Hat) | 3fdaf80 | 2015-09-25 12:58:44 -0400 | [diff] [blame^] | 1716 | mutex_unlock(&event_mutex); |
| 1717 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1718 | ret = read; |
| 1719 | *ppos += read; |
| 1720 | |
| 1721 | return ret; |
| 1722 | } |
| 1723 | |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1724 | static int ftrace_event_avail_open(struct inode *inode, struct file *file); |
| 1725 | static int ftrace_event_set_open(struct inode *inode, struct file *file); |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1726 | static int ftrace_event_set_pid_open(struct inode *inode, struct file *file); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 1727 | static int ftrace_event_release(struct inode *inode, struct file *file); |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1728 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1729 | static const struct seq_operations show_event_seq_ops = { |
| 1730 | .start = t_start, |
| 1731 | .next = t_next, |
| 1732 | .show = t_show, |
| 1733 | .stop = t_stop, |
| 1734 | }; |
| 1735 | |
| 1736 | static const struct seq_operations show_set_event_seq_ops = { |
| 1737 | .start = s_start, |
| 1738 | .next = s_next, |
| 1739 | .show = t_show, |
| 1740 | .stop = t_stop, |
| 1741 | }; |
| 1742 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1743 | static const struct seq_operations show_set_pid_seq_ops = { |
| 1744 | .start = p_start, |
| 1745 | .next = p_next, |
| 1746 | .show = p_show, |
| 1747 | .stop = p_stop, |
| 1748 | }; |
| 1749 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1750 | static const struct file_operations ftrace_avail_fops = { |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1751 | .open = ftrace_event_avail_open, |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1752 | .read = seq_read, |
| 1753 | .llseek = seq_lseek, |
| 1754 | .release = seq_release, |
| 1755 | }; |
| 1756 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1757 | static const struct file_operations ftrace_set_event_fops = { |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1758 | .open = ftrace_event_set_open, |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1759 | .read = seq_read, |
| 1760 | .write = ftrace_event_write, |
| 1761 | .llseek = seq_lseek, |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 1762 | .release = ftrace_event_release, |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1763 | }; |
| 1764 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1765 | static const struct file_operations ftrace_set_event_pid_fops = { |
| 1766 | .open = ftrace_event_set_pid_open, |
| 1767 | .read = seq_read, |
| 1768 | .write = ftrace_event_pid_write, |
| 1769 | .llseek = seq_lseek, |
| 1770 | .release = ftrace_event_release, |
| 1771 | }; |
| 1772 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1773 | static const struct file_operations ftrace_enable_fops = { |
Oleg Nesterov | bf682c3 | 2013-07-28 20:35:27 +0200 | [diff] [blame] | 1774 | .open = tracing_open_generic, |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1775 | .read = event_enable_read, |
| 1776 | .write = event_enable_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1777 | .llseek = default_llseek, |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1778 | }; |
| 1779 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1780 | static const struct file_operations ftrace_event_format_fops = { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 1781 | .open = trace_format_open, |
| 1782 | .read = seq_read, |
| 1783 | .llseek = seq_lseek, |
| 1784 | .release = seq_release, |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 1785 | }; |
| 1786 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1787 | static const struct file_operations ftrace_event_id_fops = { |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1788 | .read = event_id_read, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1789 | .llseek = default_llseek, |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1790 | }; |
| 1791 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1792 | static const struct file_operations ftrace_event_filter_fops = { |
| 1793 | .open = tracing_open_generic, |
| 1794 | .read = event_filter_read, |
| 1795 | .write = event_filter_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1796 | .llseek = default_llseek, |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 1797 | }; |
| 1798 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1799 | static const struct file_operations ftrace_subsystem_filter_fops = { |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1800 | .open = subsystem_open, |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1801 | .read = subsystem_filter_read, |
| 1802 | .write = subsystem_filter_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1803 | .llseek = default_llseek, |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1804 | .release = subsystem_release, |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1805 | }; |
| 1806 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1807 | static const struct file_operations ftrace_system_enable_fops = { |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1808 | .open = subsystem_open, |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1809 | .read = system_enable_read, |
| 1810 | .write = system_enable_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1811 | .llseek = default_llseek, |
Steven Rostedt | 40ee4df | 2011-07-05 14:32:51 -0400 | [diff] [blame] | 1812 | .release = subsystem_release, |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1813 | }; |
| 1814 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1815 | static const struct file_operations ftrace_tr_enable_fops = { |
| 1816 | .open = system_tr_open, |
| 1817 | .read = system_enable_read, |
| 1818 | .write = system_enable_write, |
| 1819 | .llseek = default_llseek, |
| 1820 | .release = subsystem_release, |
| 1821 | }; |
| 1822 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1823 | static const struct file_operations ftrace_show_header_fops = { |
| 1824 | .open = tracing_open_generic, |
| 1825 | .read = show_header, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1826 | .llseek = default_llseek, |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1827 | }; |
| 1828 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1829 | static int |
| 1830 | ftrace_event_open(struct inode *inode, struct file *file, |
| 1831 | const struct seq_operations *seq_ops) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1832 | { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1833 | struct seq_file *m; |
| 1834 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1835 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1836 | ret = seq_open(file, seq_ops); |
| 1837 | if (ret < 0) |
| 1838 | return ret; |
| 1839 | m = file->private_data; |
| 1840 | /* copy tr over to seq ops */ |
| 1841 | m->private = inode->i_private; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1842 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1843 | return ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1844 | } |
| 1845 | |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 1846 | static int ftrace_event_release(struct inode *inode, struct file *file) |
| 1847 | { |
| 1848 | struct trace_array *tr = inode->i_private; |
| 1849 | |
| 1850 | trace_array_put(tr); |
| 1851 | |
| 1852 | return seq_release(inode, file); |
| 1853 | } |
| 1854 | |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1855 | static int |
| 1856 | ftrace_event_avail_open(struct inode *inode, struct file *file) |
| 1857 | { |
| 1858 | const struct seq_operations *seq_ops = &show_event_seq_ops; |
| 1859 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1860 | return ftrace_event_open(inode, file, seq_ops); |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | static int |
| 1864 | ftrace_event_set_open(struct inode *inode, struct file *file) |
| 1865 | { |
| 1866 | const struct seq_operations *seq_ops = &show_set_event_seq_ops; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1867 | struct trace_array *tr = inode->i_private; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 1868 | int ret; |
| 1869 | |
| 1870 | if (trace_array_get(tr) < 0) |
| 1871 | return -ENODEV; |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1872 | |
| 1873 | if ((file->f_mode & FMODE_WRITE) && |
| 1874 | (file->f_flags & O_TRUNC)) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1875 | ftrace_clear_events(tr); |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1876 | |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 1877 | ret = ftrace_event_open(inode, file, seq_ops); |
| 1878 | if (ret < 0) |
| 1879 | trace_array_put(tr); |
| 1880 | return ret; |
Steven Rostedt | 15075ca | 2012-05-03 14:57:28 -0400 | [diff] [blame] | 1881 | } |
| 1882 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 1883 | static int |
| 1884 | ftrace_event_set_pid_open(struct inode *inode, struct file *file) |
| 1885 | { |
| 1886 | const struct seq_operations *seq_ops = &show_set_pid_seq_ops; |
| 1887 | struct trace_array *tr = inode->i_private; |
| 1888 | int ret; |
| 1889 | |
| 1890 | if (trace_array_get(tr) < 0) |
| 1891 | return -ENODEV; |
| 1892 | |
| 1893 | if ((file->f_mode & FMODE_WRITE) && |
| 1894 | (file->f_flags & O_TRUNC)) |
| 1895 | ftrace_clear_event_pids(tr); |
| 1896 | |
| 1897 | ret = ftrace_event_open(inode, file, seq_ops); |
| 1898 | if (ret < 0) |
| 1899 | trace_array_put(tr); |
| 1900 | return ret; |
| 1901 | } |
| 1902 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1903 | static struct event_subsystem * |
| 1904 | create_new_subsystem(const char *name) |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1905 | { |
| 1906 | struct event_subsystem *system; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1907 | |
| 1908 | /* need to create new entry */ |
| 1909 | system = kmalloc(sizeof(*system), GFP_KERNEL); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1910 | if (!system) |
| 1911 | return NULL; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1912 | |
Steven Rostedt | e9dbfae | 2011-07-05 11:36:06 -0400 | [diff] [blame] | 1913 | system->ref_count = 1; |
Steven Rostedt | 6e94a78 | 2013-06-27 10:58:31 -0400 | [diff] [blame] | 1914 | |
| 1915 | /* Only allocate if dynamic (kprobes and modules) */ |
Rasmus Villemoes | 79ac6ef | 2015-09-09 23:24:01 +0200 | [diff] [blame] | 1916 | system->name = kstrdup_const(name, GFP_KERNEL); |
| 1917 | if (!system->name) |
| 1918 | goto out_free; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1919 | |
Tom Zanussi | 30e673b | 2009-04-28 03:04:47 -0500 | [diff] [blame] | 1920 | system->filter = NULL; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1921 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1922 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1923 | if (!system->filter) |
| 1924 | goto out_free; |
| 1925 | |
| 1926 | list_add(&system->list, &event_subsystems); |
| 1927 | |
| 1928 | return system; |
| 1929 | |
| 1930 | out_free: |
Rasmus Villemoes | 79ac6ef | 2015-09-09 23:24:01 +0200 | [diff] [blame] | 1931 | kfree_const(system->name); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1932 | kfree(system); |
| 1933 | return NULL; |
| 1934 | } |
| 1935 | |
| 1936 | static struct dentry * |
| 1937 | event_subsystem_dir(struct trace_array *tr, const char *name, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1938 | struct trace_event_file *file, struct dentry *parent) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1939 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 1940 | struct trace_subsystem_dir *dir; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1941 | struct event_subsystem *system; |
| 1942 | struct dentry *entry; |
| 1943 | |
| 1944 | /* First see if we did not already create this dir */ |
| 1945 | list_for_each_entry(dir, &tr->systems, list) { |
| 1946 | system = dir->subsystem; |
| 1947 | if (strcmp(system->name, name) == 0) { |
| 1948 | dir->nr_events++; |
| 1949 | file->system = dir; |
| 1950 | return dir->entry; |
| 1951 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1952 | } |
| 1953 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1954 | /* Now see if the system itself exists. */ |
| 1955 | list_for_each_entry(system, &event_subsystems, list) { |
| 1956 | if (strcmp(system->name, name) == 0) |
| 1957 | break; |
| 1958 | } |
| 1959 | /* Reset system variable when not found */ |
| 1960 | if (&system->list == &event_subsystems) |
| 1961 | system = NULL; |
| 1962 | |
| 1963 | dir = kmalloc(sizeof(*dir), GFP_KERNEL); |
| 1964 | if (!dir) |
| 1965 | goto out_fail; |
| 1966 | |
| 1967 | if (!system) { |
| 1968 | system = create_new_subsystem(name); |
| 1969 | if (!system) |
| 1970 | goto out_free; |
| 1971 | } else |
| 1972 | __get_system(system); |
| 1973 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 1974 | dir->entry = tracefs_create_dir(name, parent); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1975 | if (!dir->entry) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 1976 | pr_warn("Failed to create system directory %s\n", name); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1977 | __put_system(system); |
| 1978 | goto out_free; |
| 1979 | } |
| 1980 | |
| 1981 | dir->tr = tr; |
| 1982 | dir->ref_count = 1; |
| 1983 | dir->nr_events = 1; |
| 1984 | dir->subsystem = system; |
| 1985 | file->system = dir; |
| 1986 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 1987 | entry = tracefs_create_file("filter", 0644, dir->entry, dir, |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1988 | &ftrace_subsystem_filter_fops); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1989 | if (!entry) { |
| 1990 | kfree(system->filter); |
| 1991 | system->filter = NULL; |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 1992 | pr_warn("Could not create tracefs '%s/filter' entry\n", name); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1993 | } |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1994 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1995 | trace_create_file("enable", 0644, dir->entry, dir, |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1996 | &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1997 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 1998 | list_add(&dir->list, &tr->systems); |
| 1999 | |
| 2000 | return dir->entry; |
| 2001 | |
| 2002 | out_free: |
| 2003 | kfree(dir); |
| 2004 | out_fail: |
| 2005 | /* Only print this message if failed on memory allocation */ |
| 2006 | if (!dir || !system) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 2007 | pr_warn("No memory to create event subsystem %s\n", name); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2008 | return NULL; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 2009 | } |
| 2010 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 2011 | static int |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2012 | event_create_dir(struct dentry *parent, struct trace_event_file *file) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 2013 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2014 | struct trace_event_call *call = file->event_call; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2015 | struct trace_array *tr = file->tr; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 2016 | struct list_head *head; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2017 | struct dentry *d_events; |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 2018 | const char *name; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 2019 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 2020 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 2021 | /* |
| 2022 | * If the trace point header did not define TRACE_SYSTEM |
| 2023 | * then the system would be called "TRACE_SYSTEM". |
| 2024 | */ |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2025 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) { |
| 2026 | d_events = event_subsystem_dir(tr, call->class->system, file, parent); |
| 2027 | if (!d_events) |
| 2028 | return -ENOMEM; |
| 2029 | } else |
| 2030 | d_events = parent; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 2031 | |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2032 | name = trace_event_name(call); |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2033 | file->dir = tracefs_create_dir(name, d_events); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2034 | if (!file->dir) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2035 | pr_warn("Could not create tracefs '%s' directory\n", name); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 2036 | return -1; |
| 2037 | } |
| 2038 | |
Steven Rostedt | 9b63776 | 2012-05-10 15:55:43 -0400 | [diff] [blame] | 2039 | if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2040 | trace_create_file("enable", 0644, file->dir, file, |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2041 | &ftrace_enable_fops); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 2042 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 2043 | #ifdef CONFIG_PERF_EVENTS |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 2044 | if (call->event.type && call->class->reg) |
Oleg Nesterov | 1a11126 | 2013-07-26 19:25:32 +0200 | [diff] [blame] | 2045 | trace_create_file("id", 0444, file->dir, |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2046 | (void *)(long)call->event.type, |
| 2047 | &ftrace_event_id_fops); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 2048 | #endif |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 2049 | |
Li Zefan | c9d932c | 2010-05-24 16:24:28 +0800 | [diff] [blame] | 2050 | /* |
| 2051 | * Other events may have the same class. Only update |
| 2052 | * the fields if they are not already defined. |
| 2053 | */ |
| 2054 | head = trace_get_fields(call); |
| 2055 | if (list_empty(head)) { |
| 2056 | ret = call->class->define_fields(call); |
| 2057 | if (ret < 0) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 2058 | pr_warn("Could not initialize trace point events/%s\n", |
| 2059 | name); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2060 | return -1; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 2061 | } |
| 2062 | } |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2063 | trace_create_file("filter", 0644, file->dir, file, |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2064 | &ftrace_event_filter_fops); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 2065 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 2066 | trace_create_file("trigger", 0644, file->dir, file, |
| 2067 | &event_trigger_fops); |
| 2068 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2069 | trace_create_file("format", 0444, file->dir, call, |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2070 | &ftrace_event_format_fops); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 2071 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 2072 | return 0; |
| 2073 | } |
| 2074 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2075 | static void remove_event_from_tracers(struct trace_event_call *call) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2076 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2077 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2078 | struct trace_array *tr; |
| 2079 | |
| 2080 | do_for_each_event_file_safe(tr, file) { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2081 | if (file->event_call != call) |
| 2082 | continue; |
| 2083 | |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 2084 | remove_event_file_dir(file); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2085 | /* |
| 2086 | * The do_for_each_event_file_safe() is |
| 2087 | * a double loop. After finding the call for this |
| 2088 | * trace_array, we use break to jump to the next |
| 2089 | * trace_array. |
| 2090 | */ |
| 2091 | break; |
| 2092 | } while_for_each_event_file(); |
| 2093 | } |
| 2094 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2095 | static void event_remove(struct trace_event_call *call) |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2096 | { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2097 | struct trace_array *tr; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2098 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2099 | |
| 2100 | do_for_each_event_file(tr, file) { |
| 2101 | if (file->event_call != call) |
| 2102 | continue; |
| 2103 | ftrace_event_enable_disable(file, 0); |
| 2104 | /* |
| 2105 | * The do_for_each_event_file() is |
| 2106 | * a double loop. After finding the call for this |
| 2107 | * trace_array, we use break to jump to the next |
| 2108 | * trace_array. |
| 2109 | */ |
| 2110 | break; |
| 2111 | } while_for_each_event_file(); |
| 2112 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2113 | if (call->event.funcs) |
Steven Rostedt (Red Hat) | 9023c93 | 2015-05-05 09:39:12 -0400 | [diff] [blame] | 2114 | __unregister_trace_event(&call->event); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2115 | remove_event_from_tracers(call); |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2116 | list_del(&call->list); |
| 2117 | } |
| 2118 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2119 | static int event_init(struct trace_event_call *call) |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2120 | { |
| 2121 | int ret = 0; |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 2122 | const char *name; |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2123 | |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2124 | name = trace_event_name(call); |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 2125 | if (WARN_ON(!name)) |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2126 | return -EINVAL; |
| 2127 | |
| 2128 | if (call->class->raw_init) { |
| 2129 | ret = call->class->raw_init(call); |
| 2130 | if (ret < 0 && ret != -ENOSYS) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 2131 | pr_warn("Could not initialize trace events/%s\n", name); |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | return ret; |
| 2135 | } |
| 2136 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 2137 | static int |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2138 | __register_event(struct trace_event_call *call, struct module *mod) |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2139 | { |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2140 | int ret; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2141 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2142 | ret = event_init(call); |
| 2143 | if (ret < 0) |
| 2144 | return ret; |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 2145 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2146 | list_add(&call->list, &ftrace_events); |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 2147 | call->mod = mod; |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 2148 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2149 | return 0; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2150 | } |
| 2151 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 2152 | static char *enum_replace(char *ptr, struct trace_enum_map *map, int len) |
| 2153 | { |
| 2154 | int rlen; |
| 2155 | int elen; |
| 2156 | |
| 2157 | /* Find the length of the enum value as a string */ |
| 2158 | elen = snprintf(ptr, 0, "%ld", map->enum_value); |
| 2159 | /* Make sure there's enough room to replace the string with the value */ |
| 2160 | if (len < elen) |
| 2161 | return NULL; |
| 2162 | |
| 2163 | snprintf(ptr, elen + 1, "%ld", map->enum_value); |
| 2164 | |
| 2165 | /* Get the rest of the string of ptr */ |
| 2166 | rlen = strlen(ptr + len); |
| 2167 | memmove(ptr + elen, ptr + len, rlen); |
| 2168 | /* Make sure we end the new string */ |
| 2169 | ptr[elen + rlen] = 0; |
| 2170 | |
| 2171 | return ptr + elen; |
| 2172 | } |
| 2173 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2174 | static void update_event_printk(struct trace_event_call *call, |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 2175 | struct trace_enum_map *map) |
| 2176 | { |
| 2177 | char *ptr; |
| 2178 | int quote = 0; |
| 2179 | int len = strlen(map->enum_string); |
| 2180 | |
| 2181 | for (ptr = call->print_fmt; *ptr; ptr++) { |
| 2182 | if (*ptr == '\\') { |
| 2183 | ptr++; |
| 2184 | /* paranoid */ |
| 2185 | if (!*ptr) |
| 2186 | break; |
| 2187 | continue; |
| 2188 | } |
| 2189 | if (*ptr == '"') { |
| 2190 | quote ^= 1; |
| 2191 | continue; |
| 2192 | } |
| 2193 | if (quote) |
| 2194 | continue; |
| 2195 | if (isdigit(*ptr)) { |
| 2196 | /* skip numbers */ |
| 2197 | do { |
| 2198 | ptr++; |
| 2199 | /* Check for alpha chars like ULL */ |
| 2200 | } while (isalnum(*ptr)); |
Steven Rostedt (Red Hat) | 3193899 | 2015-04-17 10:27:57 -0400 | [diff] [blame] | 2201 | if (!*ptr) |
| 2202 | break; |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 2203 | /* |
| 2204 | * A number must have some kind of delimiter after |
| 2205 | * it, and we can ignore that too. |
| 2206 | */ |
| 2207 | continue; |
| 2208 | } |
| 2209 | if (isalpha(*ptr) || *ptr == '_') { |
| 2210 | if (strncmp(map->enum_string, ptr, len) == 0 && |
| 2211 | !isalnum(ptr[len]) && ptr[len] != '_') { |
| 2212 | ptr = enum_replace(ptr, map, len); |
| 2213 | /* Hmm, enum string smaller than value */ |
| 2214 | if (WARN_ON_ONCE(!ptr)) |
| 2215 | return; |
| 2216 | /* |
| 2217 | * No need to decrement here, as enum_replace() |
| 2218 | * returns the pointer to the character passed |
| 2219 | * the enum, and two enums can not be placed |
| 2220 | * back to back without something in between. |
| 2221 | * We can skip that something in between. |
| 2222 | */ |
| 2223 | continue; |
| 2224 | } |
| 2225 | skip_more: |
| 2226 | do { |
| 2227 | ptr++; |
| 2228 | } while (isalnum(*ptr) || *ptr == '_'); |
Steven Rostedt (Red Hat) | 3193899 | 2015-04-17 10:27:57 -0400 | [diff] [blame] | 2229 | if (!*ptr) |
| 2230 | break; |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 2231 | /* |
| 2232 | * If what comes after this variable is a '.' or |
| 2233 | * '->' then we can continue to ignore that string. |
| 2234 | */ |
| 2235 | if (*ptr == '.' || (ptr[0] == '-' && ptr[1] == '>')) { |
| 2236 | ptr += *ptr == '.' ? 1 : 2; |
Steven Rostedt (Red Hat) | 3193899 | 2015-04-17 10:27:57 -0400 | [diff] [blame] | 2237 | if (!*ptr) |
| 2238 | break; |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 2239 | goto skip_more; |
| 2240 | } |
| 2241 | /* |
| 2242 | * Once again, we can skip the delimiter that came |
| 2243 | * after the string. |
| 2244 | */ |
| 2245 | continue; |
| 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | void trace_event_enum_update(struct trace_enum_map **map, int len) |
| 2251 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2252 | struct trace_event_call *call, *p; |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 2253 | const char *last_system = NULL; |
| 2254 | int last_i; |
| 2255 | int i; |
| 2256 | |
| 2257 | down_write(&trace_event_sem); |
| 2258 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
| 2259 | /* events are usually grouped together with systems */ |
| 2260 | if (!last_system || call->class->system != last_system) { |
| 2261 | last_i = 0; |
| 2262 | last_system = call->class->system; |
| 2263 | } |
| 2264 | |
| 2265 | for (i = last_i; i < len; i++) { |
| 2266 | if (call->class->system == map[i]->system) { |
| 2267 | /* Save the first system if need be */ |
| 2268 | if (!last_i) |
| 2269 | last_i = i; |
| 2270 | update_event_printk(call, map[i]); |
| 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | up_write(&trace_event_sem); |
| 2275 | } |
| 2276 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2277 | static struct trace_event_file * |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2278 | trace_create_new_event(struct trace_event_call *call, |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 2279 | struct trace_array *tr) |
| 2280 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2281 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 2282 | |
| 2283 | file = kmem_cache_alloc(file_cachep, GFP_TRACE); |
| 2284 | if (!file) |
| 2285 | return NULL; |
| 2286 | |
| 2287 | file->event_call = call; |
| 2288 | file->tr = tr; |
| 2289 | atomic_set(&file->sm_ref, 0); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 2290 | atomic_set(&file->tm_ref, 0); |
| 2291 | INIT_LIST_HEAD(&file->triggers); |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 2292 | list_add(&file->list, &tr->events); |
| 2293 | |
| 2294 | return file; |
| 2295 | } |
| 2296 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2297 | /* Add an event to a trace directory */ |
| 2298 | static int |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2299 | __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2300 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2301 | struct trace_event_file *file; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2302 | |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 2303 | file = trace_create_new_event(call, tr); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2304 | if (!file) |
| 2305 | return -ENOMEM; |
| 2306 | |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2307 | return event_create_dir(tr->event_dir, file); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2310 | /* |
| 2311 | * Just create a decriptor for early init. A descriptor is required |
| 2312 | * for enabling events at boot. We want to enable events before |
| 2313 | * the filesystem is initialized. |
| 2314 | */ |
| 2315 | static __init int |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2316 | __trace_early_add_new_event(struct trace_event_call *call, |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2317 | struct trace_array *tr) |
| 2318 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2319 | struct trace_event_file *file; |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2320 | |
Steven Rostedt (Red Hat) | da511bf | 2013-05-09 15:00:07 -0400 | [diff] [blame] | 2321 | file = trace_create_new_event(call, tr); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2322 | if (!file) |
| 2323 | return -ENOMEM; |
| 2324 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2325 | return 0; |
| 2326 | } |
| 2327 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2328 | struct ftrace_module_file_ops; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2329 | static void __add_event_to_tracers(struct trace_event_call *call); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2330 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2331 | /* Add an additional event_call dynamically */ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2332 | int trace_add_event_call(struct trace_event_call *call) |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2333 | { |
| 2334 | int ret; |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2335 | mutex_lock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2336 | mutex_lock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2337 | |
| 2338 | ret = __register_event(call, NULL); |
| 2339 | if (ret >= 0) |
Oleg Nesterov | 779c5e3 | 2013-07-31 19:31:32 +0200 | [diff] [blame] | 2340 | __add_event_to_tracers(call); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2341 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2342 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2343 | mutex_unlock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2344 | return ret; |
| 2345 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 2346 | |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 2347 | /* |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2348 | * Must be called under locking of trace_types_lock, event_mutex and |
| 2349 | * trace_event_sem. |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 2350 | */ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2351 | static void __trace_remove_event_call(struct trace_event_call *call) |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2352 | { |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 2353 | event_remove(call); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2354 | trace_destroy_fields(call); |
Oleg Nesterov | 5737574 | 2014-07-15 20:48:16 +0200 | [diff] [blame] | 2355 | free_event_filter(call->filter); |
| 2356 | call->filter = NULL; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2357 | } |
| 2358 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2359 | static int probe_remove_event_call(struct trace_event_call *call) |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2360 | { |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2361 | struct trace_array *tr; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2362 | struct trace_event_file *file; |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2363 | |
| 2364 | #ifdef CONFIG_PERF_EVENTS |
| 2365 | if (call->perf_refcount) |
| 2366 | return -EBUSY; |
| 2367 | #endif |
| 2368 | do_for_each_event_file(tr, file) { |
| 2369 | if (file->event_call != call) |
| 2370 | continue; |
| 2371 | /* |
| 2372 | * We can't rely on ftrace_event_enable_disable(enable => 0) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 2373 | * we are going to do, EVENT_FILE_FL_SOFT_MODE can suppress |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2374 | * TRACE_REG_UNREGISTER. |
| 2375 | */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 2376 | if (file->flags & EVENT_FILE_FL_ENABLED) |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2377 | return -EBUSY; |
Steven Rostedt (Red Hat) | 2ba6403 | 2013-07-31 13:16:22 -0400 | [diff] [blame] | 2378 | /* |
| 2379 | * The do_for_each_event_file_safe() is |
| 2380 | * a double loop. After finding the call for this |
| 2381 | * trace_array, we use break to jump to the next |
| 2382 | * trace_array. |
| 2383 | */ |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2384 | break; |
| 2385 | } while_for_each_event_file(); |
| 2386 | |
| 2387 | __trace_remove_event_call(call); |
| 2388 | |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
| 2392 | /* Remove an event_call */ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2393 | int trace_remove_event_call(struct trace_event_call *call) |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2394 | { |
| 2395 | int ret; |
| 2396 | |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2397 | mutex_lock(&trace_types_lock); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2398 | mutex_lock(&event_mutex); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2399 | down_write(&trace_event_sem); |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2400 | ret = probe_remove_event_call(call); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2401 | up_write(&trace_event_sem); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2402 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2403 | mutex_unlock(&trace_types_lock); |
Oleg Nesterov | 2816c55 | 2013-07-29 19:50:33 +0200 | [diff] [blame] | 2404 | |
| 2405 | return ret; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | #define for_each_event(event, start, end) \ |
| 2409 | for (event = start; \ |
| 2410 | (unsigned long)event < (unsigned long)end; \ |
| 2411 | event++) |
| 2412 | |
| 2413 | #ifdef CONFIG_MODULES |
| 2414 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2415 | static void trace_module_add_events(struct module *mod) |
| 2416 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2417 | struct trace_event_call **call, **start, **end; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2418 | |
Steven Rostedt (Red Hat) | 45ab281 | 2014-02-26 13:37:38 -0500 | [diff] [blame] | 2419 | if (!mod->num_trace_events) |
| 2420 | return; |
| 2421 | |
| 2422 | /* Don't add infrastructure for mods without tracepoints */ |
| 2423 | if (trace_module_has_bad_taint(mod)) { |
| 2424 | pr_err("%s: module has bad taint, not creating trace events\n", |
| 2425 | mod->name); |
| 2426 | return; |
| 2427 | } |
| 2428 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2429 | start = mod->trace_events; |
| 2430 | end = mod->trace_events + mod->num_trace_events; |
| 2431 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2432 | for_each_event(call, start, end) { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2433 | __register_event(*call, mod); |
Oleg Nesterov | 779c5e3 | 2013-07-31 19:31:32 +0200 | [diff] [blame] | 2434 | __add_event_to_tracers(*call); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | static void trace_module_remove_events(struct module *mod) |
| 2439 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2440 | struct trace_event_call *call, *p; |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 2441 | bool clear_trace = false; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2442 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2443 | down_write(&trace_event_sem); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2444 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
| 2445 | if (call->mod == mod) { |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 2446 | if (call->flags & TRACE_EVENT_FL_WAS_ENABLED) |
| 2447 | clear_trace = true; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 2448 | __trace_remove_event_call(call); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2449 | } |
| 2450 | } |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2451 | up_write(&trace_event_sem); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 2452 | |
| 2453 | /* |
| 2454 | * It is safest to reset the ring buffer if the module being unloaded |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 2455 | * registered any events that were used. The only worry is if |
| 2456 | * a new module gets loaded, and takes on the same id as the events |
| 2457 | * of this module. When printing out the buffer, traced events left |
| 2458 | * over from this module may be passed to the new module events and |
| 2459 | * unexpected results may occur. |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 2460 | */ |
Steven Rostedt (Red Hat) | 575380d | 2013-03-04 23:05:12 -0500 | [diff] [blame] | 2461 | if (clear_trace) |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 2462 | tracing_reset_all_online_cpus(); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2463 | } |
| 2464 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 2465 | static int trace_module_notify(struct notifier_block *self, |
| 2466 | unsigned long val, void *data) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2467 | { |
| 2468 | struct module *mod = data; |
| 2469 | |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2470 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2471 | mutex_lock(&event_mutex); |
| 2472 | switch (val) { |
| 2473 | case MODULE_STATE_COMING: |
| 2474 | trace_module_add_events(mod); |
| 2475 | break; |
| 2476 | case MODULE_STATE_GOING: |
| 2477 | trace_module_remove_events(mod); |
| 2478 | break; |
| 2479 | } |
| 2480 | mutex_unlock(&event_mutex); |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 2481 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2482 | |
| 2483 | return 0; |
| 2484 | } |
Steven Rostedt (Red Hat) | 315326c | 2013-03-02 17:37:14 -0500 | [diff] [blame] | 2485 | |
Oleg Nesterov | 836d481 | 2013-07-31 19:31:37 +0200 | [diff] [blame] | 2486 | static struct notifier_block trace_module_nb = { |
| 2487 | .notifier_call = trace_module_notify, |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 2488 | .priority = 1, /* higher than trace.c module notify */ |
Oleg Nesterov | 836d481 | 2013-07-31 19:31:37 +0200 | [diff] [blame] | 2489 | }; |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 2490 | #endif /* CONFIG_MODULES */ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 2491 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2492 | /* Create a new event directory structure for a trace directory. */ |
| 2493 | static void |
| 2494 | __trace_add_event_dirs(struct trace_array *tr) |
| 2495 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2496 | struct trace_event_call *call; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2497 | int ret; |
| 2498 | |
| 2499 | list_for_each_entry(call, &ftrace_events, list) { |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2500 | ret = __trace_add_new_event(call, tr); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2501 | if (ret < 0) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 2502 | pr_warn("Could not create directory for event %s\n", |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2503 | trace_event_name(call)); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2507 | struct trace_event_file * |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2508 | find_event_file(struct trace_array *tr, const char *system, const char *event) |
| 2509 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2510 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2511 | struct trace_event_call *call; |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 2512 | const char *name; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2513 | |
| 2514 | list_for_each_entry(file, &tr->events, list) { |
| 2515 | |
| 2516 | call = file->event_call; |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2517 | name = trace_event_name(call); |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2518 | |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 2519 | if (!name || !call->class || !call->class->reg) |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2520 | continue; |
| 2521 | |
| 2522 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) |
| 2523 | continue; |
| 2524 | |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 2525 | if (strcmp(event, name) == 0 && |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2526 | strcmp(system, call->class->system) == 0) |
| 2527 | return file; |
| 2528 | } |
| 2529 | return NULL; |
| 2530 | } |
| 2531 | |
Steven Rostedt (Red Hat) | 2875a08 | 2013-12-20 23:23:05 -0500 | [diff] [blame] | 2532 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 2533 | |
| 2534 | /* Avoid typos */ |
| 2535 | #define ENABLE_EVENT_STR "enable_event" |
| 2536 | #define DISABLE_EVENT_STR "disable_event" |
| 2537 | |
| 2538 | struct event_probe_data { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2539 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | 2875a08 | 2013-12-20 23:23:05 -0500 | [diff] [blame] | 2540 | unsigned long count; |
| 2541 | int ref; |
| 2542 | bool enable; |
| 2543 | }; |
| 2544 | |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2545 | static void |
| 2546 | event_enable_probe(unsigned long ip, unsigned long parent_ip, void **_data) |
| 2547 | { |
| 2548 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 2549 | struct event_probe_data *data = *pdata; |
| 2550 | |
| 2551 | if (!data) |
| 2552 | return; |
| 2553 | |
| 2554 | if (data->enable) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 2555 | clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags); |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2556 | else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 2557 | set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags); |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | static void |
| 2561 | event_enable_count_probe(unsigned long ip, unsigned long parent_ip, void **_data) |
| 2562 | { |
| 2563 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 2564 | struct event_probe_data *data = *pdata; |
| 2565 | |
| 2566 | if (!data) |
| 2567 | return; |
| 2568 | |
| 2569 | if (!data->count) |
| 2570 | return; |
| 2571 | |
| 2572 | /* Skip if the event is in a state we want to switch to */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 2573 | if (data->enable == !(data->file->flags & EVENT_FILE_FL_SOFT_DISABLED)) |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2574 | return; |
| 2575 | |
| 2576 | if (data->count != -1) |
| 2577 | (data->count)--; |
| 2578 | |
| 2579 | event_enable_probe(ip, parent_ip, _data); |
| 2580 | } |
| 2581 | |
| 2582 | static int |
| 2583 | event_enable_print(struct seq_file *m, unsigned long ip, |
| 2584 | struct ftrace_probe_ops *ops, void *_data) |
| 2585 | { |
| 2586 | struct event_probe_data *data = _data; |
| 2587 | |
| 2588 | seq_printf(m, "%ps:", (void *)ip); |
| 2589 | |
| 2590 | seq_printf(m, "%s:%s:%s", |
| 2591 | data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR, |
| 2592 | data->file->event_call->class->system, |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2593 | trace_event_name(data->file->event_call)); |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2594 | |
| 2595 | if (data->count == -1) |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2596 | seq_puts(m, ":unlimited\n"); |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2597 | else |
| 2598 | seq_printf(m, ":count=%ld\n", data->count); |
| 2599 | |
| 2600 | return 0; |
| 2601 | } |
| 2602 | |
| 2603 | static int |
| 2604 | event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip, |
| 2605 | void **_data) |
| 2606 | { |
| 2607 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 2608 | struct event_probe_data *data = *pdata; |
| 2609 | |
| 2610 | data->ref++; |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
| 2614 | static void |
| 2615 | event_enable_free(struct ftrace_probe_ops *ops, unsigned long ip, |
| 2616 | void **_data) |
| 2617 | { |
| 2618 | struct event_probe_data **pdata = (struct event_probe_data **)_data; |
| 2619 | struct event_probe_data *data = *pdata; |
| 2620 | |
| 2621 | if (WARN_ON_ONCE(data->ref <= 0)) |
| 2622 | return; |
| 2623 | |
| 2624 | data->ref--; |
| 2625 | if (!data->ref) { |
| 2626 | /* Remove the SOFT_MODE flag */ |
| 2627 | __ftrace_event_enable_disable(data->file, 0, 1); |
| 2628 | module_put(data->file->event_call->mod); |
| 2629 | kfree(data); |
| 2630 | } |
| 2631 | *pdata = NULL; |
| 2632 | } |
| 2633 | |
| 2634 | static struct ftrace_probe_ops event_enable_probe_ops = { |
| 2635 | .func = event_enable_probe, |
| 2636 | .print = event_enable_print, |
| 2637 | .init = event_enable_init, |
| 2638 | .free = event_enable_free, |
| 2639 | }; |
| 2640 | |
| 2641 | static struct ftrace_probe_ops event_enable_count_probe_ops = { |
| 2642 | .func = event_enable_count_probe, |
| 2643 | .print = event_enable_print, |
| 2644 | .init = event_enable_init, |
| 2645 | .free = event_enable_free, |
| 2646 | }; |
| 2647 | |
| 2648 | static struct ftrace_probe_ops event_disable_probe_ops = { |
| 2649 | .func = event_enable_probe, |
| 2650 | .print = event_enable_print, |
| 2651 | .init = event_enable_init, |
| 2652 | .free = event_enable_free, |
| 2653 | }; |
| 2654 | |
| 2655 | static struct ftrace_probe_ops event_disable_count_probe_ops = { |
| 2656 | .func = event_enable_count_probe, |
| 2657 | .print = event_enable_print, |
| 2658 | .init = event_enable_init, |
| 2659 | .free = event_enable_free, |
| 2660 | }; |
| 2661 | |
| 2662 | static int |
| 2663 | event_enable_func(struct ftrace_hash *hash, |
| 2664 | char *glob, char *cmd, char *param, int enabled) |
| 2665 | { |
| 2666 | struct trace_array *tr = top_trace_array(); |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2667 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2668 | struct ftrace_probe_ops *ops; |
| 2669 | struct event_probe_data *data; |
| 2670 | const char *system; |
| 2671 | const char *event; |
| 2672 | char *number; |
| 2673 | bool enable; |
| 2674 | int ret; |
| 2675 | |
Yoshihiro YUNOMAE | dc81e5e | 2014-06-06 07:35:17 +0900 | [diff] [blame] | 2676 | if (!tr) |
| 2677 | return -ENODEV; |
| 2678 | |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2679 | /* hash funcs only work with set_ftrace_filter */ |
Harsh Prateek Bora | 8092e80 | 2013-05-24 12:52:17 +0530 | [diff] [blame] | 2680 | if (!enabled || !param) |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2681 | return -EINVAL; |
| 2682 | |
| 2683 | system = strsep(¶m, ":"); |
| 2684 | if (!param) |
| 2685 | return -EINVAL; |
| 2686 | |
| 2687 | event = strsep(¶m, ":"); |
| 2688 | |
| 2689 | mutex_lock(&event_mutex); |
| 2690 | |
| 2691 | ret = -EINVAL; |
| 2692 | file = find_event_file(tr, system, event); |
| 2693 | if (!file) |
| 2694 | goto out; |
| 2695 | |
| 2696 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; |
| 2697 | |
| 2698 | if (enable) |
| 2699 | ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops; |
| 2700 | else |
| 2701 | ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops; |
| 2702 | |
| 2703 | if (glob[0] == '!') { |
| 2704 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 2705 | ret = 0; |
| 2706 | goto out; |
| 2707 | } |
| 2708 | |
| 2709 | ret = -ENOMEM; |
| 2710 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2711 | if (!data) |
| 2712 | goto out; |
| 2713 | |
| 2714 | data->enable = enable; |
| 2715 | data->count = -1; |
| 2716 | data->file = file; |
| 2717 | |
| 2718 | if (!param) |
| 2719 | goto out_reg; |
| 2720 | |
| 2721 | number = strsep(¶m, ":"); |
| 2722 | |
| 2723 | ret = -EINVAL; |
| 2724 | if (!strlen(number)) |
| 2725 | goto out_free; |
| 2726 | |
| 2727 | /* |
| 2728 | * We use the callback data field (which is a pointer) |
| 2729 | * as our counter. |
| 2730 | */ |
| 2731 | ret = kstrtoul(number, 0, &data->count); |
| 2732 | if (ret) |
| 2733 | goto out_free; |
| 2734 | |
| 2735 | out_reg: |
| 2736 | /* Don't let event modules unload while probe registered */ |
| 2737 | ret = try_module_get(file->event_call->mod); |
Masami Hiramatsu | 6ed0106 | 2013-05-16 20:48:49 +0900 | [diff] [blame] | 2738 | if (!ret) { |
| 2739 | ret = -EBUSY; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2740 | goto out_free; |
Masami Hiramatsu | 6ed0106 | 2013-05-16 20:48:49 +0900 | [diff] [blame] | 2741 | } |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2742 | |
| 2743 | ret = __ftrace_event_enable_disable(file, 1, 1); |
| 2744 | if (ret < 0) |
| 2745 | goto out_put; |
| 2746 | ret = register_ftrace_function_probe(glob, ops, data); |
Steven Rostedt (Red Hat) | ff305de | 2013-05-09 11:30:26 -0400 | [diff] [blame] | 2747 | /* |
| 2748 | * The above returns on success the # of functions enabled, |
| 2749 | * but if it didn't find any functions it returns zero. |
| 2750 | * Consider no functions a failure too. |
| 2751 | */ |
Masami Hiramatsu | a5b85bd | 2013-05-09 14:44:14 +0900 | [diff] [blame] | 2752 | if (!ret) { |
| 2753 | ret = -ENOENT; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2754 | goto out_disable; |
Steven Rostedt (Red Hat) | ff305de | 2013-05-09 11:30:26 -0400 | [diff] [blame] | 2755 | } else if (ret < 0) |
| 2756 | goto out_disable; |
| 2757 | /* Just return zero, not the number of enabled functions */ |
| 2758 | ret = 0; |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 2759 | out: |
| 2760 | mutex_unlock(&event_mutex); |
| 2761 | return ret; |
| 2762 | |
| 2763 | out_disable: |
| 2764 | __ftrace_event_enable_disable(file, 0, 1); |
| 2765 | out_put: |
| 2766 | module_put(file->event_call->mod); |
| 2767 | out_free: |
| 2768 | kfree(data); |
| 2769 | goto out; |
| 2770 | } |
| 2771 | |
| 2772 | static struct ftrace_func_command event_enable_cmd = { |
| 2773 | .name = ENABLE_EVENT_STR, |
| 2774 | .func = event_enable_func, |
| 2775 | }; |
| 2776 | |
| 2777 | static struct ftrace_func_command event_disable_cmd = { |
| 2778 | .name = DISABLE_EVENT_STR, |
| 2779 | .func = event_enable_func, |
| 2780 | }; |
| 2781 | |
| 2782 | static __init int register_event_cmds(void) |
| 2783 | { |
| 2784 | int ret; |
| 2785 | |
| 2786 | ret = register_ftrace_command(&event_enable_cmd); |
| 2787 | if (WARN_ON(ret < 0)) |
| 2788 | return ret; |
| 2789 | ret = register_ftrace_command(&event_disable_cmd); |
| 2790 | if (WARN_ON(ret < 0)) |
| 2791 | unregister_ftrace_command(&event_enable_cmd); |
| 2792 | return ret; |
| 2793 | } |
| 2794 | #else |
| 2795 | static inline int register_event_cmds(void) { return 0; } |
| 2796 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 2797 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2798 | /* |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2799 | * The top level array has already had its trace_event_file |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2800 | * descriptors created in order to allow for early events to |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2801 | * be recorded. This function is called after the tracefs has been |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2802 | * initialized, and we now have to create the files associated |
| 2803 | * to the events. |
| 2804 | */ |
| 2805 | static __init void |
| 2806 | __trace_early_add_event_dirs(struct trace_array *tr) |
| 2807 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2808 | struct trace_event_file *file; |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2809 | int ret; |
| 2810 | |
| 2811 | |
| 2812 | list_for_each_entry(file, &tr->events, list) { |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2813 | ret = event_create_dir(tr->event_dir, file); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2814 | if (ret < 0) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 2815 | pr_warn("Could not create directory for event %s\n", |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2816 | trace_event_name(file->event_call)); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | /* |
| 2821 | * For early boot up, the top trace array requires to have |
| 2822 | * a list of events that can be enabled. This must be done before |
| 2823 | * the filesystem is set up in order to allow events to be traced |
| 2824 | * early. |
| 2825 | */ |
| 2826 | static __init void |
| 2827 | __trace_early_add_events(struct trace_array *tr) |
| 2828 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2829 | struct trace_event_call *call; |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2830 | int ret; |
| 2831 | |
| 2832 | list_for_each_entry(call, &ftrace_events, list) { |
| 2833 | /* Early boot up should not have any modules loaded */ |
| 2834 | if (WARN_ON_ONCE(call->mod)) |
| 2835 | continue; |
| 2836 | |
| 2837 | ret = __trace_early_add_new_event(call, tr); |
| 2838 | if (ret < 0) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 2839 | pr_warn("Could not create early event %s\n", |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 2840 | trace_event_name(call)); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2844 | /* Remove the event directory structure for a trace directory. */ |
| 2845 | static void |
| 2846 | __trace_remove_event_dirs(struct trace_array *tr) |
| 2847 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 2848 | struct trace_event_file *file, *next; |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2849 | |
Oleg Nesterov | f6a84bd | 2013-07-26 19:25:47 +0200 | [diff] [blame] | 2850 | list_for_each_entry_safe(file, next, &tr->events, list) |
| 2851 | remove_event_file_dir(file); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2854 | static void __add_event_to_tracers(struct trace_event_call *call) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2855 | { |
| 2856 | struct trace_array *tr; |
| 2857 | |
Oleg Nesterov | 620a30e | 2013-07-31 19:31:35 +0200 | [diff] [blame] | 2858 | list_for_each_entry(tr, &ftrace_trace_arrays, list) |
| 2859 | __trace_add_new_event(call, tr); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2860 | } |
| 2861 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2862 | extern struct trace_event_call *__start_ftrace_events[]; |
| 2863 | extern struct trace_event_call *__stop_ftrace_events[]; |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 2864 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 2865 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
| 2866 | |
| 2867 | static __init int setup_trace_event(char *str) |
| 2868 | { |
| 2869 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 2870 | ring_buffer_expanded = true; |
| 2871 | tracing_selftest_disabled = true; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 2872 | |
| 2873 | return 1; |
| 2874 | } |
| 2875 | __setup("trace_event=", setup_trace_event); |
| 2876 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2877 | /* Expects to have event_mutex held when called */ |
| 2878 | static int |
| 2879 | create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2880 | { |
| 2881 | struct dentry *d_events; |
| 2882 | struct dentry *entry; |
| 2883 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2884 | entry = tracefs_create_file("set_event", 0644, parent, |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2885 | tr, &ftrace_set_event_fops); |
| 2886 | if (!entry) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2887 | pr_warn("Could not create tracefs 'set_event' entry\n"); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2888 | return -ENOMEM; |
| 2889 | } |
| 2890 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2891 | d_events = tracefs_create_dir("events", parent); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2892 | if (!d_events) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2893 | pr_warn("Could not create tracefs 'events' directory\n"); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2894 | return -ENOMEM; |
| 2895 | } |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2896 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 2897 | entry = tracefs_create_file("set_event_pid", 0644, parent, |
| 2898 | tr, &ftrace_set_event_pid_fops); |
| 2899 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2900 | /* ring buffer internal formats */ |
| 2901 | trace_create_file("header_page", 0444, d_events, |
| 2902 | ring_buffer_print_page_header, |
| 2903 | &ftrace_show_header_fops); |
| 2904 | |
| 2905 | trace_create_file("header_event", 0444, d_events, |
| 2906 | ring_buffer_print_entry_header, |
| 2907 | &ftrace_show_header_fops); |
| 2908 | |
| 2909 | trace_create_file("enable", 0644, d_events, |
| 2910 | tr, &ftrace_tr_enable_fops); |
| 2911 | |
| 2912 | tr->event_dir = d_events; |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2913 | |
| 2914 | return 0; |
| 2915 | } |
| 2916 | |
| 2917 | /** |
| 2918 | * event_trace_add_tracer - add a instance of a trace_array to events |
| 2919 | * @parent: The parent dentry to place the files/directories for events in |
| 2920 | * @tr: The trace array associated with these events |
| 2921 | * |
| 2922 | * When a new instance is created, it needs to set up its events |
| 2923 | * directory, as well as other files associated with events. It also |
| 2924 | * creates the event hierachry in the @parent/events directory. |
| 2925 | * |
| 2926 | * Returns 0 on success. |
| 2927 | */ |
| 2928 | int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr) |
| 2929 | { |
| 2930 | int ret; |
| 2931 | |
| 2932 | mutex_lock(&event_mutex); |
| 2933 | |
| 2934 | ret = create_event_toplevel_files(parent, tr); |
| 2935 | if (ret) |
| 2936 | goto out_unlock; |
| 2937 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2938 | down_write(&trace_event_sem); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2939 | __trace_add_event_dirs(tr); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2940 | up_write(&trace_event_sem); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2941 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2942 | out_unlock: |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 2943 | mutex_unlock(&event_mutex); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2944 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2945 | return ret; |
| 2946 | } |
| 2947 | |
| 2948 | /* |
| 2949 | * The top trace array already had its file descriptors created. |
| 2950 | * Now the files themselves need to be created. |
| 2951 | */ |
| 2952 | static __init int |
| 2953 | early_event_add_tracer(struct dentry *parent, struct trace_array *tr) |
| 2954 | { |
| 2955 | int ret; |
| 2956 | |
| 2957 | mutex_lock(&event_mutex); |
| 2958 | |
| 2959 | ret = create_event_toplevel_files(parent, tr); |
| 2960 | if (ret) |
| 2961 | goto out_unlock; |
| 2962 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2963 | down_write(&trace_event_sem); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2964 | __trace_early_add_event_dirs(tr); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2965 | up_write(&trace_event_sem); |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 2966 | |
| 2967 | out_unlock: |
| 2968 | mutex_unlock(&event_mutex); |
| 2969 | |
| 2970 | return ret; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 2971 | } |
| 2972 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2973 | int event_trace_del_tracer(struct trace_array *tr) |
| 2974 | { |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2975 | mutex_lock(&event_mutex); |
| 2976 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 2977 | /* Disable any event triggers and associated soft-disabled events */ |
| 2978 | clear_event_triggers(tr); |
| 2979 | |
Steven Rostedt (Red Hat) | 4909010 | 2015-09-24 11:33:26 -0400 | [diff] [blame] | 2980 | /* Clear the pid list */ |
| 2981 | __ftrace_clear_event_pids(tr); |
| 2982 | |
Steven Rostedt (Red Hat) | 2a6c24a | 2013-07-02 14:48:23 -0400 | [diff] [blame] | 2983 | /* Disable any running events */ |
| 2984 | __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0); |
| 2985 | |
Steven Rostedt | 3ccb012 | 2013-12-03 12:41:20 -0500 | [diff] [blame] | 2986 | /* Access to events are within rcu_read_lock_sched() */ |
| 2987 | synchronize_sched(); |
| 2988 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2989 | down_write(&trace_event_sem); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2990 | __trace_remove_event_dirs(tr); |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 2991 | tracefs_remove_recursive(tr->event_dir); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 2992 | up_write(&trace_event_sem); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 2993 | |
| 2994 | tr->event_dir = NULL; |
| 2995 | |
| 2996 | mutex_unlock(&event_mutex); |
| 2997 | |
| 2998 | return 0; |
| 2999 | } |
| 3000 | |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 3001 | static __init int event_trace_memsetup(void) |
| 3002 | { |
| 3003 | field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC); |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 3004 | file_cachep = KMEM_CACHE(trace_event_file, SLAB_PANIC); |
Steven Rostedt | d1a2914 | 2013-02-27 20:23:57 -0500 | [diff] [blame] | 3005 | return 0; |
| 3006 | } |
| 3007 | |
Steven Rostedt (Red Hat) | ce1039b | 2015-01-14 12:53:45 -0500 | [diff] [blame] | 3008 | static __init void |
| 3009 | early_enable_events(struct trace_array *tr, bool disable_first) |
| 3010 | { |
| 3011 | char *buf = bootup_event_buf; |
| 3012 | char *token; |
| 3013 | int ret; |
| 3014 | |
| 3015 | while (true) { |
| 3016 | token = strsep(&buf, ","); |
| 3017 | |
| 3018 | if (!token) |
| 3019 | break; |
| 3020 | if (!*token) |
| 3021 | continue; |
| 3022 | |
| 3023 | /* Restarting syscalls requires that we stop them first */ |
| 3024 | if (disable_first) |
| 3025 | ftrace_set_clr_event(tr, token, 0); |
| 3026 | |
| 3027 | ret = ftrace_set_clr_event(tr, token, 1); |
| 3028 | if (ret) |
| 3029 | pr_warn("Failed to enable trace event: %s\n", token); |
| 3030 | |
| 3031 | /* Put back the comma to allow this to be called again */ |
| 3032 | if (buf) |
| 3033 | *(buf - 1) = ','; |
| 3034 | } |
| 3035 | } |
| 3036 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 3037 | static __init int event_trace_enable(void) |
| 3038 | { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3039 | struct trace_array *tr = top_trace_array(); |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 3040 | struct trace_event_call **iter, *call; |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 3041 | int ret; |
| 3042 | |
Yoshihiro YUNOMAE | dc81e5e | 2014-06-06 07:35:17 +0900 | [diff] [blame] | 3043 | if (!tr) |
| 3044 | return -ENODEV; |
| 3045 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 3046 | for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) { |
| 3047 | |
| 3048 | call = *iter; |
| 3049 | ret = event_init(call); |
| 3050 | if (!ret) |
| 3051 | list_add(&call->list, &ftrace_events); |
| 3052 | } |
| 3053 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 3054 | /* |
| 3055 | * We need the top trace array to have a working set of trace |
| 3056 | * points at early init, before the debug files and directories |
| 3057 | * are created. Create the file entries now, and attach them |
| 3058 | * to the actual file dentries later. |
| 3059 | */ |
| 3060 | __trace_early_add_events(tr); |
| 3061 | |
Steven Rostedt (Red Hat) | ce1039b | 2015-01-14 12:53:45 -0500 | [diff] [blame] | 3062 | early_enable_events(tr, false); |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3063 | |
| 3064 | trace_printk_start_comm(); |
| 3065 | |
Steven Rostedt (Red Hat) | 3cd715d | 2013-03-12 19:35:13 -0400 | [diff] [blame] | 3066 | register_event_cmds(); |
| 3067 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 3068 | register_trigger_cmds(); |
| 3069 | |
Ezequiel Garcia | 8781915 | 2012-09-12 11:47:57 -0300 | [diff] [blame] | 3070 | return 0; |
| 3071 | } |
| 3072 | |
Steven Rostedt (Red Hat) | ce1039b | 2015-01-14 12:53:45 -0500 | [diff] [blame] | 3073 | /* |
| 3074 | * event_trace_enable() is called from trace_event_init() first to |
| 3075 | * initialize events and perhaps start any events that are on the |
| 3076 | * command line. Unfortunately, there are some events that will not |
| 3077 | * start this early, like the system call tracepoints that need |
| 3078 | * to set the TIF_SYSCALL_TRACEPOINT flag of pid 1. But event_trace_enable() |
| 3079 | * is called before pid 1 starts, and this flag is never set, making |
| 3080 | * the syscall tracepoint never get reached, but the event is enabled |
| 3081 | * regardless (and not doing anything). |
| 3082 | */ |
| 3083 | static __init int event_trace_enable_again(void) |
| 3084 | { |
| 3085 | struct trace_array *tr; |
| 3086 | |
| 3087 | tr = top_trace_array(); |
| 3088 | if (!tr) |
| 3089 | return -ENODEV; |
| 3090 | |
| 3091 | early_enable_events(tr, true); |
| 3092 | |
| 3093 | return 0; |
| 3094 | } |
| 3095 | |
| 3096 | early_initcall(event_trace_enable_again); |
| 3097 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3098 | static __init int event_trace_init(void) |
| 3099 | { |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3100 | struct trace_array *tr; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3101 | struct dentry *d_tracer; |
| 3102 | struct dentry *entry; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 3103 | int ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3104 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3105 | tr = top_trace_array(); |
Yoshihiro YUNOMAE | dc81e5e | 2014-06-06 07:35:17 +0900 | [diff] [blame] | 3106 | if (!tr) |
| 3107 | return -ENODEV; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3108 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3109 | d_tracer = tracing_init_dentry(); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 3110 | if (IS_ERR(d_tracer)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3111 | return 0; |
| 3112 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 3113 | entry = tracefs_create_file("available_events", 0444, d_tracer, |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3114 | tr, &ftrace_avail_fops); |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 3115 | if (!entry) |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 3116 | pr_warn("Could not create tracefs 'available_events' entry\n"); |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 3117 | |
Daniel Wagner | 9f61668 | 2015-08-10 14:35:46 +0200 | [diff] [blame] | 3118 | if (trace_define_generic_fields()) |
| 3119 | pr_warn("tracing: Failed to allocated generic fields"); |
| 3120 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 3121 | if (trace_define_common_fields()) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3122 | pr_warn("tracing: Failed to allocate common fields"); |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 3123 | |
Steven Rostedt | 7724822 | 2013-02-27 16:28:06 -0500 | [diff] [blame] | 3124 | ret = early_event_add_tracer(d_tracer, tr); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3125 | if (ret) |
| 3126 | return ret; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 3127 | |
Oleg Nesterov | 836d481 | 2013-07-31 19:31:37 +0200 | [diff] [blame] | 3128 | #ifdef CONFIG_MODULES |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 3129 | ret = register_module_notifier(&trace_module_nb); |
Ming Lei | 5537937 | 2009-05-18 23:04:46 +0800 | [diff] [blame] | 3130 | if (ret) |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3131 | pr_warn("Failed to register trace events module notifier\n"); |
Oleg Nesterov | 836d481 | 2013-07-31 19:31:37 +0200 | [diff] [blame] | 3132 | #endif |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3133 | return 0; |
| 3134 | } |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 3135 | |
| 3136 | void __init trace_event_init(void) |
| 3137 | { |
| 3138 | event_trace_memsetup(); |
| 3139 | init_ftrace_syscalls(); |
| 3140 | event_trace_enable(); |
| 3141 | } |
| 3142 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 3143 | fs_initcall(event_trace_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3144 | |
| 3145 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 3146 | |
| 3147 | static DEFINE_SPINLOCK(test_spinlock); |
| 3148 | static DEFINE_SPINLOCK(test_spinlock_irq); |
| 3149 | static DEFINE_MUTEX(test_mutex); |
| 3150 | |
| 3151 | static __init void test_work(struct work_struct *dummy) |
| 3152 | { |
| 3153 | spin_lock(&test_spinlock); |
| 3154 | spin_lock_irq(&test_spinlock_irq); |
| 3155 | udelay(1); |
| 3156 | spin_unlock_irq(&test_spinlock_irq); |
| 3157 | spin_unlock(&test_spinlock); |
| 3158 | |
| 3159 | mutex_lock(&test_mutex); |
| 3160 | msleep(1); |
| 3161 | mutex_unlock(&test_mutex); |
| 3162 | } |
| 3163 | |
| 3164 | static __init int event_test_thread(void *unused) |
| 3165 | { |
| 3166 | void *test_malloc; |
| 3167 | |
| 3168 | test_malloc = kmalloc(1234, GFP_KERNEL); |
| 3169 | if (!test_malloc) |
| 3170 | pr_info("failed to kmalloc\n"); |
| 3171 | |
| 3172 | schedule_on_each_cpu(test_work); |
| 3173 | |
| 3174 | kfree(test_malloc); |
| 3175 | |
| 3176 | set_current_state(TASK_INTERRUPTIBLE); |
Peter Zijlstra | fe0e01c | 2014-10-08 18:51:10 +0200 | [diff] [blame] | 3177 | while (!kthread_should_stop()) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3178 | schedule(); |
Peter Zijlstra | fe0e01c | 2014-10-08 18:51:10 +0200 | [diff] [blame] | 3179 | set_current_state(TASK_INTERRUPTIBLE); |
| 3180 | } |
| 3181 | __set_current_state(TASK_RUNNING); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3182 | |
| 3183 | return 0; |
| 3184 | } |
| 3185 | |
| 3186 | /* |
| 3187 | * Do various things that may trigger events. |
| 3188 | */ |
| 3189 | static __init void event_test_stuff(void) |
| 3190 | { |
| 3191 | struct task_struct *test_thread; |
| 3192 | |
| 3193 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); |
| 3194 | msleep(1); |
| 3195 | kthread_stop(test_thread); |
| 3196 | } |
| 3197 | |
| 3198 | /* |
| 3199 | * For every trace event defined, we will test each trace point separately, |
| 3200 | * and then by groups, and finally all trace points. |
| 3201 | */ |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3202 | static __init void event_trace_self_tests(void) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3203 | { |
Steven Rostedt (Red Hat) | 7967b3e | 2015-05-13 14:59:40 -0400 | [diff] [blame] | 3204 | struct trace_subsystem_dir *dir; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 3205 | struct trace_event_file *file; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 3206 | struct trace_event_call *call; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3207 | struct event_subsystem *system; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3208 | struct trace_array *tr; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3209 | int ret; |
| 3210 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3211 | tr = top_trace_array(); |
Yoshihiro YUNOMAE | dc81e5e | 2014-06-06 07:35:17 +0900 | [diff] [blame] | 3212 | if (!tr) |
| 3213 | return; |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3214 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3215 | pr_info("Running tests on trace events:\n"); |
| 3216 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3217 | list_for_each_entry(file, &tr->events, list) { |
| 3218 | |
| 3219 | call = file->event_call; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3220 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 3221 | /* Only test those that have a probe */ |
| 3222 | if (!call->class || !call->class->probe) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3223 | continue; |
| 3224 | |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 3225 | /* |
| 3226 | * Testing syscall events here is pretty useless, but |
| 3227 | * we still do it if configured. But this is time consuming. |
| 3228 | * What we really need is a user thread to perform the |
| 3229 | * syscalls as we test. |
| 3230 | */ |
| 3231 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 3232 | if (call->class->system && |
| 3233 | strcmp(call->class->system, "syscalls") == 0) |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 3234 | continue; |
| 3235 | #endif |
| 3236 | |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 3237 | pr_info("Testing event %s: ", trace_event_name(call)); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3238 | |
| 3239 | /* |
| 3240 | * If an event is already enabled, someone is using |
| 3241 | * it and the self test should not be on. |
| 3242 | */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 3243 | if (file->flags & EVENT_FILE_FL_ENABLED) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3244 | pr_warn("Enabled event during self test!\n"); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3245 | WARN_ON_ONCE(1); |
| 3246 | continue; |
| 3247 | } |
| 3248 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3249 | ftrace_event_enable_disable(file, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3250 | event_test_stuff(); |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3251 | ftrace_event_enable_disable(file, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3252 | |
| 3253 | pr_cont("OK\n"); |
| 3254 | } |
| 3255 | |
| 3256 | /* Now test at the sub system level */ |
| 3257 | |
| 3258 | pr_info("Running tests on trace event systems:\n"); |
| 3259 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3260 | list_for_each_entry(dir, &tr->systems, list) { |
| 3261 | |
| 3262 | system = dir->subsystem; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3263 | |
| 3264 | /* the ftrace system is special, skip it */ |
| 3265 | if (strcmp(system->name, "ftrace") == 0) |
| 3266 | continue; |
| 3267 | |
| 3268 | pr_info("Testing event system %s: ", system->name); |
| 3269 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3270 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3271 | if (WARN_ON_ONCE(ret)) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3272 | pr_warn("error enabling system %s\n", |
| 3273 | system->name); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3274 | continue; |
| 3275 | } |
| 3276 | |
| 3277 | event_test_stuff(); |
| 3278 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3279 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0); |
Yuanhan Liu | 76bab1b | 2012-08-27 15:13:45 +0800 | [diff] [blame] | 3280 | if (WARN_ON_ONCE(ret)) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3281 | pr_warn("error disabling system %s\n", |
| 3282 | system->name); |
Yuanhan Liu | 76bab1b | 2012-08-27 15:13:45 +0800 | [diff] [blame] | 3283 | continue; |
| 3284 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3285 | |
| 3286 | pr_cont("OK\n"); |
| 3287 | } |
| 3288 | |
| 3289 | /* Test with all events enabled */ |
| 3290 | |
| 3291 | pr_info("Running tests on all trace events:\n"); |
| 3292 | pr_info("Testing all events: "); |
| 3293 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3294 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3295 | if (WARN_ON_ONCE(ret)) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3296 | pr_warn("error enabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3297 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | event_test_stuff(); |
| 3301 | |
| 3302 | /* reset sysname */ |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 3303 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3304 | if (WARN_ON_ONCE(ret)) { |
Fabian Frederick | 3448bac | 2014-06-07 13:43:08 +0200 | [diff] [blame] | 3305 | pr_warn("error disabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3306 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | pr_cont("OK\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | #ifdef CONFIG_FUNCTION_TRACER |
| 3313 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 3314 | static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3315 | |
Steven Rostedt (Red Hat) | b7f0c95 | 2015-09-25 17:38:44 -0400 | [diff] [blame] | 3316 | static struct trace_array *event_tr; |
| 3317 | |
| 3318 | static void __init |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 3319 | function_test_events_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame] | 3320 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3321 | { |
| 3322 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 3323 | struct ring_buffer *buffer; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3324 | struct ftrace_entry *entry; |
| 3325 | unsigned long flags; |
| 3326 | long disabled; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3327 | int cpu; |
| 3328 | int pc; |
| 3329 | |
| 3330 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 3331 | preempt_disable_notrace(); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3332 | cpu = raw_smp_processor_id(); |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 3333 | disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3334 | |
| 3335 | if (disabled != 1) |
| 3336 | goto out; |
| 3337 | |
| 3338 | local_save_flags(flags); |
| 3339 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 3340 | event = trace_current_buffer_lock_reserve(&buffer, |
| 3341 | TRACE_FN, sizeof(*entry), |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3342 | flags, pc); |
| 3343 | if (!event) |
| 3344 | goto out; |
| 3345 | entry = ring_buffer_event_data(event); |
| 3346 | entry->ip = ip; |
| 3347 | entry->parent_ip = parent_ip; |
| 3348 | |
Steven Rostedt (Red Hat) | b7f0c95 | 2015-09-25 17:38:44 -0400 | [diff] [blame] | 3349 | trace_buffer_unlock_commit(event_tr, buffer, event, flags, pc); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3350 | |
| 3351 | out: |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 3352 | atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 3353 | preempt_enable_notrace(); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | static struct ftrace_ops trace_ops __initdata = |
| 3357 | { |
| 3358 | .func = function_test_events_call, |
Steven Rostedt | 4740974 | 2012-07-20 11:04:44 -0400 | [diff] [blame] | 3359 | .flags = FTRACE_OPS_FL_RECURSION_SAFE, |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3360 | }; |
| 3361 | |
| 3362 | static __init void event_trace_self_test_with_function(void) |
| 3363 | { |
Steven Rostedt | 17bb615 | 2011-05-23 15:27:46 -0400 | [diff] [blame] | 3364 | int ret; |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 3365 | event_tr = top_trace_array(); |
| 3366 | if (WARN_ON(!event_tr)) |
| 3367 | return; |
Steven Rostedt | 17bb615 | 2011-05-23 15:27:46 -0400 | [diff] [blame] | 3368 | ret = register_ftrace_function(&trace_ops); |
| 3369 | if (WARN_ON(ret < 0)) { |
| 3370 | pr_info("Failed to enable function tracer for event tests\n"); |
| 3371 | return; |
| 3372 | } |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 3373 | pr_info("Running tests again, along with the function tracer\n"); |
| 3374 | event_trace_self_tests(); |
| 3375 | unregister_ftrace_function(&trace_ops); |
| 3376 | } |
| 3377 | #else |
| 3378 | static __init void event_trace_self_test_with_function(void) |
| 3379 | { |
| 3380 | } |
| 3381 | #endif |
| 3382 | |
| 3383 | static __init int event_trace_self_tests_init(void) |
| 3384 | { |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 3385 | if (!tracing_selftest_disabled) { |
| 3386 | event_trace_self_tests(); |
| 3387 | event_trace_self_test_with_function(); |
| 3388 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3389 | |
| 3390 | return 0; |
| 3391 | } |
| 3392 | |
Steven Rostedt | 28d20e2 | 2009-04-20 12:12:44 -0400 | [diff] [blame] | 3393 | late_initcall(event_trace_self_tests_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 3394 | |
| 3395 | #endif |