From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932502AbcLHOt7 (ORCPT ); Thu, 8 Dec 2016 09:49:59 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36729 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932429AbcLHOtV (ORCPT ); Thu, 8 Dec 2016 09:49:21 -0500 From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ingo Molnar , Peter Zijlstra , Jiri Olsa , LKML , David Ahern , Andi Kleen , Minchan Kim Subject: [PATCH v2 3/6] perf sched timehist: Save callchain when entering idle Date: Thu, 8 Dec 2016 23:47:52 +0900 Message-Id: <20161208144755.16673-4-namhyung@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161208144755.16673-1-namhyung@kernel.org> References: <20161208144755.16673-1-namhyung@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 6f0687dd392d..4c5c58ce8958 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; @@ -2101,6 +2102,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 */ @@ -2154,6 +2178,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