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