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