selftests/powerpc: Fix set-but-not-used errors with GCC v16.2
PATCH 1/1 selftests/powerpc: Fix set-but-not-used errors with GCC v16.2
When compiling the powerpc selftests with GCC v16.2, the compilation fails with:
../pmu/lib.c: In function ‘eat_cpu_child’:
../pmu/lib.c:86:22: error: variable ‘i’ set but not used [-Werror=unused-but-set-variable=]
86 | volatile int i = 0;
| ^and:
ebb.c: In function ‘ebb_child’:
ebb.c:352:18: error: variable ‘val’ set but not used [-Werror=unused-but-set-variable=]
352 | uint64_t val;
| ^~~
cc1: all warnings being treated as errors
Add some "asm volatile" statements here to make to mark the variables as used and to avoid that the compiler might optimize the code away.
--- tools/testing/selftests/powerpc/pmu/ebb/ebb.c | 1 + tools/testing/selftests/powerpc/pmu/lib.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +1 -0
@@ -391,6 +391,7 @@ int ebb_child(union pipe read_pipe, union pipe write_pipe) val =mfspr (SPRN_MMCRA ); val |=mfspr (SPRN_MMCR2 ); val |=mfspr (SPRN_MMCR0 ); + asmvolatile ("" ::"r" (val) :"memory" ); }ebb_global_disable ();
tools/testing/selftests/powerpc/pmu/lib.c +4 -1
@@ -95,7 +95,10 @@ static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe)wait_for_parent (read_pipe);/* Soak up cpu forever */ -while (1 ) i++; +while (1 ) { + i++; + asmvolatile ("" ::"r" (i) :"memory" ); + }return 0 ; }
Signature · 1 line
2.56.0
Christophe Leroy (CS GROUP)
reviewerLe 16/11/2026 à 11:37, Thomas Huth a écrit :
Quoted 10 lines
When compiling the powerpc selftests with GCC v16.2, the compilation fails with:
../pmu/lib.c: In function ‘eat_cpu_child’:
../pmu/lib.c:86:22: error: variable ‘i’ set but not used [-Werror=unused-but-set-variable=]86 | volatile int i = 0; | ^and:
Quoted 8 lines
ebb.c: In function ‘ebb_child’:
ebb.c:352:18: error: variable ‘val’ set but not used [-Werror=unused-but-set-variable=]352 | uint64_t val; | ^~~cc1: all warnings being treated as errors
Add some "asm volatile" statements here to make to mark the variables as used and to avoid that the compiler might optimize the code away.
This looks really uggly, a cleaner way is likely possible, see below
Quoted 12 lines
Signed-off-by Thomas Huth <[email protected]>--- tools/testing/selftests/powerpc/pmu/ebb/ebb.c | 1 + tools/testing/selftests/powerpc/pmu/lib.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)tools/testing/selftests/powerpc/pmu/ebb/ebb.c +0
-0
tools/testing/selftests/powerpc/pmu/ebb/ebb.c int ebb_child(union pipe read_pipe, union pipe write_pipe) · line 394
Quoted 4 lines
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +1
-0@@ -391,6 +391,7 @@ int ebb_child(union pipe read_pipe, union pipe write_pipe) val =mfspr (SPRN_MMCRA ); val |=mfspr (SPRN_MMCR2 ); val |=mfspr (SPRN_MMCR0 ); + asmvolatile ("" ::"r" (val) :"memory" );
If val is not used, why not just do:
mfspr(SPRN_MMCRA); mfspr(SPRN_MMCR2); mfspr(SPRN_MMCR0);
mfspr() is already an 'asm volatile' so it will be executed even if the result is not used.
Quoted 8 lines
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +0
-0}ebb_global_disable ();tools/testing/selftests/powerpc/pmu/lib.c +0
-0
tools/testing/selftests/powerpc/pmu/lib.c static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe) · line 101
Quoted 8 lines
tools/testing/selftests/powerpc/pmu/lib.c +4
-1@@ -95,7 +95,10 @@ static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe)wait_for_parent (read_pipe);/* Soak up cpu forever */ -while (1 ) i++; +while (1 ) { + i++; + asmvolatile ("" ::"r" (i) :"memory" ); + }
If 'i' is not used, why keep it ?
Just do
while (1) ;
or
for (;;) ;
tools/testing/selftests/powerpc/pmu/lib.c static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe) · line 104
Quoted 3 lines
tools/testing/selftests/powerpc/pmu/lib.c +0
-0return 0 ; }
Christophe
Am 16.11.26 um 12:07 schrieb Christophe Leroy (CS GROUP):
Quoted 44 lines
Le 16/11/2026 à 11:37, Thomas Huth a écrit :
Quoted 10 lines
When compiling the powerpc selftests with GCC v16.2, the compilation fails with:
../pmu/lib.c: In function ‘eat_cpu_child’:
../pmu/lib.c:86:22: error: variable ‘i’ set but not used [- Werror=unused-but-set-variable=] 86 | volatile int i = 0;
| ^and:
Quoted 8 lines
ebb.c: In function ‘ebb_child’:
ebb.c:352:18: error: variable ‘val’ set but not used [-Werror=unused- but-set-variable=] 352 |uint64_tval;
| ^~~
cc1: all warnings being treated as errorsAdd some "asm volatile" statements here to make to mark the variables as used and to avoid that the compiler might optimize the code away.
This looks really uggly, a cleaner way is likely possible, see below
Quoted 12 lines
Signed-off-by Thomas Huth <[email protected]>---
tools/testing/selftests/powerpc/pmu/ebb/ebb.c| 1 + tools/testing/selftests/powerpc/pmu/lib.c | 5 ++++-2 files changed, 5 insertions(+), 1 deletion(-)tools/testing/selftests/powerpc/pmu/ebb/ebb.c +0
-0tools/testing/selftests/powerpc/pmu/ebb/ebb.c int ebb_child(union pipe read_pipe, union pipe · line 395
Quoted 5 lines
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +1
-0@@ -391,6 +391,7 @@ int ebb_child(union pipe read_pipe, union pipe write_pipe) val = mfspr(SPRN_MMCRA); val |= mfspr(SPRN_MMCR2); val |= mfspr(SPRN_MMCR0); + asm volatile("" :: "r"(val) : "memory");If val is not used, why not just do:
Quoted 5 lines
mfspr(SPRN_MMCRA);
mfspr(SPRN_MMCR2);
mfspr(SPRN_MMCR0);
mfspr()is already an 'asm volatile' so it will be executed even if the result is not used.
Ok, agreed, that makes sense.
Quoted 18 lines
Quoted 7 lines
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +0
-0} ebb_global_disable();tools/testing/selftests/powerpc/pmu/lib.c +0
-0tools/testing/selftests/powerpc/pmu/lib.c static int eat_cpu_child(union pipe read_pipe, union · line 101
Quoted 8 lines
tools/testing/selftests/powerpc/pmu/lib.c +4
-1@@ -95,7 +95,10 @@ static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe) wait_for_parent(read_pipe); /* Soak up cpu forever */ - while (1) i++; + while (1) { + i++; + asm volatile("" :: "r"(i) : "memory"); + }If 'i' is not used, why keep it ?
Quoted 4 lines
Just do
while (1)
;
I assume the original intention was to make the CPU do something beside a "branch to self" instruction ... ? Not sure whether it makes a difference for these pmu tests, though?
Thomas