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