linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	"David S . Miller" <davem@davemloft.net>,
	Leo Yan <leo.yan@linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	stable@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 27/28] perf intel-pt: Insert callchain context into synthesized callchains
Date: Wed, 31 Oct 2018 13:45:07 -0300	[thread overview]
Message-ID: <20181031164508.4784-28-acme@kernel.org> (raw)
In-Reply-To: <20181031164508.4784-1-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

In the absence of a fallback, callchains must encode also the callchain
context. Do that now there is no fallback.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: stable@vger.kernel.org # 4.19
Link: http://lkml.kernel.org/r/100ea2ec-ed14-b56d-d810-e0a6d2f4b069@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c     |  6 ++++--
 tools/perf/util/thread-stack.c | 44 +++++++++++++++++++++++++++++++++---------
 tools/perf/util/thread-stack.h |  2 +-
 3 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index ffa385a029b3..60732213d16a 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -759,7 +759,8 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 	if (pt->synth_opts.callchain) {
 		size_t sz = sizeof(struct ip_callchain);
 
-		sz += pt->synth_opts.callchain_sz * sizeof(u64);
+		/* Add 1 to callchain_sz for callchain context */
+		sz += (pt->synth_opts.callchain_sz + 1) * sizeof(u64);
 		ptq->chain = zalloc(sz);
 		if (!ptq->chain)
 			goto out_free;
@@ -1160,7 +1161,8 @@ static void intel_pt_prep_sample(struct intel_pt *pt,
 
 	if (pt->synth_opts.callchain) {
 		thread_stack__sample(ptq->thread, ptq->chain,
-				     pt->synth_opts.callchain_sz, sample->ip);
+				     pt->synth_opts.callchain_sz + 1,
+				     sample->ip, pt->kernel_start);
 		sample->callchain = ptq->chain;
 	}
 
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index c091635bf7dc..61a4286a74dc 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -310,20 +310,46 @@ void thread_stack__free(struct thread *thread)
 	}
 }
 
+static inline u64 callchain_context(u64 ip, u64 kernel_start)
+{
+	return ip < kernel_start ? PERF_CONTEXT_USER : PERF_CONTEXT_KERNEL;
+}
+
 void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
-			  size_t sz, u64 ip)
+			  size_t sz, u64 ip, u64 kernel_start)
 {
-	size_t i;
+	u64 context = callchain_context(ip, kernel_start);
+	u64 last_context;
+	size_t i, j;
 
-	if (!thread || !thread->ts)
-		chain->nr = 1;
-	else
-		chain->nr = min(sz, thread->ts->cnt + 1);
+	if (sz < 2) {
+		chain->nr = 0;
+		return;
+	}
 
-	chain->ips[0] = ip;
+	chain->ips[0] = context;
+	chain->ips[1] = ip;
+
+	if (!thread || !thread->ts) {
+		chain->nr = 2;
+		return;
+	}
+
+	last_context = context;
+
+	for (i = 2, j = 1; i < sz && j <= thread->ts->cnt; i++, j++) {
+		ip = thread->ts->stack[thread->ts->cnt - j].ret_addr;
+		context = callchain_context(ip, kernel_start);
+		if (context != last_context) {
+			if (i >= sz - 1)
+				break;
+			chain->ips[i++] = context;
+			last_context = context;
+		}
+		chain->ips[i] = ip;
+	}
 
-	for (i = 1; i < chain->nr; i++)
-		chain->ips[i] = thread->ts->stack[thread->ts->cnt - i].ret_addr;
+	chain->nr = i;
 }
 
 struct call_return_processor *
diff --git a/tools/perf/util/thread-stack.h b/tools/perf/util/thread-stack.h
index b7e41c4ebfdd..f97c00a8c251 100644
--- a/tools/perf/util/thread-stack.h
+++ b/tools/perf/util/thread-stack.h
@@ -84,7 +84,7 @@ int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
 			u64 to_ip, u16 insn_len, u64 trace_nr);
 void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr);
 void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
