linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 11/25] perf intel-pt: Add LBR information to synthesized PEBS sample
Date: Fri, 21 Jun 2019 14:38:17 -0300	[thread overview]
Message-ID: <20190621173831.13780-12-acme@kernel.org> (raw)
In-Reply-To: <20190621173831.13780-1-acme@kernel.org>

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

Add LBR information from PEBS data in the Intel PT trace to the
synthesized PEBS sample.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190610072803.10456-10-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 72 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index f83dd10bb7d0..db00c13dc36f 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1628,6 +1628,58 @@ static void intel_pt_add_xmm(struct regs_dump *intr_regs, u64 *pos,
 	}
 }
 
+#define LBR_INFO_MISPRED	(1ULL << 63)
+#define LBR_INFO_IN_TX		(1ULL << 62)
+#define LBR_INFO_ABORT		(1ULL << 61)
+#define LBR_INFO_CYCLES		0xffff
+
+/* Refer kernel's intel_pmu_store_pebs_lbrs() */
+static u64 intel_pt_lbr_flags(u64 info)
+{
+	union {
+		struct branch_flags flags;
+		u64 result;
+	} u = {
+		.flags = {
+			.mispred	= !!(info & LBR_INFO_MISPRED),
+			.predicted	= !(info & LBR_INFO_MISPRED),
+			.in_tx		= !!(info & LBR_INFO_IN_TX),
+			.abort		= !!(info & LBR_INFO_ABORT),
+			.cycles		= info & LBR_INFO_CYCLES,
+		}
+	};
+
+	return u.result;
+}
+
+static void intel_pt_add_lbrs(struct branch_stack *br_stack,
+			      const struct intel_pt_blk_items *items)
+{
+	u64 *to;
+	int i;
+
+	br_stack->nr = 0;
+
+	to = &br_stack->entries[0].from;
+
+	for (i = INTEL_PT_LBR_0_POS; i <= INTEL_PT_LBR_2_POS; i++) {
+		u32 mask = items->mask[i];
+		const u64 *from = items->val[i];
+
+		for (; mask; mask >>= 3, from += 3) {
+			if ((mask & 7) == 7) {
+				*to++ = from[0];
+				*to++ = from[1];
+				*to++ = intel_pt_lbr_flags(from[2]);
+				br_stack->nr += 1;
+			}
+		}
+	}
+}
+
+/* INTEL_PT_LBR_0, INTEL_PT_LBR_1 and INTEL_PT_LBR_2 */
+#define LBRS_MAX (INTEL_PT_BLK_ITEM_ID_CNT * 3)
+
 static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)
 {
 	const struct intel_pt_blk_items *items = &ptq->state->items;
@@ -1694,6 +1746,26 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)
 		intel_pt_add_xmm(&sample.intr_regs, pos, items, regs_mask);
 	}
 
+	if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
+		struct {
+			struct branch_stack br_stack;
+			struct branch_entry entries[LBRS_MAX];
+		} br;
+
+		if (items->mask[INTEL_PT_LBR_0_POS] ||
+		    items->mask[INTEL_PT_LBR_1_POS] ||
+		    items->mask[INTEL_PT_LBR_2_POS]) {
+			intel_pt_add_lbrs(&br.br_stack, items);
+			sample.branch_stack = &br.br_stack;
+		} else if (pt->synth_opts.last_branch) {
+			intel_pt_copy_last_branch_rb(ptq);
+			sample.branch_stack = ptq->last_branch;
+		} else {
+			br.br_stack.nr = 0;
+			sample.branch_stack = &br.br_stack;
+		}
+	}
+
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample, sample_type);
 }
 
-- 
2.20.1

  parent reply	other threads:[~2019-06-21 17:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-21 17:38 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 01/25] perf tests arm64: Compile tests unconditionally Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 02/25] perf: cs-etm: Optimize option setup for CPU-wide sessions Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 03/25] perf intel-pt: Add new packets for PEBS via PT Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 04/25] perf intel-pt: Add Intel PT packet decoder test Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 05/25] perf intel-pt: Add decoder support for PEBS via PT Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 06/25] perf intel-pt: Prepare to synthesize PEBS samples Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 07/25] perf intel-pt: Factor out common sample preparation for re-use Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 08/25] perf intel-pt: Synthesize PEBS sample basic information Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 09/25] perf intel-pt: Add gp registers to synthesized PEBS sample Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 10/25] perf intel-pt: Add XMM " Arnaldo Carvalho de Melo
2019-06-21 17:38 ` Arnaldo Carvalho de Melo [this message]
2019-06-21 17:38 ` [PATCH 12/25] perf intel-pt: Add memory information " Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 13/25] perf intel-pt: Add callchain " Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 14/25] tools build: Check if gettid() is available before providing helper Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 15/25] perf trace: Fix exclusion of not available syscall names from selector list Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 16/25] perf trace: Streamline validation of select syscall names list Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 17/25] tools build feature tests: Add missing SPDX headers Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 18/25] perf " Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 19/25] perf pmu: Fix uncore PMU alias list for ARM64 Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 20/25] perf trace: Fixup pointer arithmetic when consuming augmented syscall args Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 21/25] perf evsel: Make perf_evsel__name() accept a NULL argument Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 22/25] perf tools: Don't hardcode host include path for libslang Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 23/25] tools build: Add test to check if slang.h is in /usr/include/slang/ Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 24/25] perf build: Handle slang being in /usr/include and " Arnaldo Carvalho de Melo
2019-06-21 17:38 ` [PATCH 25/25] tools build: Fix the zstd test in the test-all.c common case feature test Arnaldo Carvalho de Melo
2019-06-22  6:28 ` [GIT PULL] perf/core 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=20190621173831.13780-12-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --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).