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