From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752294AbcLFDlm (ORCPT ); Mon, 5 Dec 2016 22:41:42 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33641 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752215AbcLFDli (ORCPT ); Mon, 5 Dec 2016 22:41:38 -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 07/10] perf sched timehist: Save callchain when entering idle Date: Tue, 6 Dec 2016 12:40:07 +0900 Message-Id: <20161206034010.6499-8-namhyung@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161206034010.6499-1-namhyung@kernel.org> References: <20161206034010.6499-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 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