Skip to contentSkip to conversation

perf/x86/p4: Fix "Wunused-but-set-variable" warning

PATCH In review Lucy Mielke 3 participants 5 messages Oct 7, 2023 – Oct 13, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/x86/p4: Fix "Wunused-but-set-variable" warning

This fixes a compiler warning when compiling an allyesconfig with W=1:
warning: variable ´high´ set but not used [-Wunused-but-set-variable]

---
 arch/x86/events/intel/p4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/p4.c +1 -1
index 35936188db01..69aaf7c0f340 100644
@@ -1366,7 +1366,7 @@ static __initconst const struct x86_pmu p4_pmu = {
 
 __init int p4_pmu_init(void)
 {
-	unsigned int low, high;
+	unsigned int low, __maybe_unused high;
 	int i, reg;
 
 	/* If we get stripped -- indexing fails */
Signature · 1 line
2.42.0
maintainer
#1 lore raw
Quoted 2 lines · Lucy Mielke

This fixes a compiler warning when compiling an allyesconfig with W=1:
warning: variable ´high´ set but not used [-Wunused-but-set-variable]

What compiler and what .config?

Quoted 10 lines
---
 arch/x86/events/intel/p4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/p4.c +0 -0
index 35936188db01..69aaf7c0f340 100644

arch/x86/events/intel/p4.c static __initconst const struct x86_pmu p4_pmu = { · line 1372

Quoted 8 lines
arch/x86/events/intel/p4.c +1 -1
@@ -1366,7 +1366,7 @@ static __initconst const struct x86_pmu p4_pmu = {
 
 __init int p4_pmu_init(void)
 {
-	unsigned int low, high;
+	unsigned int low, __maybe_unused high;
 	int i, reg;
 
 	/* If we get stripped -- indexing fails */

Right after this we have:

	rdmsr(MSR_IA32_MISC_ENABLE, low, high);

which should get high unconditionally used. If there's a problem then it's probably inside that rdmsr macro.

#2 lore raw
Quoted 23 lines · Peter Zijlstra
Quoted 2 lines · Lucy Mielke

This fixes a compiler warning when compiling an allyesconfig with W=1:
warning: variable ´high´ set but not used [-Wunused-but-set-variable]

What compiler and what .config?

Quoted 17 lines
---
 arch/x86/events/intel/p4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/p4.c +1 -1
index 35936188db01..69aaf7c0f340 100644
@@ -1366,7 +1366,7 @@ static __initconst const struct x86_pmu p4_pmu = {
 
 __init int p4_pmu_init(void)
 {
-	unsigned int low, high;
+	unsigned int low, __maybe_unused high;
 	int i, reg;
 
Quoted 8 lines

arch/x86/events/intel/p4.c static __initconst const struct x86_pmu p4_pmu = { · line 1372

Quoted 1 line
arch/x86/events/intel/p4.c +0 -0
 	/* If we get stripped -- indexing fails */

Right after this we have:

	rdmsr(MSR_IA32_MISC_ENABLE, low, high);

which should get high unconditionally used. If there's a problem then it's probably inside that rdmsr macro.

rdmsr() writes to "high", but nothing ever reads from high. FWIW, I would _love_ for rdmsrl() to have return semantics, e.g. to be able to do:

	low  = (u32)rdmsrl(MSR_IA32_MISC_ENABLE);

or even

	if (!(rdmsrl(MSR_IA32_MISC_ENABLE) & BIT(7)))
#3 lore raw

Am Mon, Oct 09, 2023 at 09:29:50AM -0700 schrieb Sean Christopherson:

Quoted 9 lines

rdmsr() writes to "high", but nothing ever reads from high. FWIW, I would _love_ for rdmsrl() to have return semantics, e.g. to be able to do:

	low  = (u32)rdmsrl(MSR_IA32_MISC_ENABLE);

or even

	if (!(rdmsrl(MSR_IA32_MISC_ENABLE) & BIT(7)))

I have taken a look and it seems to me like this macro is called quite a lot for different things thoughout the kernel tree, including drivers. If one were to change it to have return semantics instead of the way it currently works, you'd have to change around 300 occurences, right? (Let me know if I misunderstood something.)

Return semantics or not, since the only way "high" is used in p4_pmu_init() is by being written to by rdmsr(), the variable can be completely removed by just using rdmsrl(). Would this be a patch you'd be interested in?

Mit freundlichen Grüßen / Best regards,
Lucy

#4 lore raw
Quoted 7 lines · Lucy Mielke

Am Mon, Oct 09, 2023 at 09:29:50AM -0700 schrieb Sean Christopherson:

Quoted 6 lines

rdmsr() writes to "high", but nothing ever reads from high. FWIW, I would _love_ for rdmsrl() to have return semantics, e.g. to be able to do:

	low  = (u32)rdmsrl(MSR_IA32_MISC_ENABLE);
Quoted 8 lines
Quoted 3 lines

or even

	if (!(rdmsrl(MSR_IA32_MISC_ENABLE) & BIT(7)))

I have taken a look and it seems to me like this macro is called quite a lot for different things thoughout the kernel tree, including drivers. If one were to change it to have return semantics instead of the way it currently works, you'd have to change around 300 occurences, right?

Yep, which is the only reason I haven't force the issue.