From: Ravi Bangoria <ravi.bangoria@amd.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <namhyung@kernel.org>
Cc: <ravi.bangoria@amd.com>, <acme@kernel.org>, <eranian@google.com>,
<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@kernel.org>, <irogers@google.com>,
<adrian.hunter@intel.com>, <kan.liang@linux.intel.com>,
<tglx@linutronix.de>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>,
<linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <santosh.shukla@amd.com>,
<ananth.narayan@amd.com>, <sandipan.das@amd.com>
Subject: [PATCH 8/8] perf/core: Introduce pmu->adjust_period() callback
Date: Mon, 7 Oct 2024 03:48:10 +0000 [thread overview]
Message-ID: <20241007034810.754-9-ravi.bangoria@amd.com> (raw)
In-Reply-To: <20241007034810.754-1-ravi.bangoria@amd.com>
Many hardware pmus have constraints about sample period. For ex, minimum
supported sample period for IBS Op pmu is 0x90, the sample period must
be multiple of 0x10 for IBS Fetch and IBS Op.
Add an optional callback adjust_period() to struct pmu to allow pmu
specific drivers to adjust sample period calculated by generic code.
This will ensure the sample_period value will always be valid and no
additional code is required in PMU specific drivers to re-adjust the
period.
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
---
arch/x86/events/amd/ibs.c | 11 +++++++++++
include/linux/perf_event.h | 5 +++++
kernel/events/core.c | 12 ++++++++++--
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index 33728ed6d7a6..0d1db2fffc5b 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -573,6 +573,15 @@ static int perf_ibs_check_period(struct perf_event *event, u64 value)
return 0;
}
+static u64 perf_ibs_adjust_period(struct perf_event *event, u64 period)
+{
+ struct perf_ibs *perf_ibs = container_of(event->pmu, struct perf_ibs, pmu);
+
+ period &= ~0xFULL;
+
+ return period < perf_ibs->min_period ? perf_ibs->min_period : period;
+}
+
/*
* We need to initialize with empty group if all attributes in the
* group are dynamic.
@@ -699,6 +708,7 @@ static struct perf_ibs perf_ibs_fetch = {
.stop = perf_ibs_stop,
.read = perf_ibs_read,
.check_period = perf_ibs_check_period,
+ .adjust_period = perf_ibs_adjust_period,
.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
},
.msr = MSR_AMD64_IBSFETCHCTL,
@@ -725,6 +735,7 @@ static struct perf_ibs perf_ibs_op = {
.stop = perf_ibs_stop,
.read = perf_ibs_read,
.check_period = perf_ibs_check_period,
+ .adjust_period = perf_ibs_adjust_period,
.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
},
.msr = MSR_AMD64_IBSOPCTL,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 1a8942277dda..eca8581d8e5d 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -540,6 +540,11 @@ struct pmu {
* Check period value for PERF_EVENT_IOC_PERIOD ioctl.
*/
int (*check_period) (struct perf_event *event, u64 value); /* optional */
+
+ /*
+ * Adjust period value according to pmu constraints.
+ */
+ u64 (*adjust_period) (struct perf_event *event, u64 period); /* optional */
};
enum perf_addr_filter_action_t {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8a6c6bbcd658..f3de683ec716 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4100,9 +4100,9 @@ static void perf_adjust_period(struct perf_event *event, u64 nsec, u64 count, bo
if (!sample_period)
sample_period = 1;
- hwc->sample_period = sample_period;
+ hwc->sample_period = event->pmu->adjust_period(event, sample_period);
- if (local64_read(&hwc->period_left) > 8*sample_period) {
+ if (local64_read(&hwc->period_left) > 8*hwc->sample_period) {
if (disable)
event->pmu->stop(event, PERF_EF_UPDATE);
@@ -11363,6 +11363,11 @@ static int perf_event_nop_int(struct perf_event *event, u64 value)
return 0;
}
+static u64 perf_pmu_nop_adjust_period(struct perf_event *event, u64 period)
+{
+ return period;
+}
+
static DEFINE_PER_CPU(unsigned int, nop_txn_flags);
static void perf_pmu_start_txn(struct pmu *pmu, unsigned int flags)
@@ -11641,6 +11646,9 @@ int perf_pmu_register(struct pmu *pmu, const char *name, int type)
if (!pmu->check_period)
pmu->check_period = perf_event_nop_int;
+ if (!pmu->adjust_period)
+ pmu->adjust_period = perf_pmu_nop_adjust_period;
+
if (!pmu->event_idx)
pmu->event_idx = perf_event_idx_default;
--
2.46.2
next prev parent reply other threads:[~2024-10-07 3:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 3:48 [PATCH 0/8] perf/amd/ibs: Fix sample period computations Ravi Bangoria
2024-10-07 3:48 ` [PATCH 1/8] perf/amd/ibs: Remove IBS_{FETCH|OP}_CONFIG_MASK macros Ravi Bangoria
2024-10-07 3:48 ` [PATCH 2/8] perf/amd/ibs: Remove pointless sample period check Ravi Bangoria
2024-10-07 19:16 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 3/8] perf/amd/ibs: Fix ->config to sample period calculation for OP pmu Ravi Bangoria
2024-10-07 3:48 ` [PATCH 4/8] perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt Ravi Bangoria
2024-10-07 3:48 ` [PATCH 5/8] perf/amd/ibs: Don't allow freq mode event creation through ->config interface Ravi Bangoria
2024-10-07 19:24 ` Namhyung Kim
2024-10-08 5:30 ` Ravi Bangoria
2024-10-09 6:27 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 6/8] perf/amd/ibs: Add pmu specific minimum period Ravi Bangoria
2024-10-07 19:30 ` Namhyung Kim
2024-10-08 5:46 ` Ravi Bangoria
2024-10-09 6:32 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 7/8] perf/amd/ibs: Add ->check_period() callback Ravi Bangoria
2024-10-07 19:33 ` Namhyung Kim
2024-10-07 3:48 ` Ravi Bangoria [this message]
2024-10-09 6:33 ` [PATCH 0/8] perf/amd/ibs: Fix sample period computations Namhyung Kim
2024-11-19 13:35 ` 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=20241007034810.754-9-ravi.bangoria@amd.com \
--to=ravi.bangoria@amd.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--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=hpa@zytor.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.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=sandipan.das@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®