lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1389469379-13340-8-git-send-email-andi@firstfloor.org>
Date:	Sat, 11 Jan 2014 11:42:57 -0800
From:	Andi Kleen <andi@...stfloor.org>
To:	acme@...radead.org
Cc:	jolsa@...hat.com, namhyung@...nel.org, mingo@...nel.org,
	dsahern@...il.com, fweisbec@...il.com, adrian.hunter@...el.com,
	linux-kernel@...r.kernel.org, Andi Kleen <ak@...ux.intel.com>
Subject: [PATCH 7/9] perf, tools: Add overlap detection for report branch-call-stack mode

From: Andi Kleen <ak@...ux.intel.com>

Add a simple heuristic to detect overlap of LBR entries and the call
stack when in lbr-as-callgraph mode. The return address in the
normal callstack is one off compared to the from entry in the
branch stack. Handle this with a simple "assume call instruction
is not longer than 8 bytes" heuristic. With that we can remove
any redundant call in the callstack that is already in the branch
stack.

Signed-off-by: Andi Kleen <ak@...ux.intel.com>
---
 tools/perf/util/machine.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 853639c..1f167fe 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1349,6 +1349,7 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 	int chain_nr = min(max_stack, (int)chain->nr);
 	int i;
 	int err;
+	int first_call = 0;
 
 	callchain_cursor_reset(&callchain_cursor);
 
@@ -1362,8 +1363,6 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 	 * Limitations for now:
 	 * - No extra filters
 	 * - No annotations (should annotate somehow)
-	 * - When the sample is near the beginning of the function
- 	 *   we may overlap with the real callstack. 
 	 */
 
 	if (branch->nr > PERF_MAX_BRANCH_DEPTH) {
@@ -1372,13 +1371,23 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 	}
 
 	if (callchain_param.branch_callstack) {
-		int nr = min(max_stack, branch->nr);
+		int nr = min(max_stack, (int)branch->nr);
 		struct branch_entry be[nr];
 
 		for (i = 0; i < nr; i++) { 
-			if (callchain_param.order == ORDER_CALLEE)
+			if (callchain_param.order == ORDER_CALLEE) {
 				be[i] = branch->entries[i];
-			else
+				/* 
+				 * Check for overlap into the callchain.
+				 * The return address is one off compared to
+				 * the branch entry. To adjust for this 
+				 * assume the calling instruction is not longer
+				 * than 8 bytes.
+				 */
+				if (be[i].from < chain->ips[first_call] &&
+				    be[i].from >= chain->ips[first_call] - 8)
+					first_call++;
+			} else
 				be[i] = branch->entries[branch->nr - i - 1];
 		}
 
@@ -1405,7 +1414,7 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 		return 0;
 	}
 
-	for (i = 0; i < chain_nr; i++) {
+	for (i = first_call; i < chain_nr; i++) {
 		u64 ip;
 
 		if (callchain_param.order == ORDER_CALLEE)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