All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sandipan Das <sandipan.das@amd.com>
To: <linux-kernel@vger.kernel.org>,
	<linux-perf-users@vger.kernel.org>, <x86@kernel.org>
Cc: <peterz@infradead.org>, <bp@alien8.de>, <acme@kernel.org>,
	<namhyung@kernel.org>, <jolsa@kernel.org>, <tglx@linutronix.de>,
	<mingo@redhat.com>, <mark.rutland@arm.com>,
	<alexander.shishkin@linux.intel.com>,
	<dave.hansen@linux.intel.com>, <like.xu.linux@gmail.com>,
	<eranian@google.com>, <ananth.narayan@amd.com>,
	<ravi.bangoria@amd.com>, <santosh.shukla@amd.com>,
	<sandipan.das@amd.com>
Subject: [PATCH 13/13] perf/x86/amd/lbr: Add LbrExtV2 branch speculation info support
Date: Thu, 11 Aug 2022 18:00:01 +0530	[thread overview]
Message-ID: <ddc02f6320464cad0e3ff5bdb2314531568a91bc.1660211399.git.sandipan.das@amd.com> (raw)
In-Reply-To: <cover.1660211399.git.sandipan.das@amd.com>

Provide branch speculation information captured via AMD Last Branch Record
Extension Version 2 (LbrExtV2) by setting the speculation info in branch
records. The info is based on the "valid" and "spec" bits in the Branch To
registers.

Suggested-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
---
 arch/x86/events/amd/lbr.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c
index 5fa985cd44cb..3fd316b6adda 100644
--- a/arch/x86/events/amd/lbr.c
+++ b/arch/x86/events/amd/lbr.c
@@ -146,12 +146,19 @@ static void amd_pmu_lbr_filter(void)
 	}
 }
 
+static const int lbr_spec_map[PERF_BR_SPEC_MAX] = {
+	PERF_BR_SPEC_NA,
+	PERF_BR_SPEC_WRONG_PATH,
+	PERF_BR_NON_SPEC_CORRECT_PATH,
+	PERF_BR_SPEC_CORRECT_PATH,
+};
+
 void amd_pmu_lbr_read(void)
 {
 	struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
 	struct perf_branch_entry *br = cpuc->lbr_entries;
 	struct branch_entry entry;
-	int out = 0, i;
+	int out = 0, idx, i;
 
 	if (!cpuc->lbr_users)
 		return;
@@ -160,8 +167,11 @@ void amd_pmu_lbr_read(void)
 		entry.from.full	= amd_pmu_lbr_get_from(i);
 		entry.to.full	= amd_pmu_lbr_get_to(i);
 
-		/* Check if a branch has been logged */
-		if (!entry.to.split.valid)
+		/*
+		 * Check if a branch has been logged; if valid = 0, spec = 0
+		 * then no branch was recorded
+		 */
+		if (!entry.to.split.valid && !entry.to.split.spec)
 			continue;
 
 		perf_clear_branch_entry_bitfields(br + out);
@@ -170,6 +180,25 @@ void amd_pmu_lbr_read(void)
 		br[out].to	= sign_ext_branch_ip(entry.to.split.ip);
 		br[out].mispred	= entry.from.split.mispredict;
 		br[out].predicted = !br[out].mispred;
+
+		/*
+		 * Set branch speculation information using the status of
+		 * the valid and spec bits.
+		 *
+		 * When valid = 0, spec = 0, no branch was recorded and the
+		 * entry is discarded as seen above.
+		 *
+		 * When valid = 0, spec = 1, the recorded branch was
+		 * speculative but took the wrong path.
+		 *
+		 * When valid = 1, spec = 0, the recorded branch was
+		 * non-speculative but took the correct path.
+		 *
+		 * When valid = 1, spec = 1, the recorded branch was
+		 * speculative and took the correct path
+		 */
+		idx = (entry.to.split.valid << 1) | entry.to.split.spec;
+		br[out].spec = lbr_spec_map[idx];
 		out++;
 	}
 
-- 
2.34.1


      parent reply	other threads:[~2022-08-11 12:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 12:29 [PATCH 00/13] perf/x86/amd: Add AMD LbrExtV2 support Sandipan Das
2022-08-11 12:29 ` [PATCH 01/13] perf/x86/amd/brs: Move feature-specific functions Sandipan Das
2022-08-11 12:29 ` [PATCH 02/13] perf/x86/amd/core: Refactor branch attributes Sandipan Das
2022-08-11 12:29 ` [PATCH 03/13] perf/x86/amd/core: Add generic branch record interfaces Sandipan Das
2022-08-11 12:29 ` [PATCH 04/13] x86/cpufeatures: Add LbrExtV2 feature bit Sandipan Das
2022-08-11 13:13   ` Borislav Petkov
2022-08-15 11:27   ` Peter Zijlstra
2022-08-15 19:42     ` Stephane Eranian
2022-08-22  9:05       ` Peter Zijlstra
2022-08-22 12:52         ` Sandipan Das
2022-08-22 13:26           ` Peter Zijlstra
2022-08-23  8:51             ` Sandipan Das
2022-08-25 10:24               ` Peter Zijlstra
2022-08-25 12:26                 ` Sandipan Das
2022-08-11 12:29 ` [PATCH 05/13] perf/x86/amd/lbr: Detect LbrExtV2 support Sandipan Das
2022-08-11 12:29 ` [PATCH 06/13] perf/x86/amd/lbr: Add LbrExtV2 branch record support Sandipan Das
2022-08-11 12:29 ` [PATCH 07/13] perf/x86/amd/lbr: Add LbrExtV2 hardware branch filter support Sandipan Das
2022-08-11 12:29 ` [PATCH 08/13] perf/x86: Move branch classifier Sandipan Das
2022-08-11 12:29 ` [PATCH 09/13] perf/x86/amd/lbr: Add LbrExtV2 software branch filter support Sandipan Das
2022-08-11 12:29 ` [PATCH 10/13] perf/x86: Make branch classifier fusion-aware Sandipan Das
2022-08-11 12:29 ` [PATCH 11/13] perf/x86/amd/lbr: Use fusion-aware branch classifier Sandipan Das
2022-08-11 12:30 ` [PATCH 12/13] perf/core: Add speculation info to branch entries Sandipan Das
2022-08-11 12:30 ` Sandipan Das [this message]

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=ddc02f6320464cad0e3ff5bdb2314531568a91bc.1660211399.git.sandipan.das@amd.com \
    --to=sandipan.das@amd.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ananth.narayan@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=like.xu.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=santosh.shukla@amd.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.