Skip to content

Commit 54d2759

Browse files
dhananjay-AMDPeter Zijlstra
authored andcommitted
perf/x86/rapl: Move the cntr_mask to rapl_pmus struct
Prepare for the addition of RAPL core energy counter support. Move cntr_mask to rapl_pmus struct instead of adding a new global cntr_mask for the new RAPL power_core PMU. This will also ensure that the second "core_cntr_mask" is only created if needed (i.e. in case of AMD CPUs). Signed-off-by: Dhananjay Ugwekar <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: "Gautham R. Shenoy" <[email protected]> Reviewed-by: Zhang Rui <[email protected]> Tested-by: Zhang Rui <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bdc57ec commit 54d2759

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

arch/x86/events/rapl.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ struct rapl_pmu {
129129
struct rapl_pmus {
130130
struct pmu pmu;
131131
unsigned int nr_rapl_pmu;
132+
unsigned int cntr_mask;
132133
struct rapl_pmu *rapl_pmu[] __counted_by(nr_rapl_pmu);
133134
};
134135

@@ -148,7 +149,6 @@ struct rapl_model {
148149
/* 1/2^hw_unit Joule */
149150
static int rapl_pkg_hw_unit[NR_RAPL_PKG_DOMAINS] __read_mostly;
150151
static struct rapl_pmus *rapl_pmus_pkg;
151-
static unsigned int rapl_pkg_cntr_mask;
152152
static u64 rapl_timer_ms;
153153
static struct rapl_model *rapl_model;
154154

@@ -364,7 +364,7 @@ static int rapl_pmu_event_init(struct perf_event *event)
364364
bit = cfg - 1;
365365

366366
/* check event supported */
367-
if (!(rapl_pkg_cntr_mask & (1 << bit)))
367+
if (!(rapl_pmus_pkg->cntr_mask & (1 << bit)))
368368
return -EINVAL;
369369

370370
/* unsupported modes and filters */
@@ -592,10 +592,10 @@ static void __init rapl_advertise(void)
592592
int i;
593593

594594
pr_info("API unit is 2^-32 Joules, %d fixed counters, %llu ms ovfl timer\n",
595-
hweight32(rapl_pkg_cntr_mask), rapl_timer_ms);
595+
hweight32(rapl_pmus_pkg->cntr_mask), rapl_timer_ms);
596596

597597
for (i = 0; i < NR_RAPL_PKG_DOMAINS; i++) {
598-
if (rapl_pkg_cntr_mask & (1 << i)) {
598+
if (rapl_pmus_pkg->cntr_mask & (1 << i)) {
599599
pr_info("hw unit of domain %s 2^-%d Joules\n",
600600
rapl_pkg_domain_names[i], rapl_pkg_hw_unit[i]);
601601
}
@@ -810,9 +810,6 @@ static int __init rapl_pmu_init(void)
810810

811811
rapl_model = (struct rapl_model *) id->driver_data;
812812

813-
rapl_pkg_cntr_mask = perf_msr_probe(rapl_model->rapl_pkg_msrs, PERF_RAPL_PKG_EVENTS_MAX,
814-
false, (void *) &rapl_model->pkg_events);
815-
816813
ret = rapl_check_hw_unit();
817814
if (ret)
818815
return ret;
@@ -821,6 +818,10 @@ static int __init rapl_pmu_init(void)
821818
if (ret)
822819
return ret;
823820

821+
rapl_pmus_pkg->cntr_mask = perf_msr_probe(rapl_model->rapl_pkg_msrs,
822+
PERF_RAPL_PKG_EVENTS_MAX, false,
823+
(void *) &rapl_model->pkg_events);
824+
824825
ret = perf_pmu_register(&rapl_pmus_pkg->pmu, "power", -1);
825826
if (ret)
826827
goto out;

0 commit comments

Comments
 (0)