From: Ravi Bangoria <ravi.bangoria@amd.com>
To: <peterz@infradead.org>
Cc: <ravi.bangoria@amd.com>, <namhyung@kernel.org>,
<eranian@google.com>, <acme@kernel.org>, <mark.rutland@arm.com>,
<jolsa@kernel.org>, <irogers@google.com>, <bp@alien8.de>,
<x86@kernel.org>, <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <sandipan.das@amd.com>,
<ananth.narayan@amd.com>, <santosh.shukla@amd.com>
Subject: [PATCH v2 2/3] perf/ibs: Fix interface via core pmu events
Date: Thu, 9 Mar 2023 15:41:10 +0530 [thread overview]
Message-ID: <20230309101111.444-3-ravi.bangoria@amd.com> (raw)
In-Reply-To: <20230309101111.444-1-ravi.bangoria@amd.com>
Although, IBS pmu can be invoked via it's own interface, indirect
IBS invocation via core pmu event is also supported with fixed set
of events: cpu-cycles:p, r076:p (same as cpu-cycles:p) and r0C1:p
(micro-ops) for user convenience.
This indirect IBS invocation is broken since commit 66d258c5b048
("perf/core: Optimize perf_init_event()"), which added RAW pmu
under pmu_idr list and thus if event_init() fails with RAW pmu,
it started returning error instead of trying other pmus.
Fix it by trying to open event on all pmus if event_init() on user
requested pmu returns -ESRCH.
Without patch:
$ sudo ./perf record -C 0 -e r076:p -- sleep 1
Error:
The r076:p event is not supported.
With patch:
$ sudo ./perf record -C 0 -e r076:p -- sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.341 MB perf.data (37 samples) ]
Note that there is no notion of forward pmu mapping. i.e. kernel doesn't
know which specific pmu(or a set of pmus) the event should be forwarded
to. As of now, only AMD core pmu forwards a set of events to IBS pmu
when precise_ip attribute is set and thus trying with all pmus works.
But if more pmus starts returning -ESRCH, some sort of forward pmu
mapping needs to be introduced through which the event can directly
get forwarded to only mapped pmus. Otherwise, trying all pmus can
inadvertently open event on wrong pmu.
Fixes: 66d258c5b048 ("perf/core: Optimize perf_init_event()")
Reported-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
---
arch/x86/events/amd/core.c | 11 ++++++++---
kernel/events/core.c | 10 +++++++++-
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 8c45b198b62f..81d67b899371 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -371,10 +371,15 @@ static inline int amd_has_nb(struct cpu_hw_events *cpuc)
static int amd_pmu_hw_config(struct perf_event *event)
{
int ret;
+ u64 dummy;
- /* pass precise event sampling to ibs: */
- if (event->attr.precise_ip && get_ibs_caps())
- return -ENOENT;
+ if (event->attr.precise_ip) {
+ /* pass precise event sampling to ibs by returning -ESRCH */
+ if (get_ibs_caps() && !ibs_core_pmu_event(event, &dummy))
+ return -ESRCH;
+ else
+ return -ENOENT;
+ }
if (has_branch_stack(event) && !x86_pmu.lbr_nr)
return -EOPNOTSUPP;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f79fd8b87f75..e990c71ba34a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11639,18 +11639,26 @@ static struct pmu *perf_init_event(struct perf_event *event)
goto again;
}
+ /*
+ * pmu->event_init() should return -ESRCH only when it
+ * wants to forward the event to other pmu.
+ */
+ if (ret == -ESRCH)
+ goto try_all;
+
if (ret)
pmu = ERR_PTR(ret);
goto unlock;
}
+try_all:
list_for_each_entry_rcu(pmu, &pmus, entry, lockdep_is_held(&pmus_srcu)) {
ret = perf_try_init_event(pmu, event);
if (!ret)
goto unlock;
- if (ret != -ENOENT) {
+ if (ret != -ENOENT && ret != -ESRCH) {
pmu = ERR_PTR(ret);
goto unlock;
}
--
2.39.2
next prev parent reply other threads:[~2023-03-09 10:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 10:11 [PATCH v2 0/3] perf/ibs: Fix interface via core pmu events Ravi Bangoria
2023-03-09 10:11 ` [PATCH v2 1/3] perf/ibs: Introduce ibs_core_pmu_event() Ravi Bangoria
2023-03-09 10:11 ` Ravi Bangoria [this message]
2023-03-11 0:32 ` [PATCH v2 2/3] perf/ibs: Fix interface via core pmu events Namhyung Kim
2023-03-13 12:35 ` Ravi Bangoria
2023-03-12 14:54 ` Peter Zijlstra
2023-03-13 12:29 ` Ravi Bangoria
2023-03-13 14:21 ` Peter Zijlstra
2023-03-13 15:40 ` Ravi Bangoria
2023-03-09 10:11 ` [PATCH v2 3/3] perf test: Add selftest to test IBS invocation " Ravi Bangoria
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=20230309101111.444-3-ravi.bangoria@amd.com \
--to=ravi.bangoria@amd.com \
--cc=acme@kernel.org \
--cc=ananth.narayan@amd.com \
--cc=bp@alien8.de \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sandipan.das@amd.com \
--cc=santosh.shukla@amd.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox