ANDROID: Fix invalid caller output in trace_sched_blocked_reason
I encountered an issue where Perfetto sometimes fails to display the blocked function when a thread enters the D state. The problem arises from the caller value in the trace_sched_blocked_reason, and I observed the following outputs while using bpftrace: bpftrace -e 't:sched:sched_blocked_reason /args.caller > 0 && args.caller < 0xFFFFFFFF/ {@[args.caller]=count();}' Attaching 1 probe... ^C @[0x26a8]: 1 @[0x188]: 1 @[0x3]: 1 @[0xf833]: 1 @[0x4]: 10 @[0x9]: 14 @[0x1]: 23 When try_to_wake_up is waking a thread executing __schedule, it can trigger the trace_sched_blocked_reason. This function attempts to obtain the thread's backtrace using __get_wchan. However, __get_wchan requires the thread to be blocking in cpu_switch_to, which is not always the case. | set_current_state(TASK_UNINTERRUPTIBLE) | __schedule | deactivate_task | p->on_rq = 0 | dequeue_task try_to_wake_up | pick_next_task ttwu_state_match(TASK_UNINTERRUPTIBLE) | context_switch p->on_rq == 0 | prepare_task_switch p->__state & TASK_UNINTERRUPTIBLE | switch_mm trace_sched_blocked_reason | __switch_to __get_wchan | ...... unwind_init_from_task | cpu_switch_to state->fp = thread_saved_fp(p) | mov x10, #THREAD_CPU_CONTEXT // Load an invalid fp | add x8, x0, x10 | ...... | stp fp, x9, [x8], #16 | str lr, [x8] | ...... | ret To resolve this, we can move the trace_sched_blocked_reason call inside __schedule to ensure accurate caller information. Fixes: 44447dec ("ANDROID: sched: move blocked reason trace point to cover all class") Change-Id: Ib63839107dbe835a52f191cceef9452d13e18785 Signed-off-by:pengdonglin <pengdonglin@xiaomi.com>
Loading
Please register or sign in to comment