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