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 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 11 | #include <linux/workqueue.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/kthread.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/uaccess.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 19 | #include <linux/delay.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 20 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 21 | #include <asm/setup.h> |
| 22 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 23 | #include "trace_output.h" |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 24 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 25 | #undef TRACE_SYSTEM |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 26 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| 27 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 28 | DEFINE_MUTEX(event_mutex); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 29 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 30 | LIST_HEAD(ftrace_events); |
| 31 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 32 | struct list_head * |
| 33 | trace_get_fields(struct ftrace_event_call *event_call) |
| 34 | { |
| 35 | if (!event_call->class->get_fields) |
| 36 | return &event_call->class->fields; |
| 37 | return event_call->class->get_fields(event_call); |
| 38 | } |
| 39 | |
Frederic Weisbecker | aeaeae1 | 2009-08-27 05:09:51 +0200 | [diff] [blame] | 40 | int trace_define_field(struct ftrace_event_call *call, const char *type, |
| 41 | const char *name, int offset, int size, int is_signed, |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 42 | int filter_type) |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 43 | { |
| 44 | struct ftrace_event_field *field; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 45 | struct list_head *head; |
| 46 | |
| 47 | if (WARN_ON(!call->class)) |
| 48 | return 0; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 49 | |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 50 | field = kzalloc(sizeof(*field), GFP_KERNEL); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 51 | if (!field) |
| 52 | goto err; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 53 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 54 | field->name = kstrdup(name, GFP_KERNEL); |
| 55 | if (!field->name) |
| 56 | goto err; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 57 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 58 | field->type = kstrdup(type, GFP_KERNEL); |
| 59 | if (!field->type) |
| 60 | goto err; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 61 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 62 | if (filter_type == FILTER_OTHER) |
| 63 | field->filter_type = filter_assign_type(type); |
| 64 | else |
| 65 | field->filter_type = filter_type; |
| 66 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 67 | field->offset = offset; |
| 68 | field->size = size; |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 69 | field->is_signed = is_signed; |
Li Zefan | aa38e9f | 2009-08-07 10:33:02 +0800 | [diff] [blame] | 70 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 71 | head = trace_get_fields(call); |
| 72 | list_add(&field->link, head); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 73 | |
| 74 | return 0; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 75 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 76 | err: |
Wenji Huang | 7b60997f | 2010-02-24 15:40:26 +0800 | [diff] [blame] | 77 | if (field) |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 78 | kfree(field->name); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 79 | kfree(field); |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 80 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 81 | return -ENOMEM; |
| 82 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(trace_define_field); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 84 | |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 85 | #define __common_field(type, item) \ |
| 86 | ret = trace_define_field(call, #type, "common_" #item, \ |
| 87 | offsetof(typeof(ent), item), \ |
| 88 | sizeof(ent.item), \ |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 89 | is_signed_type(type), FILTER_OTHER); \ |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 90 | if (ret) \ |
| 91 | return ret; |
| 92 | |
Li Zefan | 614a71a | 2009-12-08 11:14:36 +0800 | [diff] [blame] | 93 | static int trace_define_common_fields(struct ftrace_event_call *call) |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 94 | { |
| 95 | int ret; |
| 96 | struct trace_entry ent; |
| 97 | |
| 98 | __common_field(unsigned short, type); |
| 99 | __common_field(unsigned char, flags); |
| 100 | __common_field(unsigned char, preempt_count); |
| 101 | __common_field(int, pid); |
Steven Rostedt | 637e7e8 | 2009-09-11 13:55:35 -0400 | [diff] [blame] | 102 | __common_field(int, lock_depth); |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 107 | void trace_destroy_fields(struct ftrace_event_call *call) |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 108 | { |
| 109 | struct ftrace_event_field *field, *next; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 110 | struct list_head *head; |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 111 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 112 | head = trace_get_fields(call); |
| 113 | list_for_each_entry_safe(field, next, head, link) { |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 114 | list_del(&field->link); |
| 115 | kfree(field->type); |
| 116 | kfree(field->name); |
| 117 | kfree(field); |
| 118 | } |
| 119 | } |
| 120 | |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 121 | int trace_event_raw_init(struct ftrace_event_call *call) |
| 122 | { |
| 123 | int id; |
| 124 | |
| 125 | id = register_ftrace_event(call->event); |
| 126 | if (!id) |
| 127 | return -ENODEV; |
| 128 | call->id = id; |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | EXPORT_SYMBOL_GPL(trace_event_raw_init); |
| 133 | |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 134 | static int ftrace_event_enable_disable(struct ftrace_event_call *call, |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 135 | int enable) |
| 136 | { |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 137 | int ret = 0; |
| 138 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 139 | switch (enable) { |
| 140 | case 0: |
| 141 | if (call->enabled) { |
| 142 | call->enabled = 0; |
Zhaolei | b11c53e | 2009-05-25 18:11:59 +0800 | [diff] [blame] | 143 | tracing_stop_cmdline_record(); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 144 | if (call->class->reg) |
| 145 | call->class->reg(call, TRACE_REG_UNREGISTER); |
| 146 | else |
| 147 | tracepoint_probe_unregister(call->name, |
| 148 | call->class->probe, |
| 149 | call); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 150 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 151 | break; |
| 152 | case 1: |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 153 | if (!call->enabled) { |
Zhaolei | b11c53e | 2009-05-25 18:11:59 +0800 | [diff] [blame] | 154 | tracing_start_cmdline_record(); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 155 | if (call->class->reg) |
| 156 | ret = call->class->reg(call, TRACE_REG_REGISTER); |
| 157 | else |
| 158 | ret = tracepoint_probe_register(call->name, |
| 159 | call->class->probe, |
| 160 | call); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 161 | if (ret) { |
| 162 | tracing_stop_cmdline_record(); |
| 163 | pr_info("event trace: Could not enable event " |
| 164 | "%s\n", call->name); |
| 165 | break; |
| 166 | } |
| 167 | call->enabled = 1; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 168 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 169 | break; |
| 170 | } |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 171 | |
| 172 | return ret; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 175 | static void ftrace_clear_events(void) |
| 176 | { |
| 177 | struct ftrace_event_call *call; |
| 178 | |
| 179 | mutex_lock(&event_mutex); |
| 180 | list_for_each_entry(call, &ftrace_events, list) { |
| 181 | ftrace_event_enable_disable(call, 0); |
| 182 | } |
| 183 | mutex_unlock(&event_mutex); |
| 184 | } |
| 185 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 186 | /* |
| 187 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. |
| 188 | */ |
| 189 | static int __ftrace_set_clr_event(const char *match, const char *sub, |
| 190 | const char *event, int set) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 191 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 192 | struct ftrace_event_call *call; |
Steven Rostedt | 29f9394 | 2009-05-08 16:06:47 -0400 | [diff] [blame] | 193 | int ret = -EINVAL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 194 | |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 195 | mutex_lock(&event_mutex); |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 196 | list_for_each_entry(call, &ftrace_events, list) { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 197 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 198 | if (!call->name || !call->class || |
| 199 | (!call->class->probe && !call->class->reg)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 200 | continue; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 201 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 202 | if (match && |
| 203 | strcmp(match, call->name) != 0 && |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 204 | strcmp(match, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 205 | continue; |
| 206 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 207 | if (sub && strcmp(sub, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 208 | continue; |
| 209 | |
| 210 | if (event && strcmp(event, call->name) != 0) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 211 | continue; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 212 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 213 | ftrace_event_enable_disable(call, set); |
| 214 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 215 | ret = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 216 | } |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 217 | mutex_unlock(&event_mutex); |
| 218 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 219 | return ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 222 | static int ftrace_set_clr_event(char *buf, int set) |
| 223 | { |
| 224 | char *event = NULL, *sub = NULL, *match; |
| 225 | |
| 226 | /* |
| 227 | * The buf format can be <subsystem>:<event-name> |
| 228 | * *:<event-name> means any event by that name. |
| 229 | * :<event-name> is the same. |
| 230 | * |
| 231 | * <subsystem>:* means all events in that subsystem |
| 232 | * <subsystem>: means the same. |
| 233 | * |
| 234 | * <name> (no ':') means all events in a subsystem with |
| 235 | * the name <name> or any event that matches <name> |
| 236 | */ |
| 237 | |
| 238 | match = strsep(&buf, ":"); |
| 239 | if (buf) { |
| 240 | sub = match; |
| 241 | event = buf; |
| 242 | match = NULL; |
| 243 | |
| 244 | if (!strlen(sub) || strcmp(sub, "*") == 0) |
| 245 | sub = NULL; |
| 246 | if (!strlen(event) || strcmp(event, "*") == 0) |
| 247 | event = NULL; |
| 248 | } |
| 249 | |
| 250 | return __ftrace_set_clr_event(match, sub, event, set); |
| 251 | } |
| 252 | |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 253 | /** |
| 254 | * trace_set_clr_event - enable or disable an event |
| 255 | * @system: system name to match (NULL for any system) |
| 256 | * @event: event name to match (NULL for all events, within system) |
| 257 | * @set: 1 to enable, 0 to disable |
| 258 | * |
| 259 | * This is a way for other parts of the kernel to enable or disable |
| 260 | * event recording. |
| 261 | * |
| 262 | * Returns 0 on success, -EINVAL if the parameters do not match any |
| 263 | * registered events. |
| 264 | */ |
| 265 | int trace_set_clr_event(const char *system, const char *event, int set) |
| 266 | { |
| 267 | return __ftrace_set_clr_event(NULL, system, event, set); |
| 268 | } |
| 269 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 270 | /* 128 should be much more than enough */ |
| 271 | #define EVENT_BUF_SIZE 127 |
| 272 | |
| 273 | static ssize_t |
| 274 | ftrace_event_write(struct file *file, const char __user *ubuf, |
| 275 | size_t cnt, loff_t *ppos) |
| 276 | { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 277 | struct trace_parser parser; |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 278 | ssize_t read, ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 279 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 280 | if (!cnt) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 281 | return 0; |
| 282 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 283 | ret = tracing_update_buffers(); |
| 284 | if (ret < 0) |
| 285 | return ret; |
| 286 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 287 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 288 | return -ENOMEM; |
| 289 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 290 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 291 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 292 | if (read >= 0 && trace_parser_loaded((&parser))) { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 293 | int set = 1; |
| 294 | |
| 295 | if (*parser.buffer == '!') |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 296 | set = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 297 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 298 | parser.buffer[parser.idx] = 0; |
| 299 | |
| 300 | ret = ftrace_set_clr_event(parser.buffer + !set, set); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 301 | if (ret) |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 302 | goto out_put; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 303 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 304 | |
| 305 | ret = read; |
| 306 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 307 | out_put: |
| 308 | trace_parser_put(&parser); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 309 | |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | static void * |
| 314 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 315 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 316 | struct ftrace_event_call *call = v; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 317 | |
| 318 | (*pos)++; |
| 319 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 320 | list_for_each_entry_continue(call, &ftrace_events, list) { |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 321 | /* |
| 322 | * The ftrace subsystem is for showing formats only. |
| 323 | * They can not be enabled or disabled via the event files. |
| 324 | */ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 325 | if (call->class && (call->class->probe || call->class->reg)) |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 326 | return call; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 327 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 328 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 329 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 333 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 334 | struct ftrace_event_call *call; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 335 | loff_t l; |
| 336 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 337 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 338 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 339 | call = list_entry(&ftrace_events, struct ftrace_event_call, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 340 | for (l = 0; l <= *pos; ) { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 341 | call = t_next(m, call, &l); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 342 | if (!call) |
| 343 | break; |
| 344 | } |
| 345 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static void * |
| 349 | s_next(struct seq_file *m, void *v, loff_t *pos) |
| 350 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 351 | struct ftrace_event_call *call = v; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 352 | |
| 353 | (*pos)++; |
| 354 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 355 | list_for_each_entry_continue(call, &ftrace_events, list) { |
| 356 | if (call->enabled) |
| 357 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 358 | } |
| 359 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 360 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 364 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 365 | struct ftrace_event_call *call; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 366 | loff_t l; |
| 367 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 368 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 369 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 370 | call = list_entry(&ftrace_events, struct ftrace_event_call, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 371 | for (l = 0; l <= *pos; ) { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 372 | call = s_next(m, call, &l); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 373 | if (!call) |
| 374 | break; |
| 375 | } |
| 376 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static int t_show(struct seq_file *m, void *v) |
| 380 | { |
| 381 | struct ftrace_event_call *call = v; |
| 382 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 383 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
| 384 | seq_printf(m, "%s:", call->class->system); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 385 | seq_printf(m, "%s\n", call->name); |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static void t_stop(struct seq_file *m, void *p) |
| 391 | { |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 392 | mutex_unlock(&event_mutex); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static int |
| 396 | ftrace_event_seq_open(struct inode *inode, struct file *file) |
| 397 | { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 398 | const struct seq_operations *seq_ops; |
| 399 | |
| 400 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 401 | (file->f_flags & O_TRUNC)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 402 | ftrace_clear_events(); |
| 403 | |
| 404 | seq_ops = inode->i_private; |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 405 | return seq_open(file, seq_ops); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 406 | } |
| 407 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 408 | static ssize_t |
| 409 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 410 | loff_t *ppos) |
| 411 | { |
| 412 | struct ftrace_event_call *call = filp->private_data; |
| 413 | char *buf; |
| 414 | |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 415 | if (call->enabled) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 416 | buf = "1\n"; |
| 417 | else |
| 418 | buf = "0\n"; |
| 419 | |
| 420 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 421 | } |
| 422 | |
| 423 | static ssize_t |
| 424 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 425 | loff_t *ppos) |
| 426 | { |
| 427 | struct ftrace_event_call *call = filp->private_data; |
| 428 | char buf[64]; |
| 429 | unsigned long val; |
| 430 | int ret; |
| 431 | |
| 432 | if (cnt >= sizeof(buf)) |
| 433 | return -EINVAL; |
| 434 | |
| 435 | if (copy_from_user(&buf, ubuf, cnt)) |
| 436 | return -EFAULT; |
| 437 | |
| 438 | buf[cnt] = 0; |
| 439 | |
| 440 | ret = strict_strtoul(buf, 10, &val); |
| 441 | if (ret < 0) |
| 442 | return ret; |
| 443 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 444 | ret = tracing_update_buffers(); |
| 445 | if (ret < 0) |
| 446 | return ret; |
| 447 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 448 | switch (val) { |
| 449 | case 0: |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 450 | case 1: |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 451 | mutex_lock(&event_mutex); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 452 | ret = ftrace_event_enable_disable(call, val); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 453 | mutex_unlock(&event_mutex); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 454 | break; |
| 455 | |
| 456 | default: |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | |
| 460 | *ppos += cnt; |
| 461 | |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 462 | return ret ? ret : cnt; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 465 | static ssize_t |
| 466 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 467 | loff_t *ppos) |
| 468 | { |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 469 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 470 | const char *system = filp->private_data; |
| 471 | struct ftrace_event_call *call; |
| 472 | char buf[2]; |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 473 | int set = 0; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 474 | int ret; |
| 475 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 476 | mutex_lock(&event_mutex); |
| 477 | list_for_each_entry(call, &ftrace_events, list) { |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 478 | if (!call->name || !call->class || |
| 479 | (!call->class->probe && !call->class->reg)) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 480 | continue; |
| 481 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 482 | if (system && strcmp(call->class->system, system) != 0) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 483 | continue; |
| 484 | |
| 485 | /* |
| 486 | * We need to find out if all the events are set |
| 487 | * or if all events or cleared, or if we have |
| 488 | * a mixture. |
| 489 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 490 | set |= (1 << !!call->enabled); |
| 491 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 492 | /* |
| 493 | * If we have a mixture, no need to look further. |
| 494 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 495 | if (set == 3) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 496 | break; |
| 497 | } |
| 498 | mutex_unlock(&event_mutex); |
| 499 | |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 500 | buf[0] = set_to_char[set]; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 501 | buf[1] = '\n'; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 502 | |
| 503 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 504 | |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | static ssize_t |
| 509 | system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 510 | loff_t *ppos) |
| 511 | { |
| 512 | const char *system = filp->private_data; |
| 513 | unsigned long val; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 514 | char buf[64]; |
| 515 | ssize_t ret; |
| 516 | |
| 517 | if (cnt >= sizeof(buf)) |
| 518 | return -EINVAL; |
| 519 | |
| 520 | if (copy_from_user(&buf, ubuf, cnt)) |
| 521 | return -EFAULT; |
| 522 | |
| 523 | buf[cnt] = 0; |
| 524 | |
| 525 | ret = strict_strtoul(buf, 10, &val); |
| 526 | if (ret < 0) |
| 527 | return ret; |
| 528 | |
| 529 | ret = tracing_update_buffers(); |
| 530 | if (ret < 0) |
| 531 | return ret; |
| 532 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 533 | if (val != 0 && val != 1) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 534 | return -EINVAL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 535 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 536 | ret = __ftrace_set_clr_event(NULL, system, NULL, val); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 537 | if (ret) |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 538 | goto out; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 539 | |
| 540 | ret = cnt; |
| 541 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 542 | out: |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 543 | *ppos += cnt; |
| 544 | |
| 545 | return ret; |
| 546 | } |
| 547 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 548 | static ssize_t |
| 549 | event_format_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 550 | loff_t *ppos) |
| 551 | { |
| 552 | struct ftrace_event_call *call = filp->private_data; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 553 | struct ftrace_event_field *field; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 554 | struct list_head *head; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 555 | struct trace_seq *s; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 556 | int common_field_count = 5; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 557 | char *buf; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 558 | int r = 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 559 | |
Tom Zanussi | c269fc8 | 2009-03-17 01:20:59 -0500 | [diff] [blame] | 560 | if (*ppos) |
| 561 | return 0; |
| 562 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 563 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 564 | if (!s) |
| 565 | return -ENOMEM; |
| 566 | |
| 567 | trace_seq_init(s); |
| 568 | |
Steven Rostedt | c5e4e19 | 2009-03-02 15:10:02 -0500 | [diff] [blame] | 569 | trace_seq_printf(s, "name: %s\n", call->name); |
| 570 | trace_seq_printf(s, "ID: %d\n", call->id); |
| 571 | trace_seq_printf(s, "format:\n"); |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 572 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 573 | head = trace_get_fields(call); |
| 574 | list_for_each_entry_reverse(field, head, link) { |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 575 | /* |
| 576 | * Smartly shows the array type(except dynamic array). |
| 577 | * Normal: |
| 578 | * field:TYPE VAR |
| 579 | * If TYPE := TYPE[LEN], it is shown: |
| 580 | * field:TYPE VAR[LEN] |
| 581 | */ |
| 582 | const char *array_descriptor = strchr(field->type, '['); |
| 583 | |
| 584 | if (!strncmp(field->type, "__data_loc", 10)) |
| 585 | array_descriptor = NULL; |
| 586 | |
| 587 | if (!array_descriptor) { |
| 588 | r = trace_seq_printf(s, "\tfield:%s %s;\toffset:%u;" |
| 589 | "\tsize:%u;\tsigned:%d;\n", |
| 590 | field->type, field->name, field->offset, |
| 591 | field->size, !!field->is_signed); |
| 592 | } else { |
| 593 | r = trace_seq_printf(s, "\tfield:%.*s %s%s;\toffset:%u;" |
| 594 | "\tsize:%u;\tsigned:%d;\n", |
| 595 | (int)(array_descriptor - field->type), |
| 596 | field->type, field->name, |
| 597 | array_descriptor, field->offset, |
| 598 | field->size, !!field->is_signed); |
| 599 | } |
| 600 | |
| 601 | if (--common_field_count == 0) |
| 602 | r = trace_seq_printf(s, "\n"); |
| 603 | |
| 604 | if (!r) |
| 605 | break; |
| 606 | } |
| 607 | |
| 608 | if (r) |
| 609 | r = trace_seq_printf(s, "\nprint fmt: %s\n", |
| 610 | call->print_fmt); |
| 611 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 612 | if (!r) { |
| 613 | /* |
| 614 | * ug! The format output is bigger than a PAGE!! |
| 615 | */ |
| 616 | buf = "FORMAT TOO BIG\n"; |
| 617 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 618 | buf, strlen(buf)); |
| 619 | goto out; |
| 620 | } |
| 621 | |
| 622 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 623 | s->buffer, s->len); |
| 624 | out: |
| 625 | kfree(s); |
| 626 | return r; |
| 627 | } |
| 628 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 629 | static ssize_t |
| 630 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 631 | { |
| 632 | struct ftrace_event_call *call = filp->private_data; |
| 633 | struct trace_seq *s; |
| 634 | int r; |
| 635 | |
| 636 | if (*ppos) |
| 637 | return 0; |
| 638 | |
| 639 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 640 | if (!s) |
| 641 | return -ENOMEM; |
| 642 | |
| 643 | trace_seq_init(s); |
| 644 | trace_seq_printf(s, "%d\n", call->id); |
| 645 | |
| 646 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 647 | s->buffer, s->len); |
| 648 | kfree(s); |
| 649 | return r; |
| 650 | } |
| 651 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 652 | static ssize_t |
| 653 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 654 | loff_t *ppos) |
| 655 | { |
| 656 | struct ftrace_event_call *call = filp->private_data; |
| 657 | struct trace_seq *s; |
| 658 | int r; |
| 659 | |
| 660 | if (*ppos) |
| 661 | return 0; |
| 662 | |
| 663 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 664 | if (!s) |
| 665 | return -ENOMEM; |
| 666 | |
| 667 | trace_seq_init(s); |
| 668 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 669 | print_event_filter(call, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 670 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 671 | |
| 672 | kfree(s); |
| 673 | |
| 674 | return r; |
| 675 | } |
| 676 | |
| 677 | static ssize_t |
| 678 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 679 | loff_t *ppos) |
| 680 | { |
| 681 | struct ftrace_event_call *call = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 682 | char *buf; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 683 | int err; |
| 684 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 685 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 686 | return -EINVAL; |
| 687 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 688 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 689 | if (!buf) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 690 | return -ENOMEM; |
| 691 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 692 | if (copy_from_user(buf, ubuf, cnt)) { |
| 693 | free_page((unsigned long) buf); |
| 694 | return -EFAULT; |
| 695 | } |
| 696 | buf[cnt] = '\0'; |
| 697 | |
| 698 | err = apply_event_filter(call, buf); |
| 699 | free_page((unsigned long) buf); |
| 700 | if (err < 0) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 701 | return err; |
Tom Zanussi | 0a19e53 | 2009-04-13 03:17:50 -0500 | [diff] [blame] | 702 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 703 | *ppos += cnt; |
| 704 | |
| 705 | return cnt; |
| 706 | } |
| 707 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 708 | static ssize_t |
| 709 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 710 | loff_t *ppos) |
| 711 | { |
| 712 | struct event_subsystem *system = filp->private_data; |
| 713 | struct trace_seq *s; |
| 714 | int r; |
| 715 | |
| 716 | if (*ppos) |
| 717 | return 0; |
| 718 | |
| 719 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 720 | if (!s) |
| 721 | return -ENOMEM; |
| 722 | |
| 723 | trace_seq_init(s); |
| 724 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 725 | print_subsystem_event_filter(system, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 726 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 727 | |
| 728 | kfree(s); |
| 729 | |
| 730 | return r; |
| 731 | } |
| 732 | |
| 733 | static ssize_t |
| 734 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 735 | loff_t *ppos) |
| 736 | { |
| 737 | struct event_subsystem *system = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 738 | char *buf; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 739 | int err; |
| 740 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 741 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 742 | return -EINVAL; |
| 743 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 744 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 745 | if (!buf) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 746 | return -ENOMEM; |
| 747 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 748 | if (copy_from_user(buf, ubuf, cnt)) { |
| 749 | free_page((unsigned long) buf); |
| 750 | return -EFAULT; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 751 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 752 | buf[cnt] = '\0'; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 753 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 754 | err = apply_subsystem_event_filter(system, buf); |
| 755 | free_page((unsigned long) buf); |
| 756 | if (err < 0) |
Li Zefan | 44e9c8b | 2009-04-11 15:55:28 +0800 | [diff] [blame] | 757 | return err; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 758 | |
| 759 | *ppos += cnt; |
| 760 | |
| 761 | return cnt; |
| 762 | } |
| 763 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 764 | static ssize_t |
| 765 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 766 | { |
| 767 | int (*func)(struct trace_seq *s) = filp->private_data; |
| 768 | struct trace_seq *s; |
| 769 | int r; |
| 770 | |
| 771 | if (*ppos) |
| 772 | return 0; |
| 773 | |
| 774 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 775 | if (!s) |
| 776 | return -ENOMEM; |
| 777 | |
| 778 | trace_seq_init(s); |
| 779 | |
| 780 | func(s); |
| 781 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
| 782 | |
| 783 | kfree(s); |
| 784 | |
| 785 | return r; |
| 786 | } |
| 787 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 788 | static const struct seq_operations show_event_seq_ops = { |
| 789 | .start = t_start, |
| 790 | .next = t_next, |
| 791 | .show = t_show, |
| 792 | .stop = t_stop, |
| 793 | }; |
| 794 | |
| 795 | static const struct seq_operations show_set_event_seq_ops = { |
| 796 | .start = s_start, |
| 797 | .next = s_next, |
| 798 | .show = t_show, |
| 799 | .stop = t_stop, |
| 800 | }; |
| 801 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 802 | static const struct file_operations ftrace_avail_fops = { |
| 803 | .open = ftrace_event_seq_open, |
| 804 | .read = seq_read, |
| 805 | .llseek = seq_lseek, |
| 806 | .release = seq_release, |
| 807 | }; |
| 808 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 809 | static const struct file_operations ftrace_set_event_fops = { |
| 810 | .open = ftrace_event_seq_open, |
| 811 | .read = seq_read, |
| 812 | .write = ftrace_event_write, |
| 813 | .llseek = seq_lseek, |
| 814 | .release = seq_release, |
| 815 | }; |
| 816 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 817 | static const struct file_operations ftrace_enable_fops = { |
| 818 | .open = tracing_open_generic, |
| 819 | .read = event_enable_read, |
| 820 | .write = event_enable_write, |
| 821 | }; |
| 822 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 823 | static const struct file_operations ftrace_event_format_fops = { |
| 824 | .open = tracing_open_generic, |
| 825 | .read = event_format_read, |
| 826 | }; |
| 827 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 828 | static const struct file_operations ftrace_event_id_fops = { |
| 829 | .open = tracing_open_generic, |
| 830 | .read = event_id_read, |
| 831 | }; |
| 832 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 833 | static const struct file_operations ftrace_event_filter_fops = { |
| 834 | .open = tracing_open_generic, |
| 835 | .read = event_filter_read, |
| 836 | .write = event_filter_write, |
| 837 | }; |
| 838 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 839 | static const struct file_operations ftrace_subsystem_filter_fops = { |
| 840 | .open = tracing_open_generic, |
| 841 | .read = subsystem_filter_read, |
| 842 | .write = subsystem_filter_write, |
| 843 | }; |
| 844 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 845 | static const struct file_operations ftrace_system_enable_fops = { |
| 846 | .open = tracing_open_generic, |
| 847 | .read = system_enable_read, |
| 848 | .write = system_enable_write, |
| 849 | }; |
| 850 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 851 | static const struct file_operations ftrace_show_header_fops = { |
| 852 | .open = tracing_open_generic, |
| 853 | .read = show_header, |
| 854 | }; |
| 855 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 856 | static struct dentry *event_trace_events_dir(void) |
| 857 | { |
| 858 | static struct dentry *d_tracer; |
| 859 | static struct dentry *d_events; |
| 860 | |
| 861 | if (d_events) |
| 862 | return d_events; |
| 863 | |
| 864 | d_tracer = tracing_init_dentry(); |
| 865 | if (!d_tracer) |
| 866 | return NULL; |
| 867 | |
| 868 | d_events = debugfs_create_dir("events", d_tracer); |
| 869 | if (!d_events) |
| 870 | pr_warning("Could not create debugfs " |
| 871 | "'events' directory\n"); |
| 872 | |
| 873 | return d_events; |
| 874 | } |
| 875 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 876 | static LIST_HEAD(event_subsystems); |
| 877 | |
| 878 | static struct dentry * |
| 879 | event_subsystem_dir(const char *name, struct dentry *d_events) |
| 880 | { |
| 881 | struct event_subsystem *system; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 882 | struct dentry *entry; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 883 | |
| 884 | /* First see if we did not already create this dir */ |
| 885 | list_for_each_entry(system, &event_subsystems, list) { |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 886 | if (strcmp(system->name, name) == 0) { |
| 887 | system->nr_events++; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 888 | return system->entry; |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 889 | } |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /* need to create new entry */ |
| 893 | system = kmalloc(sizeof(*system), GFP_KERNEL); |
| 894 | if (!system) { |
| 895 | pr_warning("No memory to create event subsystem %s\n", |
| 896 | name); |
| 897 | return d_events; |
| 898 | } |
| 899 | |
| 900 | system->entry = debugfs_create_dir(name, d_events); |
| 901 | if (!system->entry) { |
| 902 | pr_warning("Could not create event subsystem %s\n", |
| 903 | name); |
| 904 | kfree(system); |
| 905 | return d_events; |
| 906 | } |
| 907 | |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 908 | system->nr_events = 1; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 909 | system->name = kstrdup(name, GFP_KERNEL); |
| 910 | if (!system->name) { |
| 911 | debugfs_remove(system->entry); |
| 912 | kfree(system); |
| 913 | return d_events; |
| 914 | } |
| 915 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 916 | list_add(&system->list, &event_subsystems); |
| 917 | |
Tom Zanussi | 30e673b | 2009-04-28 03:04:47 -0500 | [diff] [blame] | 918 | system->filter = NULL; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 919 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 920 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); |
| 921 | if (!system->filter) { |
| 922 | pr_warning("Could not allocate filter for subsystem " |
| 923 | "'%s'\n", name); |
| 924 | return system->entry; |
| 925 | } |
| 926 | |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 927 | entry = debugfs_create_file("filter", 0644, system->entry, system, |
| 928 | &ftrace_subsystem_filter_fops); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 929 | if (!entry) { |
| 930 | kfree(system->filter); |
| 931 | system->filter = NULL; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 932 | pr_warning("Could not create debugfs " |
| 933 | "'%s/filter' entry\n", name); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 934 | } |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 935 | |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 936 | trace_create_file("enable", 0644, system->entry, |
| 937 | (void *)system->name, |
| 938 | &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 939 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 940 | return system->entry; |
| 941 | } |
| 942 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 943 | static int |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 944 | event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, |
| 945 | const struct file_operations *id, |
| 946 | const struct file_operations *enable, |
| 947 | const struct file_operations *filter, |
| 948 | const struct file_operations *format) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 949 | { |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 950 | struct list_head *head; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 951 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 952 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 953 | /* |
| 954 | * If the trace point header did not define TRACE_SYSTEM |
| 955 | * then the system would be called "TRACE_SYSTEM". |
| 956 | */ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 957 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
| 958 | d_events = event_subsystem_dir(call->class->system, d_events); |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 959 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 960 | call->dir = debugfs_create_dir(call->name, d_events); |
| 961 | if (!call->dir) { |
| 962 | pr_warning("Could not create debugfs " |
| 963 | "'%s' directory\n", call->name); |
| 964 | return -1; |
| 965 | } |
| 966 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 967 | if (call->class->probe || call->class->reg) |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 968 | trace_create_file("enable", 0644, call->dir, call, |
| 969 | enable); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 970 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 971 | #ifdef CONFIG_PERF_EVENTS |
| 972 | if (call->id && (call->class->perf_probe || call->class->reg)) |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 973 | trace_create_file("id", 0444, call->dir, call, |
| 974 | id); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 975 | #endif |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 976 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 977 | if (call->class->define_fields) { |
| 978 | /* |
| 979 | * Other events may have the same class. Only update |
| 980 | * the fields if they are not already defined. |
| 981 | */ |
| 982 | head = trace_get_fields(call); |
| 983 | if (list_empty(head)) { |
| 984 | ret = trace_define_common_fields(call); |
| 985 | if (!ret) |
| 986 | ret = call->class->define_fields(call); |
| 987 | if (ret < 0) { |
| 988 | pr_warning("Could not initialize trace point" |
| 989 | " events/%s\n", call->name); |
| 990 | return ret; |
| 991 | } |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 992 | } |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 993 | trace_create_file("filter", 0644, call->dir, call, |
| 994 | filter); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 995 | } |
| 996 | |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 997 | trace_create_file("format", 0444, call->dir, call, |
| 998 | format); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 999 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1000 | return 0; |
| 1001 | } |
| 1002 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1003 | static int __trace_add_event_call(struct ftrace_event_call *call) |
| 1004 | { |
| 1005 | struct dentry *d_events; |
| 1006 | int ret; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1007 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1008 | if (!call->name) |
| 1009 | return -EINVAL; |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1010 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1011 | if (call->raw_init) { |
| 1012 | ret = call->raw_init(call); |
| 1013 | if (ret < 0) { |
| 1014 | if (ret != -ENOSYS) |
| 1015 | pr_warning("Could not initialize trace " |
| 1016 | "events/%s\n", call->name); |
| 1017 | return ret; |
| 1018 | } |
| 1019 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1020 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1021 | d_events = event_trace_events_dir(); |
| 1022 | if (!d_events) |
| 1023 | return -ENOENT; |
| 1024 | |
Masami Hiramatsu | 588bebb | 2009-09-16 11:42:55 -0400 | [diff] [blame] | 1025 | ret = event_create_dir(call, d_events, &ftrace_event_id_fops, |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1026 | &ftrace_enable_fops, &ftrace_event_filter_fops, |
| 1027 | &ftrace_event_format_fops); |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1028 | if (!ret) |
| 1029 | list_add(&call->list, &ftrace_events); |
| 1030 | |
Masami Hiramatsu | 588bebb | 2009-09-16 11:42:55 -0400 | [diff] [blame] | 1031 | return ret; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /* Add an additional event_call dynamically */ |
| 1035 | int trace_add_event_call(struct ftrace_event_call *call) |
| 1036 | { |
| 1037 | int ret; |
| 1038 | mutex_lock(&event_mutex); |
| 1039 | ret = __trace_add_event_call(call); |
| 1040 | mutex_unlock(&event_mutex); |
| 1041 | return ret; |
| 1042 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1043 | |
Frederic Weisbecker | a2ca5e0 | 2009-08-06 07:32:21 +0200 | [diff] [blame] | 1044 | static void remove_subsystem_dir(const char *name) |
| 1045 | { |
| 1046 | struct event_subsystem *system; |
| 1047 | |
| 1048 | if (strcmp(name, TRACE_SYSTEM) == 0) |
| 1049 | return; |
| 1050 | |
| 1051 | list_for_each_entry(system, &event_subsystems, list) { |
| 1052 | if (strcmp(system->name, name) == 0) { |
| 1053 | if (!--system->nr_events) { |
| 1054 | struct event_filter *filter = system->filter; |
| 1055 | |
| 1056 | debugfs_remove_recursive(system->entry); |
| 1057 | list_del(&system->list); |
| 1058 | if (filter) { |
| 1059 | kfree(filter->filter_string); |
| 1060 | kfree(filter); |
| 1061 | } |
| 1062 | kfree(system->name); |
| 1063 | kfree(system); |
| 1064 | } |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1070 | /* |
| 1071 | * Must be called under locking both of event_mutex and trace_event_mutex. |
| 1072 | */ |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1073 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
| 1074 | { |
| 1075 | ftrace_event_enable_disable(call, 0); |
| 1076 | if (call->event) |
| 1077 | __unregister_ftrace_event(call->event); |
| 1078 | debugfs_remove_recursive(call->dir); |
| 1079 | list_del(&call->list); |
| 1080 | trace_destroy_fields(call); |
| 1081 | destroy_preds(call); |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 1082 | remove_subsystem_dir(call->class->system); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | /* Remove an event_call */ |
| 1086 | void trace_remove_event_call(struct ftrace_event_call *call) |
| 1087 | { |
| 1088 | mutex_lock(&event_mutex); |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1089 | down_write(&trace_event_mutex); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1090 | __trace_remove_event_call(call); |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1091 | up_write(&trace_event_mutex); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1092 | mutex_unlock(&event_mutex); |
| 1093 | } |
| 1094 | |
| 1095 | #define for_each_event(event, start, end) \ |
| 1096 | for (event = start; \ |
| 1097 | (unsigned long)event < (unsigned long)end; \ |
| 1098 | event++) |
| 1099 | |
| 1100 | #ifdef CONFIG_MODULES |
| 1101 | |
| 1102 | static LIST_HEAD(ftrace_module_file_list); |
| 1103 | |
| 1104 | /* |
| 1105 | * Modules must own their file_operations to keep up with |
| 1106 | * reference counting. |
| 1107 | */ |
| 1108 | struct ftrace_module_file_ops { |
| 1109 | struct list_head list; |
| 1110 | struct module *mod; |
| 1111 | struct file_operations id; |
| 1112 | struct file_operations enable; |
| 1113 | struct file_operations format; |
| 1114 | struct file_operations filter; |
| 1115 | }; |
| 1116 | |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1117 | static struct ftrace_module_file_ops * |
| 1118 | trace_create_file_ops(struct module *mod) |
| 1119 | { |
| 1120 | struct ftrace_module_file_ops *file_ops; |
| 1121 | |
| 1122 | /* |
| 1123 | * This is a bit of a PITA. To allow for correct reference |
| 1124 | * counting, modules must "own" their file_operations. |
| 1125 | * To do this, we allocate the file operations that will be |
| 1126 | * used in the event directory. |
| 1127 | */ |
| 1128 | |
| 1129 | file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL); |
| 1130 | if (!file_ops) |
| 1131 | return NULL; |
| 1132 | |
| 1133 | file_ops->mod = mod; |
| 1134 | |
| 1135 | file_ops->id = ftrace_event_id_fops; |
| 1136 | file_ops->id.owner = mod; |
| 1137 | |
| 1138 | file_ops->enable = ftrace_enable_fops; |
| 1139 | file_ops->enable.owner = mod; |
| 1140 | |
| 1141 | file_ops->filter = ftrace_event_filter_fops; |
| 1142 | file_ops->filter.owner = mod; |
| 1143 | |
| 1144 | file_ops->format = ftrace_event_format_fops; |
| 1145 | file_ops->format.owner = mod; |
| 1146 | |
| 1147 | list_add(&file_ops->list, &ftrace_module_file_list); |
| 1148 | |
| 1149 | return file_ops; |
| 1150 | } |
| 1151 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1152 | static void trace_module_add_events(struct module *mod) |
| 1153 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1154 | struct ftrace_module_file_ops *file_ops = NULL; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1155 | struct ftrace_event_call *call, *start, *end; |
| 1156 | struct dentry *d_events; |
Jason Baron | f744bd5 | 2009-08-10 16:52:39 -0400 | [diff] [blame] | 1157 | int ret; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1158 | |
| 1159 | start = mod->trace_events; |
| 1160 | end = mod->trace_events + mod->num_trace_events; |
| 1161 | |
| 1162 | if (start == end) |
| 1163 | return; |
| 1164 | |
| 1165 | d_events = event_trace_events_dir(); |
| 1166 | if (!d_events) |
| 1167 | return; |
| 1168 | |
| 1169 | for_each_event(call, start, end) { |
| 1170 | /* The linker may leave blanks */ |
| 1171 | if (!call->name) |
| 1172 | continue; |
Jason Baron | f744bd5 | 2009-08-10 16:52:39 -0400 | [diff] [blame] | 1173 | if (call->raw_init) { |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1174 | ret = call->raw_init(call); |
Jason Baron | f744bd5 | 2009-08-10 16:52:39 -0400 | [diff] [blame] | 1175 | if (ret < 0) { |
| 1176 | if (ret != -ENOSYS) |
| 1177 | pr_warning("Could not initialize trace " |
| 1178 | "point events/%s\n", call->name); |
| 1179 | continue; |
| 1180 | } |
| 1181 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1182 | /* |
| 1183 | * This module has events, create file ops for this module |
| 1184 | * if not already done. |
| 1185 | */ |
| 1186 | if (!file_ops) { |
| 1187 | file_ops = trace_create_file_ops(mod); |
| 1188 | if (!file_ops) |
| 1189 | return; |
| 1190 | } |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1191 | call->mod = mod; |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1192 | ret = event_create_dir(call, d_events, |
| 1193 | &file_ops->id, &file_ops->enable, |
| 1194 | &file_ops->filter, &file_ops->format); |
| 1195 | if (!ret) |
| 1196 | list_add(&call->list, &ftrace_events); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | static void trace_module_remove_events(struct module *mod) |
| 1201 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1202 | struct ftrace_module_file_ops *file_ops; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1203 | struct ftrace_event_call *call, *p; |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1204 | bool found = false; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1205 | |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1206 | down_write(&trace_event_mutex); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1207 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
| 1208 | if (call->mod == mod) { |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1209 | found = true; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1210 | __trace_remove_event_call(call); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1211 | } |
| 1212 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1213 | |
| 1214 | /* Now free the file_operations */ |
| 1215 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { |
| 1216 | if (file_ops->mod == mod) |
| 1217 | break; |
| 1218 | } |
| 1219 | if (&file_ops->list != &ftrace_module_file_list) { |
| 1220 | list_del(&file_ops->list); |
| 1221 | kfree(file_ops); |
| 1222 | } |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1223 | |
| 1224 | /* |
| 1225 | * It is safest to reset the ring buffer if the module being unloaded |
| 1226 | * registered any events. |
| 1227 | */ |
| 1228 | if (found) |
| 1229 | tracing_reset_current_online_cpus(); |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1230 | up_write(&trace_event_mutex); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1233 | static int trace_module_notify(struct notifier_block *self, |
| 1234 | unsigned long val, void *data) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1235 | { |
| 1236 | struct module *mod = data; |
| 1237 | |
| 1238 | mutex_lock(&event_mutex); |
| 1239 | switch (val) { |
| 1240 | case MODULE_STATE_COMING: |
| 1241 | trace_module_add_events(mod); |
| 1242 | break; |
| 1243 | case MODULE_STATE_GOING: |
| 1244 | trace_module_remove_events(mod); |
| 1245 | break; |
| 1246 | } |
| 1247 | mutex_unlock(&event_mutex); |
| 1248 | |
| 1249 | return 0; |
| 1250 | } |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1251 | #else |
| 1252 | static int trace_module_notify(struct notifier_block *self, |
| 1253 | unsigned long val, void *data) |
| 1254 | { |
| 1255 | return 0; |
| 1256 | } |
| 1257 | #endif /* CONFIG_MODULES */ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1258 | |
Steven Rostedt | ec827c7 | 2009-09-14 10:50:23 -0400 | [diff] [blame] | 1259 | static struct notifier_block trace_module_nb = { |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1260 | .notifier_call = trace_module_notify, |
| 1261 | .priority = 0, |
| 1262 | }; |
| 1263 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1264 | extern struct ftrace_event_call __start_ftrace_events[]; |
| 1265 | extern struct ftrace_event_call __stop_ftrace_events[]; |
| 1266 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1267 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
| 1268 | |
| 1269 | static __init int setup_trace_event(char *str) |
| 1270 | { |
| 1271 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); |
| 1272 | ring_buffer_expanded = 1; |
| 1273 | tracing_selftest_disabled = 1; |
| 1274 | |
| 1275 | return 1; |
| 1276 | } |
| 1277 | __setup("trace_event=", setup_trace_event); |
| 1278 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1279 | static __init int event_trace_init(void) |
| 1280 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1281 | struct ftrace_event_call *call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1282 | struct dentry *d_tracer; |
| 1283 | struct dentry *entry; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1284 | struct dentry *d_events; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1285 | int ret; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1286 | char *buf = bootup_event_buf; |
| 1287 | char *token; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1288 | |
| 1289 | d_tracer = tracing_init_dentry(); |
| 1290 | if (!d_tracer) |
| 1291 | return 0; |
| 1292 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1293 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
| 1294 | (void *)&show_event_seq_ops, |
| 1295 | &ftrace_avail_fops); |
| 1296 | if (!entry) |
| 1297 | pr_warning("Could not create debugfs " |
| 1298 | "'available_events' entry\n"); |
| 1299 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1300 | entry = debugfs_create_file("set_event", 0644, d_tracer, |
| 1301 | (void *)&show_set_event_seq_ops, |
| 1302 | &ftrace_set_event_fops); |
| 1303 | if (!entry) |
| 1304 | pr_warning("Could not create debugfs " |
| 1305 | "'set_event' entry\n"); |
| 1306 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1307 | d_events = event_trace_events_dir(); |
| 1308 | if (!d_events) |
| 1309 | return 0; |
| 1310 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1311 | /* ring buffer internal formats */ |
| 1312 | trace_create_file("header_page", 0444, d_events, |
| 1313 | ring_buffer_print_page_header, |
| 1314 | &ftrace_show_header_fops); |
| 1315 | |
| 1316 | trace_create_file("header_event", 0444, d_events, |
| 1317 | ring_buffer_print_entry_header, |
| 1318 | &ftrace_show_header_fops); |
| 1319 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1320 | trace_create_file("enable", 0644, d_events, |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1321 | NULL, &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1322 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1323 | for_each_event(call, __start_ftrace_events, __stop_ftrace_events) { |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1324 | /* The linker may leave blanks */ |
| 1325 | if (!call->name) |
| 1326 | continue; |
Jason Baron | f744bd5 | 2009-08-10 16:52:39 -0400 | [diff] [blame] | 1327 | if (call->raw_init) { |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1328 | ret = call->raw_init(call); |
Jason Baron | f744bd5 | 2009-08-10 16:52:39 -0400 | [diff] [blame] | 1329 | if (ret < 0) { |
| 1330 | if (ret != -ENOSYS) |
| 1331 | pr_warning("Could not initialize trace " |
| 1332 | "point events/%s\n", call->name); |
| 1333 | continue; |
| 1334 | } |
| 1335 | } |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1336 | ret = event_create_dir(call, d_events, &ftrace_event_id_fops, |
| 1337 | &ftrace_enable_fops, |
| 1338 | &ftrace_event_filter_fops, |
| 1339 | &ftrace_event_format_fops); |
| 1340 | if (!ret) |
| 1341 | list_add(&call->list, &ftrace_events); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1342 | } |
| 1343 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1344 | while (true) { |
| 1345 | token = strsep(&buf, ","); |
| 1346 | |
| 1347 | if (!token) |
| 1348 | break; |
| 1349 | if (!*token) |
| 1350 | continue; |
| 1351 | |
| 1352 | ret = ftrace_set_clr_event(token, 1); |
| 1353 | if (ret) |
| 1354 | pr_warning("Failed to enable trace event: %s\n", token); |
| 1355 | } |
| 1356 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1357 | ret = register_module_notifier(&trace_module_nb); |
Ming Lei | 5537937 | 2009-05-18 23:04:46 +0800 | [diff] [blame] | 1358 | if (ret) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1359 | pr_warning("Failed to register trace events module notifier\n"); |
| 1360 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1361 | return 0; |
| 1362 | } |
| 1363 | fs_initcall(event_trace_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1364 | |
| 1365 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1366 | |
| 1367 | static DEFINE_SPINLOCK(test_spinlock); |
| 1368 | static DEFINE_SPINLOCK(test_spinlock_irq); |
| 1369 | static DEFINE_MUTEX(test_mutex); |
| 1370 | |
| 1371 | static __init void test_work(struct work_struct *dummy) |
| 1372 | { |
| 1373 | spin_lock(&test_spinlock); |
| 1374 | spin_lock_irq(&test_spinlock_irq); |
| 1375 | udelay(1); |
| 1376 | spin_unlock_irq(&test_spinlock_irq); |
| 1377 | spin_unlock(&test_spinlock); |
| 1378 | |
| 1379 | mutex_lock(&test_mutex); |
| 1380 | msleep(1); |
| 1381 | mutex_unlock(&test_mutex); |
| 1382 | } |
| 1383 | |
| 1384 | static __init int event_test_thread(void *unused) |
| 1385 | { |
| 1386 | void *test_malloc; |
| 1387 | |
| 1388 | test_malloc = kmalloc(1234, GFP_KERNEL); |
| 1389 | if (!test_malloc) |
| 1390 | pr_info("failed to kmalloc\n"); |
| 1391 | |
| 1392 | schedule_on_each_cpu(test_work); |
| 1393 | |
| 1394 | kfree(test_malloc); |
| 1395 | |
| 1396 | set_current_state(TASK_INTERRUPTIBLE); |
| 1397 | while (!kthread_should_stop()) |
| 1398 | schedule(); |
| 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | /* |
| 1404 | * Do various things that may trigger events. |
| 1405 | */ |
| 1406 | static __init void event_test_stuff(void) |
| 1407 | { |
| 1408 | struct task_struct *test_thread; |
| 1409 | |
| 1410 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); |
| 1411 | msleep(1); |
| 1412 | kthread_stop(test_thread); |
| 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * For every trace event defined, we will test each trace point separately, |
| 1417 | * and then by groups, and finally all trace points. |
| 1418 | */ |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1419 | static __init void event_trace_self_tests(void) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1420 | { |
| 1421 | struct ftrace_event_call *call; |
| 1422 | struct event_subsystem *system; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1423 | int ret; |
| 1424 | |
| 1425 | pr_info("Running tests on trace events:\n"); |
| 1426 | |
| 1427 | list_for_each_entry(call, &ftrace_events, list) { |
| 1428 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1429 | /* Only test those that have a probe */ |
| 1430 | if (!call->class || !call->class->probe) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1431 | continue; |
| 1432 | |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 1433 | /* |
| 1434 | * Testing syscall events here is pretty useless, but |
| 1435 | * we still do it if configured. But this is time consuming. |
| 1436 | * What we really need is a user thread to perform the |
| 1437 | * syscalls as we test. |
| 1438 | */ |
| 1439 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 1440 | if (call->class->system && |
| 1441 | strcmp(call->class->system, "syscalls") == 0) |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 1442 | continue; |
| 1443 | #endif |
| 1444 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1445 | pr_info("Testing event %s: ", call->name); |
| 1446 | |
| 1447 | /* |
| 1448 | * If an event is already enabled, someone is using |
| 1449 | * it and the self test should not be on. |
| 1450 | */ |
| 1451 | if (call->enabled) { |
| 1452 | pr_warning("Enabled event during self test!\n"); |
| 1453 | WARN_ON_ONCE(1); |
| 1454 | continue; |
| 1455 | } |
| 1456 | |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1457 | ftrace_event_enable_disable(call, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1458 | event_test_stuff(); |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1459 | ftrace_event_enable_disable(call, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1460 | |
| 1461 | pr_cont("OK\n"); |
| 1462 | } |
| 1463 | |
| 1464 | /* Now test at the sub system level */ |
| 1465 | |
| 1466 | pr_info("Running tests on trace event systems:\n"); |
| 1467 | |
| 1468 | list_for_each_entry(system, &event_subsystems, list) { |
| 1469 | |
| 1470 | /* the ftrace system is special, skip it */ |
| 1471 | if (strcmp(system->name, "ftrace") == 0) |
| 1472 | continue; |
| 1473 | |
| 1474 | pr_info("Testing event system %s: ", system->name); |
| 1475 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1476 | ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1477 | if (WARN_ON_ONCE(ret)) { |
| 1478 | pr_warning("error enabling system %s\n", |
| 1479 | system->name); |
| 1480 | continue; |
| 1481 | } |
| 1482 | |
| 1483 | event_test_stuff(); |
| 1484 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1485 | ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1486 | if (WARN_ON_ONCE(ret)) |
| 1487 | pr_warning("error disabling system %s\n", |
| 1488 | system->name); |
| 1489 | |
| 1490 | pr_cont("OK\n"); |
| 1491 | } |
| 1492 | |
| 1493 | /* Test with all events enabled */ |
| 1494 | |
| 1495 | pr_info("Running tests on all trace events:\n"); |
| 1496 | pr_info("Testing all events: "); |
| 1497 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1498 | ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1499 | if (WARN_ON_ONCE(ret)) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1500 | pr_warning("error enabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1501 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | event_test_stuff(); |
| 1505 | |
| 1506 | /* reset sysname */ |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1507 | ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1508 | if (WARN_ON_ONCE(ret)) { |
| 1509 | pr_warning("error disabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1510 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | pr_cont("OK\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | #ifdef CONFIG_FUNCTION_TRACER |
| 1517 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1518 | static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1519 | |
| 1520 | static void |
| 1521 | function_test_events_call(unsigned long ip, unsigned long parent_ip) |
| 1522 | { |
| 1523 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1524 | struct ring_buffer *buffer; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1525 | struct ftrace_entry *entry; |
| 1526 | unsigned long flags; |
| 1527 | long disabled; |
| 1528 | int resched; |
| 1529 | int cpu; |
| 1530 | int pc; |
| 1531 | |
| 1532 | pc = preempt_count(); |
| 1533 | resched = ftrace_preempt_disable(); |
| 1534 | cpu = raw_smp_processor_id(); |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1535 | disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1536 | |
| 1537 | if (disabled != 1) |
| 1538 | goto out; |
| 1539 | |
| 1540 | local_save_flags(flags); |
| 1541 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1542 | event = trace_current_buffer_lock_reserve(&buffer, |
| 1543 | TRACE_FN, sizeof(*entry), |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1544 | flags, pc); |
| 1545 | if (!event) |
| 1546 | goto out; |
| 1547 | entry = ring_buffer_event_data(event); |
| 1548 | entry->ip = ip; |
| 1549 | entry->parent_ip = parent_ip; |
| 1550 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1551 | trace_nowake_buffer_unlock_commit(buffer, event, flags, pc); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1552 | |
| 1553 | out: |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1554 | atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1555 | ftrace_preempt_enable(resched); |
| 1556 | } |
| 1557 | |
| 1558 | static struct ftrace_ops trace_ops __initdata = |
| 1559 | { |
| 1560 | .func = function_test_events_call, |
| 1561 | }; |
| 1562 | |
| 1563 | static __init void event_trace_self_test_with_function(void) |
| 1564 | { |
| 1565 | register_ftrace_function(&trace_ops); |
| 1566 | pr_info("Running tests again, along with the function tracer\n"); |
| 1567 | event_trace_self_tests(); |
| 1568 | unregister_ftrace_function(&trace_ops); |
| 1569 | } |
| 1570 | #else |
| 1571 | static __init void event_trace_self_test_with_function(void) |
| 1572 | { |
| 1573 | } |
| 1574 | #endif |
| 1575 | |
| 1576 | static __init int event_trace_self_tests_init(void) |
| 1577 | { |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1578 | if (!tracing_selftest_disabled) { |
| 1579 | event_trace_self_tests(); |
| 1580 | event_trace_self_test_with_function(); |
| 1581 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1582 | |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
Steven Rostedt | 28d20e2 | 2009-04-20 12:12:44 -0400 | [diff] [blame] | 1586 | late_initcall(event_trace_self_tests_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1587 | |
| 1588 | #endif |