From: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<namhyung@kernel.org>, <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>,
<rui.zhang@intel.com>, <oleksandr@natalenko.name>
Cc: <eranian@google.com>, <gautham.shenoy@amd.com>,
<ravi.bangoria@amd.com>, <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
"Dhananjay Ugwekar" <Dhananjay.Ugwekar@amd.com>
Subject: [PATCH v5 2/9] perf/x86/rapl: Remove the cpu_to_rapl_pmu() function
Date: Fri, 13 Sep 2024 15:21:42 +0000 [thread overview]
Message-ID: <20240913152149.6317-3-Dhananjay.Ugwekar@amd.com> (raw)
In-Reply-To: <20240913152149.6317-1-Dhananjay.Ugwekar@amd.com>
Preparation for the addition of per-core RAPL energy counter support for
AMD CPUs. Post which, one cpu might be mapped to more than one rapl_pmu
(package/die one or per-core one), also makes sense to use the
get_rapl_pmu_idx macro which is anyway used to index into the
rapl_pmus->pmus[] array.
Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
---
arch/x86/events/rapl.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index ce04dc5844c4..b997899233c3 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -162,17 +162,6 @@ static inline unsigned int get_rapl_pmu_idx(int cpu)
topology_logical_die_id(cpu);
}
-static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu)
-{
- unsigned int rapl_pmu_idx = get_rapl_pmu_idx(cpu);
-
- /*
- * The unsigned check also catches the '-1' return value for non
- * existent mappings in the topology map.
- */
- return rapl_pmu_idx < rapl_pmus->nr_rapl_pmu ? rapl_pmus->pmus[rapl_pmu_idx] : NULL;
-}
-
static inline u64 rapl_read_counter(struct perf_event *event)
{
u64 raw;
@@ -348,7 +337,7 @@ static void rapl_pmu_event_del(struct perf_event *event, int flags)
static int rapl_pmu_event_init(struct perf_event *event)
{
u64 cfg = event->attr.config & RAPL_EVENT_MASK;
- int bit, ret = 0;
+ int bit, rapl_pmu_idx, ret = 0;
struct rapl_pmu *pmu;
/* only look at RAPL events */
@@ -376,8 +365,12 @@ static int rapl_pmu_event_init(struct perf_event *event)
if (event->attr.sample_period) /* no sampling */
return -EINVAL;
+ rapl_pmu_idx = get_rapl_pmu_idx(event->cpu);
+ if (rapl_pmu_idx >= rapl_pmus->nr_rapl_pmu)
+ return -EINVAL;
+
/* must be done before validate_group */
- pmu = cpu_to_rapl_pmu(event->cpu);
+ pmu = rapl_pmus->pmus[rapl_pmu_idx];
if (!pmu)
return -EINVAL;
event->pmu_private = pmu;
@@ -623,12 +616,16 @@ static const struct attribute_group *rapl_attr_update[] = {
static void __init init_rapl_pmu(void)
{
struct rapl_pmu *pmu;
- int cpu;
+ int cpu, rapl_pmu_idx;
cpus_read_lock();
for_each_cpu(cpu, cpu_online_mask) {
- pmu = cpu_to_rapl_pmu(cpu);
+ rapl_pmu_idx = get_rapl_pmu_idx(cpu);
+ if (rapl_pmu_idx >= rapl_pmus->nr_rapl_pmu)
+ continue;
+
+ pmu = rapl_pmus->pmus[rapl_pmu_idx];
if (pmu)
continue;
pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));
@@ -640,7 +637,7 @@ static void __init init_rapl_pmu(void)
pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
rapl_hrtimer_init(pmu);
- rapl_pmus->pmus[get_rapl_pmu_idx(cpu)] = pmu;
+ rapl_pmus->pmus[rapl_pmu_idx] = pmu;
}
cpus_read_unlock();
--
2.34.1
next prev parent reply other threads:[~2024-09-13 15:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 15:21 [PATCH v5 0/9] Add per-core RAPL energy counter support for AMD CPUs Dhananjay Ugwekar
2024-09-13 15:21 ` [PATCH v5 1/9] x86/topology: Introduce topology_logical_core_id() Dhananjay Ugwekar
2024-09-13 15:21 ` Dhananjay Ugwekar [this message]
2024-09-13 15:21 ` [PATCH v5 3/9] perf/x86/rapl: Rename rapl_pmu variables Dhananjay Ugwekar
2024-09-13 15:47 ` [PATCH v5 4/9] perf/x86/rapl: Make rapl_model struct global Dhananjay Ugwekar
2024-09-13 15:47 ` [PATCH v5 5/9] perf/x86/rapl: Add arguments to the cleanup and init functions Dhananjay Ugwekar
2024-09-13 15:47 ` [PATCH v5 6/9] perf/x86/rapl: Modify the generic variable names to *_pkg* Dhananjay Ugwekar
2024-09-13 15:47 ` [PATCH v5 7/9] perf/x86/rapl: Remove the global variable rapl_msrs Dhananjay Ugwekar
2024-09-13 15:48 ` [PATCH v5 8/9] perf/x86/rapl: Move the cntr_mask to rapl_pmus struct Dhananjay Ugwekar
2024-09-13 15:48 ` [PATCH v5 9/9] perf/x86/rapl: Add per-core energy counter support for AMD CPUs Dhananjay Ugwekar
2024-10-07 6:41 ` Gautham R. Shenoy
2024-10-07 8:38 ` Dhananjay Ugwekar
2024-09-13 21:18 ` [PATCH v5 0/9] Add per-core RAPL " Oleksandr Natalenko
2024-09-16 4:18 ` Dhananjay Ugwekar
2024-09-16 6:49 ` Oleksandr Natalenko
2024-09-16 8:01 ` Dhananjay Ugwekar
2024-10-08 6:08 ` Zhang, Rui
2024-10-08 6:43 ` Dhananjay Ugwekar
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=20240913152149.6317-3-Dhananjay.Ugwekar@amd.com \
--to=dhananjay.ugwekar@amd.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=eranian@google.com \
--cc=gautham.shenoy@amd.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=oleksandr@natalenko.name \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=rui.zhang@intel.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.