Frederic Weisbecker | 47788c5 | 2009-04-08 20:40:59 +0200 | [diff] [blame] | 1 | #include <trace/syscall.h> |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 2 | #include <trace/events/syscalls.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 3 | #include <linux/kernel.h> |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 4 | #include <linux/ftrace.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 5 | #include <linux/perf_event.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 6 | #include <asm/syscall.h> |
| 7 | |
| 8 | #include "trace_output.h" |
| 9 | #include "trace.h" |
| 10 | |
Frederic Weisbecker | 5be71b6 | 2009-03-15 22:10:37 +0100 | [diff] [blame] | 11 | static DEFINE_MUTEX(syscall_trace_lock); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 12 | static int sys_refcount_enter; |
| 13 | static int sys_refcount_exit; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 14 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); |
| 15 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 16 | |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 17 | extern unsigned long __start_syscalls_metadata[]; |
| 18 | extern unsigned long __stop_syscalls_metadata[]; |
| 19 | |
| 20 | static struct syscall_metadata **syscalls_metadata; |
| 21 | |
| 22 | static struct syscall_metadata *find_syscall_meta(unsigned long syscall) |
| 23 | { |
| 24 | struct syscall_metadata *start; |
| 25 | struct syscall_metadata *stop; |
| 26 | char str[KSYM_SYMBOL_LEN]; |
| 27 | |
| 28 | |
| 29 | start = (struct syscall_metadata *)__start_syscalls_metadata; |
| 30 | stop = (struct syscall_metadata *)__stop_syscalls_metadata; |
| 31 | kallsyms_lookup(syscall, NULL, NULL, NULL, str); |
| 32 | |
| 33 | for ( ; start < stop; start++) { |
| 34 | /* |
| 35 | * Only compare after the "sys" prefix. Archs that use |
| 36 | * syscall wrappers may have syscalls symbols aliases prefixed |
| 37 | * with "SyS" instead of "sys", leading to an unwanted |
| 38 | * mismatch. |
| 39 | */ |
| 40 | if (start->name && !strcmp(start->name + 3, str + 3)) |
| 41 | return start; |
| 42 | } |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | static struct syscall_metadata *syscall_nr_to_meta(int nr) |
| 47 | { |
| 48 | if (!syscalls_metadata || nr >= NR_syscalls || nr < 0) |
| 49 | return NULL; |
| 50 | |
| 51 | return syscalls_metadata[nr]; |
| 52 | } |
| 53 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 54 | enum print_line_t |
| 55 | print_syscall_enter(struct trace_iterator *iter, int flags) |
| 56 | { |
| 57 | struct trace_seq *s = &iter->seq; |
| 58 | struct trace_entry *ent = iter->ent; |
| 59 | struct syscall_trace_enter *trace; |
| 60 | struct syscall_metadata *entry; |
| 61 | int i, ret, syscall; |
| 62 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 63 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 64 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 65 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 66 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 67 | if (!entry) |
| 68 | goto end; |
| 69 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 70 | if (entry->enter_event->id != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 71 | WARN_ON_ONCE(1); |
| 72 | goto end; |
| 73 | } |
| 74 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 75 | ret = trace_seq_printf(s, "%s(", entry->name); |
| 76 | if (!ret) |
| 77 | return TRACE_TYPE_PARTIAL_LINE; |
| 78 | |
| 79 | for (i = 0; i < entry->nb_args; i++) { |
| 80 | /* parameter types */ |
Li Zefan | ba8b3a4 | 2009-08-17 16:55:18 +0800 | [diff] [blame] | 81 | if (trace_flags & TRACE_ITER_VERBOSE) { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 82 | ret = trace_seq_printf(s, "%s ", entry->types[i]); |
| 83 | if (!ret) |
| 84 | return TRACE_TYPE_PARTIAL_LINE; |
| 85 | } |
| 86 | /* parameter values */ |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 87 | ret = trace_seq_printf(s, "%s: %lx%s", entry->args[i], |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 88 | trace->args[i], |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 89 | i == entry->nb_args - 1 ? "" : ", "); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 90 | if (!ret) |
| 91 | return TRACE_TYPE_PARTIAL_LINE; |
| 92 | } |
| 93 | |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 94 | ret = trace_seq_putc(s, ')'); |
| 95 | if (!ret) |
| 96 | return TRACE_TYPE_PARTIAL_LINE; |
| 97 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 98 | end: |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 99 | ret = trace_seq_putc(s, '\n'); |
| 100 | if (!ret) |
| 101 | return TRACE_TYPE_PARTIAL_LINE; |
| 102 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 103 | return TRACE_TYPE_HANDLED; |
| 104 | } |
| 105 | |
| 106 | enum print_line_t |
| 107 | print_syscall_exit(struct trace_iterator *iter, int flags) |
| 108 | { |
| 109 | struct trace_seq *s = &iter->seq; |
| 110 | struct trace_entry *ent = iter->ent; |
| 111 | struct syscall_trace_exit *trace; |
| 112 | int syscall; |
| 113 | struct syscall_metadata *entry; |
| 114 | int ret; |
| 115 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 116 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 117 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 118 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 119 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 120 | if (!entry) { |
| 121 | trace_seq_printf(s, "\n"); |
| 122 | return TRACE_TYPE_HANDLED; |
| 123 | } |
| 124 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 125 | if (entry->exit_event->id != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 126 | WARN_ON_ONCE(1); |
| 127 | return TRACE_TYPE_UNHANDLED; |
| 128 | } |
| 129 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 130 | ret = trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, |
| 131 | trace->ret); |
| 132 | if (!ret) |
| 133 | return TRACE_TYPE_PARTIAL_LINE; |
| 134 | |
| 135 | return TRACE_TYPE_HANDLED; |
| 136 | } |
| 137 | |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 138 | extern char *__bad_type_size(void); |
| 139 | |
| 140 | #define SYSCALL_FIELD(type, name) \ |
| 141 | sizeof(type) != sizeof(trace.name) ? \ |
| 142 | __bad_type_size() : \ |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 143 | #type, #name, offsetof(typeof(trace), name), \ |
| 144 | sizeof(trace.name), is_signed_type(type) |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 145 | |
Li Zefan | 10a5b66 | 2009-08-19 15:53:05 +0800 | [diff] [blame] | 146 | int syscall_enter_format(struct ftrace_event_call *call, struct trace_seq *s) |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 147 | { |
| 148 | int i; |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 149 | int ret; |
Lai Jiangshan | 31c16b1 | 2009-12-01 16:23:30 +0800 | [diff] [blame] | 150 | struct syscall_metadata *entry = call->data; |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 151 | struct syscall_trace_enter trace; |
| 152 | int offset = offsetof(struct syscall_trace_enter, args); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 153 | |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 154 | ret = trace_seq_printf(s, "\tfield:%s %s;\toffset:%zu;\tsize:%zu;" |
| 155 | "\tsigned:%u;\n", |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 156 | SYSCALL_FIELD(int, nr)); |
| 157 | if (!ret) |
| 158 | return 0; |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 159 | |
| 160 | for (i = 0; i < entry->nb_args; i++) { |
| 161 | ret = trace_seq_printf(s, "\tfield:%s %s;", entry->types[i], |
| 162 | entry->args[i]); |
| 163 | if (!ret) |
| 164 | return 0; |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 165 | ret = trace_seq_printf(s, "\toffset:%d;\tsize:%zu;" |
| 166 | "\tsigned:%u;\n", offset, |
| 167 | sizeof(unsigned long), |
| 168 | is_signed_type(unsigned long)); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 169 | if (!ret) |
| 170 | return 0; |
| 171 | offset += sizeof(unsigned long); |
| 172 | } |
| 173 | |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 174 | trace_seq_puts(s, "\nprint fmt: \""); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 175 | for (i = 0; i < entry->nb_args; i++) { |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 176 | ret = trace_seq_printf(s, "%s: 0x%%0%zulx%s", entry->args[i], |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 177 | sizeof(unsigned long), |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 178 | i == entry->nb_args - 1 ? "" : ", "); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 179 | if (!ret) |
| 180 | return 0; |
| 181 | } |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 182 | trace_seq_putc(s, '"'); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 183 | |
| 184 | for (i = 0; i < entry->nb_args; i++) { |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 185 | ret = trace_seq_printf(s, ", ((unsigned long)(REC->%s))", |
| 186 | entry->args[i]); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 187 | if (!ret) |
| 188 | return 0; |
| 189 | } |
| 190 | |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 191 | return trace_seq_putc(s, '\n'); |
Frederic Weisbecker | dc4ddb4 | 2009-08-11 19:03:54 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Li Zefan | 10a5b66 | 2009-08-19 15:53:05 +0800 | [diff] [blame] | 194 | int syscall_exit_format(struct ftrace_event_call *call, struct trace_seq *s) |
| 195 | { |
| 196 | int ret; |
| 197 | struct syscall_trace_exit trace; |
| 198 | |
| 199 | ret = trace_seq_printf(s, |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 200 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;" |
| 201 | "\tsigned:%u;\n" |
| 202 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;" |
| 203 | "\tsigned:%u;\n", |
Li Zefan | 10a5b66 | 2009-08-19 15:53:05 +0800 | [diff] [blame] | 204 | SYSCALL_FIELD(int, nr), |
Tom Zanussi | ee949a8 | 2009-10-06 01:00:49 -0500 | [diff] [blame] | 205 | SYSCALL_FIELD(long, ret)); |
Li Zefan | 10a5b66 | 2009-08-19 15:53:05 +0800 | [diff] [blame] | 206 | if (!ret) |
| 207 | return 0; |
| 208 | |
| 209 | return trace_seq_printf(s, "\nprint fmt: \"0x%%lx\", REC->ret\n"); |
| 210 | } |
| 211 | |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 212 | int syscall_enter_define_fields(struct ftrace_event_call *call) |
| 213 | { |
| 214 | struct syscall_trace_enter trace; |
Lai Jiangshan | 31c16b1 | 2009-12-01 16:23:30 +0800 | [diff] [blame] | 215 | struct syscall_metadata *meta = call->data; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 216 | int ret; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 217 | int i; |
| 218 | int offset = offsetof(typeof(trace), args); |
| 219 | |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 220 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr), FILTER_OTHER); |
| 221 | if (ret) |
| 222 | return ret; |
| 223 | |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 224 | for (i = 0; i < meta->nb_args; i++) { |
Frederic Weisbecker | aeaeae1 | 2009-08-27 05:09:51 +0200 | [diff] [blame] | 225 | ret = trace_define_field(call, meta->types[i], |
| 226 | meta->args[i], offset, |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 227 | sizeof(unsigned long), 0, |
| 228 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 229 | offset += sizeof(unsigned long); |
| 230 | } |
| 231 | |
| 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | int syscall_exit_define_fields(struct ftrace_event_call *call) |
| 236 | { |
| 237 | struct syscall_trace_exit trace; |
| 238 | int ret; |
| 239 | |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 240 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr), FILTER_OTHER); |
| 241 | if (ret) |
| 242 | return ret; |
| 243 | |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 244 | ret = trace_define_field(call, SYSCALL_FIELD(long, ret), |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 245 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 246 | |
| 247 | return ret; |
| 248 | } |
| 249 | |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 250 | void ftrace_syscall_enter(struct pt_regs *regs, long id) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 251 | { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 252 | struct syscall_trace_enter *entry; |
| 253 | struct syscall_metadata *sys_data; |
| 254 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 255 | struct ring_buffer *buffer; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 256 | int size; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 257 | int syscall_nr; |
| 258 | |
| 259 | syscall_nr = syscall_get_nr(current, regs); |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 260 | if (syscall_nr < 0) |
| 261 | return; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 262 | if (!test_bit(syscall_nr, enabled_enter_syscalls)) |
| 263 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 264 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 265 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 266 | if (!sys_data) |
| 267 | return; |
| 268 | |
| 269 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
| 270 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 271 | event = trace_current_buffer_lock_reserve(&buffer, |
| 272 | sys_data->enter_event->id, size, 0, 0); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 273 | if (!event) |
| 274 | return; |
| 275 | |
| 276 | entry = ring_buffer_event_data(event); |
| 277 | entry->nr = syscall_nr; |
| 278 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); |
| 279 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 280 | if (!filter_current_check_discard(buffer, sys_data->enter_event, |
| 281 | entry, event)) |
| 282 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 285 | void ftrace_syscall_exit(struct pt_regs *regs, long ret) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 286 | { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 287 | struct syscall_trace_exit *entry; |
| 288 | struct syscall_metadata *sys_data; |
| 289 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 290 | struct ring_buffer *buffer; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 291 | int syscall_nr; |
| 292 | |
| 293 | syscall_nr = syscall_get_nr(current, regs); |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 294 | if (syscall_nr < 0) |
| 295 | return; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 296 | if (!test_bit(syscall_nr, enabled_exit_syscalls)) |
| 297 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 298 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 299 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 300 | if (!sys_data) |
| 301 | return; |
| 302 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 303 | event = trace_current_buffer_lock_reserve(&buffer, |
| 304 | sys_data->exit_event->id, sizeof(*entry), 0, 0); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 305 | if (!event) |
| 306 | return; |
| 307 | |
| 308 | entry = ring_buffer_event_data(event); |
| 309 | entry->nr = syscall_nr; |
| 310 | entry->ret = syscall_get_return_value(current, regs); |
| 311 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 312 | if (!filter_current_check_discard(buffer, sys_data->exit_event, |
| 313 | entry, event)) |
| 314 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 317 | int reg_event_syscall_enter(struct ftrace_event_call *call) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 318 | { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 319 | int ret = 0; |
| 320 | int num; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 321 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 322 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 323 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 324 | return -ENOSYS; |
| 325 | mutex_lock(&syscall_trace_lock); |
| 326 | if (!sys_refcount_enter) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 327 | ret = register_trace_sys_enter(ftrace_syscall_enter); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 328 | if (ret) { |
| 329 | pr_info("event trace: Could not activate" |
| 330 | "syscall entry trace point"); |
| 331 | } else { |
| 332 | set_bit(num, enabled_enter_syscalls); |
| 333 | sys_refcount_enter++; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 334 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 335 | mutex_unlock(&syscall_trace_lock); |
| 336 | return ret; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 337 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 338 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 339 | void unreg_event_syscall_enter(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 340 | { |
| 341 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 342 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 343 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 344 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 345 | return; |
| 346 | mutex_lock(&syscall_trace_lock); |
| 347 | sys_refcount_enter--; |
| 348 | clear_bit(num, enabled_enter_syscalls); |
| 349 | if (!sys_refcount_enter) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 350 | unregister_trace_sys_enter(ftrace_syscall_enter); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 351 | mutex_unlock(&syscall_trace_lock); |
| 352 | } |
| 353 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 354 | int reg_event_syscall_exit(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 355 | { |
| 356 | int ret = 0; |
| 357 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 358 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 359 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 360 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 361 | return -ENOSYS; |
| 362 | mutex_lock(&syscall_trace_lock); |
| 363 | if (!sys_refcount_exit) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 364 | ret = register_trace_sys_exit(ftrace_syscall_exit); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 365 | if (ret) { |
| 366 | pr_info("event trace: Could not activate" |
| 367 | "syscall exit trace point"); |
| 368 | } else { |
| 369 | set_bit(num, enabled_exit_syscalls); |
| 370 | sys_refcount_exit++; |
| 371 | } |
| 372 | mutex_unlock(&syscall_trace_lock); |
| 373 | return ret; |
| 374 | } |
| 375 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 376 | void unreg_event_syscall_exit(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 377 | { |
| 378 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 379 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 380 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 381 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 382 | return; |
| 383 | mutex_lock(&syscall_trace_lock); |
| 384 | sys_refcount_exit--; |
| 385 | clear_bit(num, enabled_exit_syscalls); |
| 386 | if (!sys_refcount_exit) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 387 | unregister_trace_sys_exit(ftrace_syscall_exit); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 388 | mutex_unlock(&syscall_trace_lock); |
| 389 | } |
| 390 | |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 391 | int init_syscall_trace(struct ftrace_event_call *call) |
| 392 | { |
| 393 | int id; |
| 394 | |
| 395 | id = register_ftrace_event(call->event); |
| 396 | if (!id) |
| 397 | return -ENODEV; |
| 398 | call->id = id; |
| 399 | INIT_LIST_HEAD(&call->fields); |
| 400 | return 0; |
| 401 | } |
| 402 | |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 403 | int __init init_ftrace_syscalls(void) |
| 404 | { |
| 405 | struct syscall_metadata *meta; |
| 406 | unsigned long addr; |
| 407 | int i; |
| 408 | |
| 409 | syscalls_metadata = kzalloc(sizeof(*syscalls_metadata) * |
| 410 | NR_syscalls, GFP_KERNEL); |
| 411 | if (!syscalls_metadata) { |
| 412 | WARN_ON(1); |
| 413 | return -ENOMEM; |
| 414 | } |
| 415 | |
| 416 | for (i = 0; i < NR_syscalls; i++) { |
| 417 | addr = arch_syscall_addr(i); |
| 418 | meta = find_syscall_meta(addr); |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 419 | if (!meta) |
| 420 | continue; |
| 421 | |
| 422 | meta->syscall_nr = i; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 423 | syscalls_metadata[i] = meta; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | core_initcall(init_ftrace_syscalls); |
| 429 | |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 430 | #ifdef CONFIG_EVENT_PROFILE |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 431 | |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 432 | static DECLARE_BITMAP(enabled_prof_enter_syscalls, NR_syscalls); |
| 433 | static DECLARE_BITMAP(enabled_prof_exit_syscalls, NR_syscalls); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 434 | static int sys_prof_refcount_enter; |
| 435 | static int sys_prof_refcount_exit; |
| 436 | |
| 437 | static void prof_syscall_enter(struct pt_regs *regs, long id) |
| 438 | { |
| 439 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 440 | struct syscall_trace_enter *rec; |
| 441 | unsigned long flags; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 442 | char *trace_buf; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 443 | char *raw_data; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 444 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 445 | int rctx; |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 446 | int size; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 447 | int cpu; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 448 | |
| 449 | syscall_nr = syscall_get_nr(current, regs); |
| 450 | if (!test_bit(syscall_nr, enabled_prof_enter_syscalls)) |
| 451 | return; |
| 452 | |
| 453 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 454 | if (!sys_data) |
| 455 | return; |
| 456 | |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 457 | /* get the size after alignment with the u32 buffer size field */ |
| 458 | size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); |
| 459 | size = ALIGN(size + sizeof(u32), sizeof(u64)); |
| 460 | size -= sizeof(u32); |
| 461 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 462 | if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE, |
| 463 | "profile buffer not large enough")) |
| 464 | return; |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 465 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 466 | /* Protect the per cpu buffer, begin the rcu read side */ |
| 467 | local_irq_save(flags); |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 468 | |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 469 | rctx = perf_swevent_get_recursion_context(); |
| 470 | if (rctx < 0) |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 471 | goto end_recursion; |
| 472 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 473 | cpu = smp_processor_id(); |
| 474 | |
Frederic Weisbecker | 28889bf | 2009-11-22 05:21:33 +0100 | [diff] [blame] | 475 | trace_buf = rcu_dereference(perf_trace_buf); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 476 | |
Frederic Weisbecker | 444a2a3 | 2009-11-06 04:13:05 +0100 | [diff] [blame] | 477 | if (!trace_buf) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 478 | goto end; |
| 479 | |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 480 | raw_data = per_cpu_ptr(trace_buf, cpu); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 481 | |
| 482 | /* zero the dead bytes from align to not leak stack to user */ |
| 483 | *(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL; |
| 484 | |
| 485 | rec = (struct syscall_trace_enter *) raw_data; |
| 486 | tracing_generic_entry_update(&rec->ent, 0, 0); |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 487 | rec->ent.type = sys_data->enter_event->id; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 488 | rec->nr = syscall_nr; |
| 489 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, |
| 490 | (unsigned long *)&rec->args); |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 491 | perf_tp_event(sys_data->enter_event->id, 0, 1, rec, size); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 492 | |
| 493 | end: |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 494 | perf_swevent_put_recursion_context(rctx); |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 495 | end_recursion: |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 496 | local_irq_restore(flags); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 499 | int prof_sysenter_enable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 500 | { |
| 501 | int ret = 0; |
| 502 | int num; |
| 503 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 504 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 505 | |
| 506 | mutex_lock(&syscall_trace_lock); |
| 507 | if (!sys_prof_refcount_enter) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 508 | ret = register_trace_sys_enter(prof_syscall_enter); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 509 | if (ret) { |
| 510 | pr_info("event trace: Could not activate" |
| 511 | "syscall entry trace point"); |
| 512 | } else { |
| 513 | set_bit(num, enabled_prof_enter_syscalls); |
| 514 | sys_prof_refcount_enter++; |
| 515 | } |
| 516 | mutex_unlock(&syscall_trace_lock); |
| 517 | return ret; |
| 518 | } |
| 519 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 520 | void prof_sysenter_disable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 521 | { |
| 522 | int num; |
| 523 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 524 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 525 | |
| 526 | mutex_lock(&syscall_trace_lock); |
| 527 | sys_prof_refcount_enter--; |
| 528 | clear_bit(num, enabled_prof_enter_syscalls); |
| 529 | if (!sys_prof_refcount_enter) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 530 | unregister_trace_sys_enter(prof_syscall_enter); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 531 | mutex_unlock(&syscall_trace_lock); |
| 532 | } |
| 533 | |
| 534 | static void prof_syscall_exit(struct pt_regs *regs, long ret) |
| 535 | { |
| 536 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 537 | struct syscall_trace_exit *rec; |
| 538 | unsigned long flags; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 539 | int syscall_nr; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 540 | char *trace_buf; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 541 | char *raw_data; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 542 | int rctx; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 543 | int size; |
| 544 | int cpu; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 545 | |
| 546 | syscall_nr = syscall_get_nr(current, regs); |
| 547 | if (!test_bit(syscall_nr, enabled_prof_exit_syscalls)) |
| 548 | return; |
| 549 | |
| 550 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 551 | if (!sys_data) |
| 552 | return; |
| 553 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 554 | /* We can probably do that at build time */ |
| 555 | size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); |
| 556 | size -= sizeof(u32); |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 557 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 558 | /* |
| 559 | * Impossible, but be paranoid with the future |
| 560 | * How to put this check outside runtime? |
| 561 | */ |
| 562 | if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE, |
| 563 | "exit event has grown above profile buffer size")) |
| 564 | return; |
| 565 | |
| 566 | /* Protect the per cpu buffer, begin the rcu read side */ |
| 567 | local_irq_save(flags); |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 568 | |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 569 | rctx = perf_swevent_get_recursion_context(); |
| 570 | if (rctx < 0) |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 571 | goto end_recursion; |
| 572 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 573 | cpu = smp_processor_id(); |
| 574 | |
Frederic Weisbecker | 28889bf | 2009-11-22 05:21:33 +0100 | [diff] [blame] | 575 | trace_buf = rcu_dereference(perf_trace_buf); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 576 | |
Frederic Weisbecker | 444a2a3 | 2009-11-06 04:13:05 +0100 | [diff] [blame] | 577 | if (!trace_buf) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 578 | goto end; |
| 579 | |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 580 | raw_data = per_cpu_ptr(trace_buf, cpu); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 581 | |
| 582 | /* zero the dead bytes from align to not leak stack to user */ |
| 583 | *(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL; |
| 584 | |
| 585 | rec = (struct syscall_trace_exit *)raw_data; |
| 586 | |
| 587 | tracing_generic_entry_update(&rec->ent, 0, 0); |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 588 | rec->ent.type = sys_data->exit_event->id; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 589 | rec->nr = syscall_nr; |
| 590 | rec->ret = syscall_get_return_value(current, regs); |
| 591 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 592 | perf_tp_event(sys_data->exit_event->id, 0, 1, rec, size); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 593 | |
| 594 | end: |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 595 | perf_swevent_put_recursion_context(rctx); |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 596 | end_recursion: |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 597 | local_irq_restore(flags); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 600 | int prof_sysexit_enable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 601 | { |
| 602 | int ret = 0; |
| 603 | int num; |
| 604 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 605 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 606 | |
| 607 | mutex_lock(&syscall_trace_lock); |
| 608 | if (!sys_prof_refcount_exit) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 609 | ret = register_trace_sys_exit(prof_syscall_exit); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 610 | if (ret) { |
| 611 | pr_info("event trace: Could not activate" |
| 612 | "syscall entry trace point"); |
| 613 | } else { |
| 614 | set_bit(num, enabled_prof_exit_syscalls); |
| 615 | sys_prof_refcount_exit++; |
| 616 | } |
| 617 | mutex_unlock(&syscall_trace_lock); |
| 618 | return ret; |
| 619 | } |
| 620 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 621 | void prof_sysexit_disable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 622 | { |
| 623 | int num; |
| 624 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 625 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 626 | |
| 627 | mutex_lock(&syscall_trace_lock); |
| 628 | sys_prof_refcount_exit--; |
| 629 | clear_bit(num, enabled_prof_exit_syscalls); |
| 630 | if (!sys_prof_refcount_exit) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 631 | unregister_trace_sys_exit(prof_syscall_exit); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 632 | mutex_unlock(&syscall_trace_lock); |
| 633 | } |
| 634 | |
| 635 | #endif |
| 636 | |
| 637 | |