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