Skip to content

Commit 8c74e4e

Browse files
Dapeng MiPeter Zijlstra
authored andcommitted
perf/x86: Use macros to replace magic numbers in attr_rdpmc
Replace magic numbers in attr_rdpmc with macros to improve readability and make their meanings clearer for users. Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260114011750.350569-7-dapeng1.mi@linux.intel.com
1 parent c847a20 commit 8c74e4e

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

arch/x86/events/core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,8 @@ static int __init init_hw_perf_events(void)
21632163

21642164
pr_cont("%s PMU driver.\n", x86_pmu.name);
21652165

2166-
x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
2166+
/* enable userspace RDPMC usage by default */
2167+
x86_pmu.attr_rdpmc = X86_USER_RDPMC_CONDITIONAL_ENABLE;
21672168

21682169
for (quirk = x86_pmu.quirks; quirk; quirk = quirk->next)
21692170
quirk->func();
@@ -2643,12 +2644,12 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
26432644
*/
26442645
if (val == 0)
26452646
static_branch_inc(&rdpmc_never_available_key);
2646-
else if (x86_pmu.attr_rdpmc == 0)
2647+
else if (x86_pmu.attr_rdpmc == X86_USER_RDPMC_NEVER_ENABLE)
26472648
static_branch_dec(&rdpmc_never_available_key);
26482649

26492650
if (val == 2)
26502651
static_branch_inc(&rdpmc_always_available_key);
2651-
else if (x86_pmu.attr_rdpmc == 2)
2652+
else if (x86_pmu.attr_rdpmc == X86_USER_RDPMC_ALWAYS_ENABLE)
26522653
static_branch_dec(&rdpmc_always_available_key);
26532654

26542655
on_each_cpu(cr4_update_pce, NULL, 1);

arch/x86/events/intel/p6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static __init void p6_pmu_rdpmc_quirk(void)
243243
*/
244244
pr_warn("Userspace RDPMC support disabled due to a CPU erratum\n");
245245
x86_pmu.attr_rdpmc_broken = 1;
246-
x86_pmu.attr_rdpmc = 0;
246+
x86_pmu.attr_rdpmc = X86_USER_RDPMC_NEVER_ENABLE;
247247
}
248248
}
249249

arch/x86/events/perf_event.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ struct amd_nb {
187187
(1ULL << PERF_REG_X86_R14) | \
188188
(1ULL << PERF_REG_X86_R15))
189189

190+
/* user space rdpmc control values */
191+
enum {
192+
X86_USER_RDPMC_NEVER_ENABLE = 0,
193+
X86_USER_RDPMC_CONDITIONAL_ENABLE = 1,
194+
X86_USER_RDPMC_ALWAYS_ENABLE = 2,
195+
};
196+
190197
/*
191198
* Per register state.
192199
*/

0 commit comments

Comments
 (0)