-			  size_t sz, u64 ip);
+			  size_t sz, u64 ip, u64 kernel_start);
 int thread_stack__flush(struct thread *thread);
 void thread_stack__free(struct thread *thread);
 size_t thread_stack__depth(struct thread *thread);
-- 
2.14.4


  parent reply	other threads:[~2018-10-31 16:46 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31 16:44 [GIT PULL 00/24] perf/urgent improvements and fixes Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 01/28] tools include uapi: Grab a copy of linux/fs.h Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 02/28] perf beauty: Add a generator for MS_ mount/umount's flag constants Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 03/28] perf beauty: Switch from GPL v2.0 to LGPL v2.1 Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 04/28] perf beauty: Introduce strarray__scnprintf_flags() Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 05/28] perf trace beauty: Allow syscalls to mask an argument before considering it Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 06/28] perf trace beauty: Beautify mount/umount's 'flags' argument Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 07/28] perf trace: Consider syscall aliases too Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 08/28] perf trace: Beautify the umount's 'name' argument Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 09/28] perf trace: Beautify mount's first pathname arg Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 10/28] perf top: Allow disabling the overwrite mode Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 11/28] perf top: Do not use overwrite mode by default Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 12/28] perf unwind: Take pgoff into account when reporting elf to libdwfl Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 13/28] perf cs-etm: Correct CPU mode for samples Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 14/28] perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc} Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 15/28] tools include uapi: Update linux/fs.h copy Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 16/28] tools arch uapi: Update asm-generic/unistd.h and arm64 unistd.h copies Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 17/28] tools include uapi: Update asound.h copy Arnaldo Carvalho de Melo
2018-10-31 17:00   ` Takashi Iwai
2018-10-31 17:27     ` Joe Perches
2018-10-31 18:32       ` Takashi Iwai
2018-10-31 19:29       ` Arnaldo Carvalho de Melo
2018-11-01 11:54         ` Takashi Sakamoto
2018-11-01 13:04           ` Arnaldo Carvalho de Melo
2018-11-01 13:57             ` Takashi Sakamoto
2018-10-31 19:28     ` Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 18/28] perf beauty: Add a generator for MAP_ mmap's flag constants Arnaldo Carvalho de Melo
2018-10-31 16:44 ` [PATCH 19/28] perf beauty: Wire up the mmap flags table generator to the Makefile Arnaldo Carvalho de Melo
2018-11-05 15:44   ` Guenter Roeck
2018-11-05 17:11     ` Arnaldo Carvalho de Melo
2018-11-05 18:46       ` Arnaldo Carvalho de Melo
2018-11-05 19:13         ` Arnaldo Carvalho de Melo
2018-11-05 21:18           ` Guenter Roeck
2018-11-06 19:18         ` [tip:perf/urgent] perf beauty: Use SRCARCH, ARCH=x86_64 must map to "x86" to find the headers tip-bot for Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 20/28] perf trace beauty: Use the mmap flags table generated from headers Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 21/28] tools include uapi: Update linux/mmap.h copy Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 22/28] tools headers: Sync the various kvm.h header copies Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 23/28] tools headers uapi: Update linux/netlink.h header copy Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 24/28] tools headers uapi: Update linux/if_link.h " Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 25/28] perf top: Start display thread earlier Arnaldo Carvalho de Melo
2018-10-31 16:45 ` [PATCH 26/28] perf tools: Don't clone maps from parent when synthesizing forks Arnaldo Carvalho de Melo
2018-10-31 16:45 ` Arnaldo Carvalho de Melo [this message]
2018-10-31 16:45 ` [PATCH 28/28] perf intel-pt/bts: Calculate cpumode for synthesized samples Arnaldo Carvalho de Melo
2018-10-31 21:56 ` [GIT PULL 00/24] perf/urgent improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181031164508.4784-28-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).