1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * trace task wakeup timings 4 * 5 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> 6 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> 7 * 8 * Based on code from the latency_tracer, that is: 9 * 10 * Copyright (C) 2004-2006 Ingo Molnar 11 * Copyright (C) 2004 Nadia Yvette Chambers 12 */ 13 #include <linux/module.h> 14 #include <linux/kallsyms.h> 15 #include <linux/uaccess.h> 16 #include <linux/ftrace.h> 17 #include <linux/sched/rt.h> 18 #include <linux/sched/deadline.h> 19 #include <trace/events/sched.h> 20 #include "trace.h" 21 22 static struct trace_array *wakeup_trace; 23 static int __read_mostly tracer_enabled; 24 25 static struct task_struct *wakeup_task; 26 static int wakeup_cpu; 27 static int wakeup_current_cpu; 28 static unsigned wakeup_prio = -1; 29 static bool wakeup_rt; 30 static bool wakeup_dl; 31 static bool tracing_dl; 32 33 static arch_spinlock_t wakeup_lock = 34 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; 35 36 static void wakeup_reset(struct trace_array *tr); 37 static void __wakeup_reset(struct trace_array *tr); 38 static int start_func_tracer(struct trace_array *tr, int graph); 39 static void stop_func_tracer(struct trace_array *tr, int graph); 40 41 static int save_flags; 42 43 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 44 # define is_graph(tr) ((tr)->trace_flags & TRACE_ITER_DISPLAY_GRAPH) 45 #else 46 # define is_graph(tr) false 47 #endif 48 49 #ifdef CONFIG_FUNCTION_TRACER 50 51 static bool function_enabled; 52 53 /* 54 * Prologue for the wakeup function tracers. 55 * 56 * Returns 1 if it is OK to continue, and preemption 57 * is disabled and data->disabled is incremented. 58 * 0 if the trace is to be ignored, and preemption 59 * is not disabled and data->disabled is 60 * kept the same. 61 * 62 * Note, this function is also used outside this ifdef but 63 * inside the #ifdef of the function graph tracer below. 64 * This is OK, since the function graph tracer is 65 * dependent on the function tracer. 66 */ 67 static int 68 func_prolog_preempt_disable(struct trace_array *tr, 69 struct trace_array_cpu **data, 70 unsigned int *trace_ctx) 71 { 72 long disabled; 73 int cpu; 74 75 if (likely(!wakeup_task)) 76 return 0; 77 78 *trace_ctx = tracing_gen_ctx(); 79 preempt_disable_notrace(); 80 81 cpu = raw_smp_processor_id(); 82 if (cpu != wakeup_current_cpu) 83 goto out_enable; 84 85 *data = per_cpu_ptr(tr->array_buffer.data, cpu); 86 disabled = atomic_inc_return(&(*data)->disabled); 87 if (unlikely(disabled != 1)) 88 goto out; 89 90 return 1; 91 92 out: 93 atomic_dec(&(*data)->disabled); 94 95 out_enable: 96 preempt_enable_notrace(); 97 return 0; 98 } 99 100 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 101 102 static int wakeup_display_graph(struct trace_array *tr, int set) 103 { 104 if (!(is_graph(tr) ^ set)) 105 return 0; 106 107 stop_func_tracer(tr, !set); 108 109 wakeup_reset(wakeup_trace); 110 tr->max_latency = 0; 111 112 return start_func_tracer(tr, set); 113 } 114 115 static int wakeup_graph_entry(struct ftrace_graph_ent *trace, 116 struct fgraph_ops *gops, 117 struct ftrace_regs *fregs) 118 { 119 struct trace_array *tr = wakeup_trace; 120 struct trace_array_cpu *data; 121 unsigned int trace_ctx; 122 u64 *calltime; 123 int ret = 0; 124 125 if (ftrace_graph_ignore_func(gops, trace)) 126 return 0; 127 /* 128 * Do not trace a function if it's filtered by set_graph_notrace. 129 * Make the index of ret stack negative to indicate that it should 130 * ignore further functions. But it needs its own ret stack entry 131 * to recover the original index in order to continue tracing after 132 * returning from the function. 133 */ 134 if (ftrace_graph_notrace_addr(trace->func)) 135 return 1; 136 137 if (!func_prolog_preempt_disable(tr, &data, &trace_ctx)) 138 return 0; 139 140 calltime = fgraph_reserve_data(gops->idx, sizeof(*calltime)); 141 if (!calltime) 142 return 0; 143 144 *calltime = trace_clock_local(); 145 146 ret = __trace_graph_entry(tr, trace, trace_ctx); 147 atomic_dec(&data->disabled); 148 preempt_enable_notrace(); 149 150 return ret; 151 } 152 153 static void wakeup_graph_return(struct ftrace_graph_ret *trace, 154 struct fgraph_ops *gops, 155 struct ftrace_regs *fregs) 156 { 157 struct trace_array *tr = wakeup_trace; 158 struct trace_array_cpu *data; 159 unsigned int trace_ctx; 160 u64 *calltime; 161 int size; 162 163 ftrace_graph_addr_finish(gops, trace); 164 165 if (!func_prolog_preempt_disable(tr, &data, &trace_ctx)) 166 return; 167 168 calltime = fgraph_retrieve_data(gops->idx, &size); 169 if (!calltime) 170 return; 171 trace->calltime = *calltime; 172 173 __trace_graph_return(tr, trace, trace_ctx); 174 atomic_dec(&data->disabled); 175 176 preempt_enable_notrace(); 177 return; 178 } 179 180 static struct fgraph_ops fgraph_wakeup_ops = { 181 .entryfunc = &wakeup_graph_entry, 182 .retfunc = &wakeup_graph_return, 183 }; 184 185 static void wakeup_trace_open(struct trace_iterator *iter) 186 { 187 if (is_graph(iter->tr)) 188 graph_trace_open(iter); 189 else 190 iter->private = NULL; 191 } 192 193 static void wakeup_trace_close(struct trace_iterator *iter) 194 { 195 if (iter->private) 196 graph_trace_close(iter); 197 } 198 199 #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_PROC | \ 200 TRACE_GRAPH_PRINT_CPU | \ 201 TRACE_GRAPH_PRINT_REL_TIME | \ 202 TRACE_GRAPH_PRINT_DURATION | \ 203 TRACE_GRAPH_PRINT_OVERHEAD | \ 204 TRACE_GRAPH_PRINT_IRQS) 205 206 static enum print_line_t wakeup_print_line(struct trace_iterator *iter) 207 { 208 /* 209 * In graph mode call the graph tracer output function, 210 * otherwise go with the TRACE_FN event handler 211 */ 212 if (is_graph(iter->tr)) 213 return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS); 214 215 return TRACE_TYPE_UNHANDLED; 216 } 217 218 static void wakeup_print_header(struct seq_file *s) 219 { 220 if (is_graph(wakeup_trace)) 221 print_graph_headers_flags(s, GRAPH_TRACER_FLAGS); 222 else 223 trace_default_header(s); 224 } 225 #endif /* else CONFIG_FUNCTION_GRAPH_TRACER */ 226 227 /* 228 * wakeup uses its own tracer function to keep the overhead down: 229 */ 230 static void 231 wakeup_tracer_call(unsigned long ip, unsigned long parent_ip, 232 struct ftrace_ops *op, struct ftrace_regs *fregs) 233 { 234 struct trace_array *tr = wakeup_trace; 235 struct trace_array_cpu *data; 236 unsigned long flags; 237 unsigned int trace_ctx; 238 239 if (!func_prolog_preempt_disable(tr, &data, &trace_ctx)) 240 return; 241 242 local_irq_save(flags); 243 trace_function(tr, ip, parent_ip, trace_ctx); 244 local_irq_restore(flags); 245 246 atomic_dec(&data->disabled); 247 preempt_enable_notrace(); 248 } 249 250 static int register_wakeup_function(struct trace_array *tr, int graph, int set) 251 { 252 int ret; 253 254 /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */ 255 if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION))) 256 return 0; 257 258 if (graph) 259 ret = register_ftrace_graph(&fgraph_wakeup_ops); 260 else 261 ret = register_ftrace_function(tr->ops); 262 263 if (!ret) 264 function_enabled = true; 265 266 return ret; 267 } 268 269 static void unregister_wakeup_function(struct trace_array *tr, int graph) 270 { 271 if (!function_enabled) 272 return; 273 274 if (graph) 275 unregister_ftrace_graph(&fgraph_wakeup_ops); 276 else 277 unregister_ftrace_function(tr->ops); 278 279 function_enabled = false; 280 } 281 282 static int wakeup_function_set(struct trace_array *tr, u32 mask, int set) 283 { 284 if (!(mask & TRACE_ITER_FUNCTION)) 285 return 0; 286 287 if (set) 288 register_wakeup_function(tr, is_graph(tr), 1); 289 else 290 unregister_wakeup_function(tr, is_graph(tr)); 291 return 1; 292 } 293 #else /* CONFIG_FUNCTION_TRACER */ 294 static int register_wakeup_function(struct trace_array *tr, int graph, int set) 295 { 296 return 0; 297 } 298 static void unregister_wakeup_function(struct trace_array *tr, int graph) { } 299 static int wakeup_function_set(struct trace_array *tr, u32 mask, int set) 300 { 301 return 0; 302 } 303 #endif /* else CONFIG_FUNCTION_TRACER */ 304 305 #ifndef CONFIG_FUNCTION_GRAPH_TRACER 306 static enum print_line_t wakeup_print_line(struct trace_iterator *iter) 307 { 308 return TRACE_TYPE_UNHANDLED; 309 } 310 311 static void wakeup_trace_open(struct trace_iterator *iter) { } 312 static void wakeup_trace_close(struct trace_iterator *iter) { } 313 314 static void wakeup_print_header(struct seq_file *s) 315 { 316 trace_default_header(s); 317 } 318 #endif /* !CONFIG_FUNCTION_GRAPH_TRACER */ 319 320 static void 321 __trace_function(struct trace_array *tr, 322 unsigned long ip, unsigned long parent_ip, 323 unsigned int trace_ctx) 324 { 325 if (is_graph(tr)) 326 trace_graph_function(tr, ip, parent_ip, trace_ctx); 327 else 328 trace_function(tr, ip, parent_ip, trace_ctx); 329 } 330 331 static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set) 332 { 333 struct tracer *tracer = tr->current_trace; 334 335 if (wakeup_function_set(tr, mask, set)) 336 return 0; 337 338 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 339 if (mask & TRACE_ITER_DISPLAY_GRAPH) 340 return wakeup_display_graph(tr, set); 341 #endif 342 343 return trace_keep_overwrite(tracer, mask, set); 344 } 345 346 static int start_func_tracer(struct trace_array *tr, int graph) 347 { 348 int ret; 349 350 ret = register_wakeup_function(tr, graph, 0); 351 352 if (!ret && tracing_is_enabled()) 353 tracer_enabled = 1; 354 else 355 tracer_enabled = 0; 356 357 return ret; 358 } 359 360 static void stop_func_tracer(struct trace_array *tr, int graph) 361 { 362 tracer_enabled = 0; 363 364 unregister_wakeup_function(tr, graph); 365 } 366 367 /* 368 * Should this new latency be reported/recorded? 369 */ 370 static bool report_latency(struct trace_array *tr, u64 delta) 371 { 372 if (tracing_thresh) { 373 if (delta < tracing_thresh) 374 return false; 375 } else { 376 if (delta <= tr->max_latency) 377 return false; 378 } 379 return true; 380 } 381 382 static void 383 probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu) 384 { 385 if (task != wakeup_task) 386 return; 387 388 wakeup_current_cpu = cpu; 389 } 390 391 static void 392 tracing_sched_switch_trace(struct trace_array *tr, 393 struct task_struct *prev, 394 struct task_struct *next, 395 unsigned int trace_ctx) 396 { 397 struct trace_buffer *buffer = tr->array_buffer.buffer; 398 struct ring_buffer_event *event; 399 struct ctx_switch_entry *entry; 400 401 event = trace_buffer_lock_reserve(buffer, TRACE_CTX, 402 sizeof(*entry), trace_ctx); 403 if (!event) 404 return; 405 entry = ring_buffer_event_data(event); 406 entry->prev_pid = prev->pid; 407 entry->prev_prio = prev->prio; 408 entry->prev_state = task_state_index(prev); 409 entry->next_pid = next->pid; 410 entry->next_prio = next->prio; 411 entry->next_state = task_state_index(next); 412 entry->next_cpu = task_cpu(next); 413 414 trace_buffer_unlock_commit(tr, buffer, event, trace_ctx); 415 } 416 417 static void 418 tracing_sched_wakeup_trace(struct trace_array *tr, 419 struct task_struct *wakee, 420 struct task_struct *curr, 421 unsigned int trace_ctx) 422 { 423 struct ring_buffer_event *event; 424 struct ctx_switch_entry *entry; 425 struct trace_buffer *buffer = tr->array_buffer.buffer; 426 427 event = trace_buffer_lock_reserve(buffer, TRACE_WAKE, 428 sizeof(*entry), trace_ctx); 429 if (!event) 430 return; 431 entry = ring_buffer_event_data(event); 432 entry->prev_pid = curr->pid; 433 entry->prev_prio = curr->prio; 434 entry->prev_state = task_state_index(curr); 435 entry->next_pid = wakee->pid; 436 entry->next_prio = wakee->prio; 437 entry->next_state = task_state_index(wakee); 438 entry->next_cpu = task_cpu(wakee); 439 440 trace_buffer_unlock_commit(tr, buffer, event, trace_ctx); 441 } 442 443 static void notrace 444 probe_wakeup_sched_switch(void *ignore, bool preempt, 445 struct task_struct *prev, struct task_struct *next, 446 unsigned int prev_state) 447 { 448 struct trace_array_cpu *data; 449 u64 T0, T1, delta; 450 unsigned long flags; 451 long disabled; 452 int cpu; 453 unsigned int trace_ctx; 454 455 tracing_record_cmdline(prev); 456 457 if (unlikely(!tracer_enabled)) 458 return; 459 460 /* 461 * When we start a new trace, we set wakeup_task to NULL 462 * and then set tracer_enabled = 1. We want to make sure 463 * that another CPU does not see the tracer_enabled = 1 464 * and the wakeup_task with an older task, that might 465 * actually be the same as next. 466 */ 467 smp_rmb(); 468 469 if (next != wakeup_task) 470 return; 471 472 /* disable local data, not wakeup_cpu data */ 473 cpu = raw_smp_processor_id(); 474 disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 475 if (likely(disabled != 1)) 476 goto out; 477 478 local_irq_save(flags); 479 trace_ctx = tracing_gen_ctx_flags(flags); 480 481 arch_spin_lock(&wakeup_lock); 482 483 /* We could race with grabbing wakeup_lock */ 484 if (unlikely(!tracer_enabled || next != wakeup_task)) 485 goto out_unlock; 486 487 /* The task we are waiting for is waking up */ 488 data = per_cpu_ptr(wakeup_trace->array_buffer.data, wakeup_cpu); 489 490 __trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, trace_ctx); 491 tracing_sched_switch_trace(wakeup_trace, prev, next, trace_ctx); 492 __trace_stack(wakeup_trace, trace_ctx, 0); 493 494 T0 = data->preempt_timestamp; 495 T1 = ftrace_now(cpu); 496 delta = T1-T0; 497 498 if (!report_latency(wakeup_trace, delta)) 499 goto out_unlock; 500 501 if (likely(!is_tracing_stopped())) { 502 wakeup_trace->max_latency = delta; 503 update_max_tr(wakeup_trace, wakeup_task, wakeup_cpu, NULL); 504 } 505 506 out_unlock: 507 __wakeup_reset(wakeup_trace); 508 arch_spin_unlock(&wakeup_lock); 509 local_irq_restore(flags); 510 out: 511 atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 512 } 513 514 static void __wakeup_reset(struct trace_array *tr) 515 { 516 wakeup_cpu = -1; 517 wakeup_prio = -1; 518 tracing_dl = false; 519 520 if (wakeup_task) 521 put_task_struct(wakeup_task); 522 523 wakeup_task = NULL; 524 } 525 526 static void wakeup_reset(struct trace_array *tr) 527 { 528 unsigned long flags; 529 530 tracing_reset_online_cpus(&tr->array_buffer); 531 532 local_irq_save(flags); 533 arch_spin_lock(&wakeup_lock); 534 __wakeup_reset(tr); 535 arch_spin_unlock(&wakeup_lock); 536 local_irq_restore(flags); 537 } 538 539 static void 540 probe_wakeup(void *ignore, struct task_struct *p) 541 { 542 struct trace_array_cpu *data; 543 int cpu = smp_processor_id(); 544 long disabled; 545 unsigned int trace_ctx; 546 547 if (likely(!tracer_enabled)) 548 return; 549 550 tracing_record_cmdline(p); 551 tracing_record_cmdline(current); 552 553 /* 554 * Semantic is like this: 555 * - wakeup tracer handles all tasks in the system, independently 556 * from their scheduling class; 557 * - wakeup_rt tracer handles tasks belonging to sched_dl and 558 * sched_rt class; 559 * - wakeup_dl handles tasks belonging to sched_dl class only. 560 */ 561 if (tracing_dl || (wakeup_dl && !dl_task(p)) || 562 (wakeup_rt && !rt_or_dl_task(p)) || 563 (!dl_task(p) && (p->prio >= wakeup_prio || p->prio >= current->prio))) 564 return; 565 566 disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 567 if (unlikely(disabled != 1)) 568 goto out; 569 570 trace_ctx = tracing_gen_ctx(); 571 572 /* interrupts should be off from try_to_wake_up */ 573 arch_spin_lock(&wakeup_lock); 574 575 /* check for races. */ 576 if (!tracer_enabled || tracing_dl || 577 (!dl_task(p) && p->prio >= wakeup_prio)) 578 goto out_locked; 579 580 /* reset the trace */ 581 __wakeup_reset(wakeup_trace); 582 583 wakeup_cpu = task_cpu(p); 584 wakeup_current_cpu = wakeup_cpu; 585 wakeup_prio = p->prio; 586 587 /* 588 * Once you start tracing a -deadline task, don't bother tracing 589 * another task until the first one wakes up. 590 */ 591 if (dl_task(p)) 592 tracing_dl = true; 593 else 594 tracing_dl = false; 595 596 wakeup_task = get_task_struct(p); 597 598 data = per_cpu_ptr(wakeup_trace->array_buffer.data, wakeup_cpu); 599 data->preempt_timestamp = ftrace_now(cpu); 600 tracing_sched_wakeup_trace(wakeup_trace, p, current, trace_ctx); 601 __trace_stack(wakeup_trace, trace_ctx, 0); 602 603 /* 604 * We must be careful in using CALLER_ADDR2. But since wake_up 605 * is not called by an assembly function (where as schedule is) 606 * it should be safe to use it here. 607 */ 608 __trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, trace_ctx); 609 610 out_locked: 611 arch_spin_unlock(&wakeup_lock); 612 out: 613 atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 614 } 615 616 static void start_wakeup_tracer(struct trace_array *tr) 617 { 618 int ret; 619 620 ret = register_trace_sched_wakeup(probe_wakeup, NULL); 621 if (ret) { 622 pr_info("wakeup trace: Couldn't activate tracepoint" 623 " probe to kernel_sched_wakeup\n"); 624 return; 625 } 626 627 ret = register_trace_sched_wakeup_new(probe_wakeup, NULL); 628 if (ret) { 629 pr_info("wakeup trace: Couldn't activate tracepoint" 630 " probe to kernel_sched_wakeup_new\n"); 631 goto fail_deprobe; 632 } 633 634 ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL); 635 if (ret) { 636 pr_info("sched trace: Couldn't activate tracepoint" 637 " probe to kernel_sched_switch\n"); 638 goto fail_deprobe_wake_new; 639 } 640 641 ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL); 642 if (ret) { 643 pr_info("wakeup trace: Couldn't activate tracepoint" 644 " probe to kernel_sched_migrate_task\n"); 645 goto fail_deprobe_sched_switch; 646 } 647 648 wakeup_reset(tr); 649 650 /* 651 * Don't let the tracer_enabled = 1 show up before 652 * the wakeup_task is reset. This may be overkill since 653 * wakeup_reset does a spin_unlock after setting the 654 * wakeup_task to NULL, but I want to be safe. 655 * This is a slow path anyway. 656 */ 657 smp_wmb(); 658 659 if (start_func_tracer(tr, is_graph(tr))) 660 printk(KERN_ERR "failed to start wakeup tracer\n"); 661 662 return; 663 fail_deprobe_sched_switch: 664 unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL); 665 fail_deprobe_wake_new: 666 unregister_trace_sched_wakeup_new(probe_wakeup, NULL); 667 fail_deprobe: 668 unregister_trace_sched_wakeup(probe_wakeup, NULL); 669 } 670 671 static void stop_wakeup_tracer(struct trace_array *tr) 672 { 673 tracer_enabled = 0; 674 stop_func_tracer(tr, is_graph(tr)); 675 unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL); 676 unregister_trace_sched_wakeup_new(probe_wakeup, NULL); 677 unregister_trace_sched_wakeup(probe_wakeup, NULL); 678 unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL); 679 } 680 681 static bool wakeup_busy; 682 683 static int __wakeup_tracer_init(struct trace_array *tr) 684 { 685 save_flags = tr->trace_flags; 686 687 /* non overwrite screws up the latency tracers */ 688 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1); 689 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1); 690 691 tr->max_latency = 0; 692 wakeup_trace = tr; 693 ftrace_init_array_ops(tr, wakeup_tracer_call); 694 start_wakeup_tracer(tr); 695 696 wakeup_busy = true; 697 return 0; 698 } 699 700 static int wakeup_tracer_init(struct trace_array *tr) 701 { 702 if (wakeup_busy) 703 return -EBUSY; 704 705 wakeup_dl = false; 706 wakeup_rt = false; 707 return __wakeup_tracer_init(tr); 708 } 709 710 static int wakeup_rt_tracer_init(struct trace_array *tr) 711 { 712 if (wakeup_busy) 713 return -EBUSY; 714 715 wakeup_dl = false; 716 wakeup_rt = true; 717 return __wakeup_tracer_init(tr); 718 } 719 720 static int wakeup_dl_tracer_init(struct trace_array *tr) 721 { 722 if (wakeup_busy) 723 return -EBUSY; 724 725 wakeup_dl = true; 726 wakeup_rt = false; 727 return __wakeup_tracer_init(tr); 728 } 729 730 static void wakeup_tracer_reset(struct trace_array *tr) 731 { 732 int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; 733 int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; 734 735 stop_wakeup_tracer(tr); 736 /* make sure we put back any tasks we are tracing */ 737 wakeup_reset(tr); 738 739 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag); 740 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag); 741 ftrace_reset_array_ops(tr); 742 wakeup_busy = false; 743 } 744 745 static void wakeup_tracer_start(struct trace_array *tr) 746 { 747 wakeup_reset(tr); 748 tracer_enabled = 1; 749 } 750 751 static void wakeup_tracer_stop(struct trace_array *tr) 752 { 753 tracer_enabled = 0; 754 } 755 756 static struct tracer wakeup_tracer __read_mostly = 757 { 758 .name = "wakeup", 759 .init = wakeup_tracer_init, 760 .reset = wakeup_tracer_reset, 761 .start = wakeup_tracer_start, 762 .stop = wakeup_tracer_stop, 763 .print_max = true, 764 .print_header = wakeup_print_header, 765 .print_line = wakeup_print_line, 766 .flag_changed = wakeup_flag_changed, 767 #ifdef CONFIG_FTRACE_SELFTEST 768 .selftest = trace_selftest_startup_wakeup, 769 #endif 770 .open = wakeup_trace_open, 771 .close = wakeup_trace_close, 772 .allow_instances = true, 773 .use_max_tr = true, 774 }; 775 776 static struct tracer wakeup_rt_tracer __read_mostly = 777 { 778 .name = "wakeup_rt", 779 .init = wakeup_rt_tracer_init, 780 .reset = wakeup_tracer_reset, 781 .start = wakeup_tracer_start, 782 .stop = wakeup_tracer_stop, 783 .print_max = true, 784 .print_header = wakeup_print_header, 785 .print_line = wakeup_print_line, 786 .flag_changed = wakeup_flag_changed, 787 #ifdef CONFIG_FTRACE_SELFTEST 788 .selftest = trace_selftest_startup_wakeup, 789 #endif 790 .open = wakeup_trace_open, 791 .close = wakeup_trace_close, 792 .allow_instances = true, 793 .use_max_tr = true, 794 }; 795 796 static struct tracer wakeup_dl_tracer __read_mostly = 797 { 798 .name = "wakeup_dl", 799 .init = wakeup_dl_tracer_init, 800 .reset = wakeup_tracer_reset, 801 .start = wakeup_tracer_start, 802 .stop = wakeup_tracer_stop, 803 .print_max = true, 804 .print_header = wakeup_print_header, 805 .print_line = wakeup_print_line, 806 .flag_changed = wakeup_flag_changed, 807 #ifdef CONFIG_FTRACE_SELFTEST 808 .selftest = trace_selftest_startup_wakeup, 809 #endif 810 .open = wakeup_trace_open, 811 .close = wakeup_trace_close, 812 .allow_instances = true, 813 .use_max_tr = true, 814 }; 815 816 __init static int init_wakeup_tracer(void) 817 { 818 int ret; 819 820 ret = register_tracer(&wakeup_tracer); 821 if (ret) 822 return ret; 823 824 ret = register_tracer(&wakeup_rt_tracer); 825 if (ret) 826 return ret; 827 828 ret = register_tracer(&wakeup_dl_tracer); 829 if (ret) 830 return ret; 831 832 return 0; 833 } 834 core_initcall(init_wakeup_tracer); 835