In order to investigate reason of idle, it needs to keep the callchains when entering to idle. This can be identified sched_switch event having next_pid as 0.
Signed-off-by: Namhyung Kim <namhy...@kernel.org> --- tools/perf/builtin-sched.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index d3ee814ce77f..058cb549cf3e 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -200,6 +200,7 @@ struct perf_sched { /* options for timehist command */ bool summary; bool summary_only; + bool idle_hist; bool show_callchain; unsigned int max_stack; bool show_cpu_visual; @@ -2099,6 +2100,29 @@ static struct thread *get_idle_thread(int cpu) return idle_threads[cpu]; } +static void save_idle_callchain(struct thread *thread, + struct perf_sample *sample) +{ + struct thread *idle; + struct idle_thread_runtime *itr; + + if (!symbol_conf.use_callchain || sample->callchain == NULL) + return; + + idle = get_idle_thread(sample->cpu); + if (idle == NULL) { + pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); + return; + } + + itr = thread__priv(idle); + if (itr == NULL) + return; + + itr->last_thread = thread; + callchain_cursor__copy(&itr->cursor, &callchain_cursor); +} + /* * handle runtime stats saved per thread */ @@ -2152,6 +2176,11 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, } save_task_callchain(sched, sample, evsel, machine); + if (sched->idle_hist) { + /* copy task callchain when entering to idle */ + if (perf_evsel__intval(evsel, sample, "next_pid") == 0) + save_idle_callchain(thread, sample); + } } return thread; -- 2.10.1