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,
	"David S. Miller" <davem@davemloft.net>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Souvik Banerjee <souvik1997@gmail.com>,
	Wang Nan <wangnan0@huawei.com>,
	stable@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 14/28] perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc}
Date: Wed, 31 Oct 2018 13:44:54 -0300	[thread overview]
Message-ID: <20181031164508.4784-15-acme@kernel.org> (raw)
In-Reply-To: <20181031164508.4784-1-acme@kernel.org>

From: "David S. Miller" <davem@davemloft.net>

When processing using 'perf report -g caller', which is the default, we
ended up reverting the callchain entries received from the kernel, but
simply reverting throws away the information that tells that from a
point onwards the addresses are for userspace, kernel, guest kernel,
guest user, hypervisor.

The idea is that if we are walking backwards, for each cluster of
non-cpumode entries we have to first scan backwards for the next one and
use that for the cluster.

This seems silly and more expensive than it needs to be but it is enough
for a initial fix.

The code here is really complicated because it is intimately intertwined
with the lbr and branch handling, as well as this callchain order,
further fixes will be needed to properly take into account the cpumode
in those cases.

Another problem with ORDER_CALLER is that the NULL "0" IP that is at the
end of most callchains shows up at the top of the histogram because
every callchain contains it and with ORDER_CALLER it is the first entry.

Signed-off-by: David S. Miller <davem@davemloft.net>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Souvik Banerjee <souvik1997@gmail.com>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: stable@vger.kernel.org # 4.19
Link: https://lkml.kernel.org/n/tip-2wt3ayp6j2y2f2xowixa8y6y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 111ae858cbcb..8ee8ab39d8ac 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2140,6 +2140,27 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
 	return 0;
 }
 
+static int find_prev_cpumode(struct ip_callchain *chain, struct thread *thread,
+			     struct callchain_cursor *cursor,
+			     struct symbol **parent,
+			     struct addr_location *root_al,
+			     u8 *cpumode, int ent)
+{
+	int err = 0;
+
+	while (--ent >= 0) {
+		u64 ip = chain->ips[ent];
+
+		if (ip >= PERF_CONTEXT_MAX) {
+			err = add_callchain_ip(thread, cursor, parent,
+					       root_al, cpumode, ip,
+					       false, NULL, NULL, 0);
+			break;
+		}
+	}
+	return err;
+}
+
 static int thread__resolve_callchain_sample(struct thread *thread,
 					    struct callchain_cursor *cursor,
 					    struct perf_evsel *evsel,
@@ -2246,6 +2267,12 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 	}
 
 check_calls:
+	if (callchain_param.order != ORDER_CALLEE) {
+		err = find_prev_cpumode(chain, thread, cursor, parent, root_al,
+					&cpumode, chain->nr - first_call);
+		if (err)
+			return (err < 0) ? err : 0;
+	}
 	for (i = first_call, nr_entries = 0;
 	     i < chain_nr && nr_entries < max_stack; i++) {
 		u64 ip;
@@ -2260,9 +2287,15 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 			continue;
 #endif
 		ip = chain->ips[j];
-
 		if (ip < PERF_CONTEXT_MAX)
                        ++nr_entries;
+		else if (callchain_param.order != ORDER_CALLEE) {
+			err = find_prev_cpumode(chain, thread, cursor, parent,
+						root_al, &cpumode, j);
+			if (err)
+				return (err < 0) ? err : 0;
+			continue;
+		}
 
 		err = add_callchain_ip(thread, cursor, parent,
 				       root_al, &cpumode, ip,
-- 
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 ` Arnaldo Carvalho de Melo [this message]
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 ` [PATCH 27/28] perf intel-pt: Insert callchain context into synthesized callchains Arnaldo Carvalho de Melo
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-15-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=souvik1997@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=wangnan0@huawei.com \
    --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).