mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Shuah Khan <shuah@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [PATCH] selftests/powerpc: Fix set-but-not-used errors with GCC v16.2
Date: Mon, 16 Nov 2026 13:27:08 +0100	[thread overview]
Message-ID: <562b9015-6967-4858-8f17-a49978b30f2a@redhat.com> (raw)
In-Reply-To: <b2abcfcd-2d89-44a3-ac03-7354c3be2436@kernel.org>

Am 16.11.26 um 12:07 schrieb Christophe Leroy (CS GROUP):
> 
> 
> Le 16/11/2026 à 11:37, Thomas Huth a écrit :
>> 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.
> 
> This looks really uggly, a cleaner way is likely possible, see below
> 
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   tools/testing/selftests/powerpc/pmu/ebb/ebb.c | 1 +
>>   tools/testing/selftests/powerpc/pmu/lib.c     | 5 ++++-
>>   2 files changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c b/tools/ 
>> testing/selftests/powerpc/pmu/ebb/ebb.c
>> index 21537d6eb6b7d..f4ef92bacd9ab 100644
>> --- a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
>> +++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
>> @@ -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:
> 
>          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.

>>       }
>>       ebb_global_disable();
>> diff --git a/tools/testing/selftests/powerpc/pmu/lib.c b/tools/testing/ 
>> selftests/powerpc/pmu/lib.c
>> index 3213579874084..32cafd40d2c56 100644
>> --- a/tools/testing/selftests/powerpc/pmu/lib.c
>> +++ b/tools/testing/selftests/powerpc/pmu/lib.c
>> @@ -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 ?
> 
> 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


      reply	other threads:[~2026-11-16 12:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 10:37 Thomas Huth
2026-11-16 11:07 ` Christophe Leroy (CS GROUP)
2026-11-16 12:27   ` Thomas Huth [this message]

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=562b9015-6967-4858-8f17-a49978b30f2a@redhat.com \
    --to=thuth@redhat.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=segher@kernel.crashing.org \
    --cc=shuah@kernel.org \
    --cc=sshegde@linux.ibm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®