linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] sched/core: silence a warning in sched_init()
@ 2019-06-25 12:44 Qian Cai
  2019-06-25 13:52 ` Peter Zijlstra
  2019-07-08 14:32 ` Qian Cai
  0 siblings, 2 replies; 8+ messages in thread
From: Qian Cai @ 2019-06-25 12:44 UTC (permalink / raw)
  To: mingo, peterz; +Cc: valentin.schneider, linux-kernel, Qian Cai

Compiling a kernel with both FAIR_GROUP_SCHED=n and RT_GROUP_SCHED=n
will generate a warning using W=1,

kernel/sched/core.c: In function 'sched_init':
kernel/sched/core.c:5906:32: warning: variable 'ptr' set but not used
[-Wunused-but-set-variable]
  unsigned long alloc_size = 0, ptr;
                                ^~~

It apparently the maintainers don't like the previous fix [1] which
contains ugly idefs, so silence it by appending the __maybe_unused
attribute for it instead.

[1] https://lore.kernel.org/lkml/1559681162-5385-1-git-send-email-cai@lca.pw/

Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Qian Cai <cai@lca.pw>
---

v2: Incorporate the feedback from Valentin.

 kernel/sched/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 874c427742a9..12b9b69c8a66 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5903,7 +5903,8 @@ int in_sched_functions(unsigned long addr)
 void __init sched_init(void)
 {
 	int i, j;
-	unsigned long alloc_size = 0, ptr;
+	unsigned long alloc_size = 0;
+	unsigned long __maybe_unused ptr;
 
 	wait_bit_init();
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 12:44 [PATCH v2] sched/core: silence a warning in sched_init() Qian Cai
@ 2019-06-25 13:52 ` Peter Zijlstra
  2019-06-25 14:04   ` Qian Cai
  2019-07-08 14:32 ` Qian Cai
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2019-06-25 13:52 UTC (permalink / raw)
  To: Qian Cai; +Cc: mingo, valentin.schneider, linux-kernel

On Tue, Jun 25, 2019 at 08:44:22AM -0400, Qian Cai wrote:
> Compiling a kernel with both FAIR_GROUP_SCHED=n and RT_GROUP_SCHED=n
> will generate a warning using W=1,
> 
> kernel/sched/core.c: In function 'sched_init':
> kernel/sched/core.c:5906:32: warning: variable 'ptr' set but not used
> [-Wunused-but-set-variable]
>   unsigned long alloc_size = 0, ptr;
>                                 ^~~
> 
> It apparently the maintainers don't like the previous fix [1] which
> contains ugly idefs, so silence it by appending the __maybe_unused
> attribute for it instead.
> 
> Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
> 
> v2: Incorporate the feedback from Valentin.
> 
>  kernel/sched/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 874c427742a9..12b9b69c8a66 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -5903,7 +5903,8 @@ int in_sched_functions(unsigned long addr)
>  void __init sched_init(void)
>  {
>  	int i, j;
> -	unsigned long alloc_size = 0, ptr;
> +	unsigned long alloc_size = 0;
> +	unsigned long __maybe_unused ptr;
>  

That still isn't particularly pretty.

Why do we care about W=1 build noise? Some of that seems rather silly,
like that -Wmissing-prototype nonsense.

As to this one, ideally the compiler would not be stupid, and understand
the below, but alas.

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fa43ce3962e7..cb652e165570 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6369,7 +6369,7 @@ DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
 
 void __init sched_init(void)
 {
-	unsigned long alloc_size = 0, ptr;
+	unsigned long alloc_size = 0;
 	int i;
 
 	wait_bit_init();
@@ -6381,7 +6381,7 @@ void __init sched_init(void)
 	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
 #endif
 	if (alloc_size) {
-		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
+		unsigned long ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 		root_task_group.se = (struct sched_entity **)ptr;

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 13:52 ` Peter Zijlstra
@ 2019-06-25 14:04   ` Qian Cai
  2019-06-25 14:25     ` Peter Zijlstra
  0 siblings, 1 reply; 8+ messages in thread
From: Qian Cai @ 2019-06-25 14:04 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, valentin.schneider, linux-kernel

On Tue, 2019-06-25 at 15:52 +0200, Peter Zijlstra wrote:
> On Tue, Jun 25, 2019 at 08:44:22AM -0400, Qian Cai wrote:
> > Compiling a kernel with both FAIR_GROUP_SCHED=n and RT_GROUP_SCHED=n
> > will generate a warning using W=1,
> > 
> > kernel/sched/core.c: In function 'sched_init':
> > kernel/sched/core.c:5906:32: warning: variable 'ptr' set but not used
> > [-Wunused-but-set-variable]
> >   unsigned long alloc_size = 0, ptr;
> >                                 ^~~
> > 
> > It apparently the maintainers don't like the previous fix [1] which
> > contains ugly idefs, so silence it by appending the __maybe_unused
> > attribute for it instead.
> > 
> > Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
> > Signed-off-by: Qian Cai <cai@lca.pw>
> > ---
> > 
> > v2: Incorporate the feedback from Valentin.
> > 
> >  kernel/sched/core.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 874c427742a9..12b9b69c8a66 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -5903,7 +5903,8 @@ int in_sched_functions(unsigned long addr)
> >  void __init sched_init(void)
> >  {
> >  	int i, j;
> > -	unsigned long alloc_size = 0, ptr;
> > +	unsigned long alloc_size = 0;
> > +	unsigned long __maybe_unused ptr;
> >  
> 
> That still isn't particularly pretty.
> 
> Why do we care about W=1 build noise? Some of that seems rather silly,
> like that -Wmissing-prototype nonsense.

Yes, -Wmissing-prototype makes no sense, but "-Wunused-but-set-variable" is
pretty valid to catch certain developer errors. For example,

https://lists.linuxfoundation.org/pipermail/iommu/2019-May/035680.html

> 
> As to this one, ideally the compiler would not be stupid, and understand
> the below, but alas.

Pretty sure that won't work, as the compiler will complain something like,

ISO C90 forbids mixed declarations and code

> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index fa43ce3962e7..cb652e165570 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6369,7 +6369,7 @@ DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
>  
>  void __init sched_init(void)
>  {
> -	unsigned long alloc_size = 0, ptr;
> +	unsigned long alloc_size = 0;
>  	int i;
>  
>  	wait_bit_init();
> @@ -6381,7 +6381,7 @@ void __init sched_init(void)
>  	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
>  #endif
>  	if (alloc_size) {
> -		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
> +		unsigned long ptr = (unsigned long)kzalloc(alloc_size,
> GFP_NOWAIT);
>  
>  #ifdef CONFIG_FAIR_GROUP_SCHED
>  		root_task_group.se = (struct sched_entity **)ptr;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 14:04   ` Qian Cai
@ 2019-06-25 14:25     ` Peter Zijlstra
  2019-06-25 15:07       ` Qian Cai
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2019-06-25 14:25 UTC (permalink / raw)
  To: Qian Cai; +Cc: mingo, valentin.schneider, linux-kernel

On Tue, Jun 25, 2019 at 10:04:19AM -0400, Qian Cai wrote:
> On Tue, 2019-06-25 at 15:52 +0200, Peter Zijlstra wrote:

> Yes, -Wmissing-prototype makes no sense, but "-Wunused-but-set-variable" is
> pretty valid to catch certain developer errors. For example,
> 
> https://lists.linuxfoundation.org/pipermail/iommu/2019-May/035680.html
> 
> > 
> > As to this one, ideally the compiler would not be stupid, and understand
> > the below, but alas.
> 
> Pretty sure that won't work, as the compiler will complain something like,
> 
> ISO C90 forbids mixed declarations and code

No, it builds just fine, it's a new block and C allows new variables at
every block start -- with the scope of that block.

And for our config, alloc_size is an unconditional 0, so it should DCE
the whole block and with that our variable. But clearly the passes are
the other way around :/

> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index fa43ce3962e7..cb652e165570 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -6369,7 +6369,7 @@ DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
> >  
> >  void __init sched_init(void)
> >  {
> > -	unsigned long alloc_size = 0, ptr;
> > +	unsigned long alloc_size = 0;
> >  	int i;
> >  
> >  	wait_bit_init();
> > @@ -6381,7 +6381,7 @@ void __init sched_init(void)
> >  	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
> >  #endif
> >  	if (alloc_size) {
> > -		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
> > +		unsigned long ptr = (unsigned long)kzalloc(alloc_size,
> > GFP_NOWAIT);
> >  
> >  #ifdef CONFIG_FAIR_GROUP_SCHED
> >  		root_task_group.se = (struct sched_entity **)ptr;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 14:25     ` Peter Zijlstra
@ 2019-06-25 15:07       ` Qian Cai
  2019-06-25 15:57         ` Peter Zijlstra
  0 siblings, 1 reply; 8+ messages in thread
From: Qian Cai @ 2019-06-25 15:07 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, valentin.schneider, linux-kernel

On Tue, 2019-06-25 at 16:25 +0200, Peter Zijlstra wrote:
> On Tue, Jun 25, 2019 at 10:04:19AM -0400, Qian Cai wrote:
> > On Tue, 2019-06-25 at 15:52 +0200, Peter Zijlstra wrote:
> > Yes, -Wmissing-prototype makes no sense, but "-Wunused-but-set-variable" is
> > pretty valid to catch certain developer errors. For example,
> > 
> > https://lists.linuxfoundation.org/pipermail/iommu/2019-May/035680.html
> > 
> > > 
> > > As to this one, ideally the compiler would not be stupid, and understand
> > > the below, but alas.
> > 
> > Pretty sure that won't work, as the compiler will complain something like,
> > 
> > ISO C90 forbids mixed declarations and code
> 
> No, it builds just fine, it's a new block and C allows new variables at
> every block start -- with the scope of that block.

I remember I tried that before but recalled the error code wrong. Here it is,

kernel/sched/core.c:5940:17: warning: unused variable 'ptr' [-Wunused-variable]
                unsigned long ptr = (unsigned long)kzalloc(alloc_size,
GFP_NOWAIT);

> 
> And for our config, alloc_size is an unconditional 0, so it should DCE
> the whole block and with that our variable. But clearly the passes are
> the other way around :/
> 
> > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > index fa43ce3962e7..cb652e165570 100644
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -6369,7 +6369,7 @@ DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
> > >  
> > >  void __init sched_init(void)
> > >  {
> > > -	unsigned long alloc_size = 0, ptr;
> > > +	unsigned long alloc_size = 0;
> > >  	int i;
> > >  
> > >  	wait_bit_init();
> > > @@ -6381,7 +6381,7 @@ void __init sched_init(void)
> > >  	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
> > >  #endif
> > >  	if (alloc_size) {
> > > -		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
> > > +		unsigned long ptr = (unsigned long)kzalloc(alloc_size,
> > > GFP_NOWAIT);
> > >  
> > >  #ifdef CONFIG_FAIR_GROUP_SCHED
> > >  		root_task_group.se = (struct sched_entity **)ptr;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 15:07       ` Qian Cai
@ 2019-06-25 15:57         ` Peter Zijlstra
  2019-07-18 20:44           ` Qian Cai
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2019-06-25 15:57 UTC (permalink / raw)
  To: Qian Cai; +Cc: mingo, valentin.schneider, linux-kernel

On Tue, Jun 25, 2019 at 11:07:09AM -0400, Qian Cai wrote:
> On Tue, 2019-06-25 at 16:25 +0200, Peter Zijlstra wrote:
> > On Tue, Jun 25, 2019 at 10:04:19AM -0400, Qian Cai wrote:
> > > On Tue, 2019-06-25 at 15:52 +0200, Peter Zijlstra wrote:
> > > Yes, -Wmissing-prototype makes no sense, but "-Wunused-but-set-variable" is
> > > pretty valid to catch certain developer errors. For example,
> > > 
> > > https://lists.linuxfoundation.org/pipermail/iommu/2019-May/035680.html
> > > 
> > > > 
> > > > As to this one, ideally the compiler would not be stupid, and understand
> > > > the below, but alas.
> > > 
> > > Pretty sure that won't work, as the compiler will complain something like,
> > > 
> > > ISO C90 forbids mixed declarations and code
> > 
> > No, it builds just fine, it's a new block and C allows new variables at
> > every block start -- with the scope of that block.
> 
> I remember I tried that before but recalled the error code wrong. Here it is,
> 
> kernel/sched/core.c:5940:17: warning: unused variable 'ptr' [-Wunused-variable]
>                 unsigned long ptr = (unsigned long)kzalloc(alloc_size,
> GFP_NOWAIT);

Yes, I know, I tried. And GCC is a moron because of it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 12:44 [PATCH v2] sched/core: silence a warning in sched_init() Qian Cai
  2019-06-25 13:52 ` Peter Zijlstra
@ 2019-07-08 14:32 ` Qian Cai
  1 sibling, 0 replies; 8+ messages in thread
From: Qian Cai @ 2019-07-08 14:32 UTC (permalink / raw)
  To: mingo, peterz; +Cc: valentin.schneider, linux-kernel

Ping. Per discussion, sounds like this is the best thing to do in order to avoid
compilation warnings.

On Tue, 2019-06-25 at 08:44 -0400, Qian Cai wrote:
> Compiling a kernel with both FAIR_GROUP_SCHED=n and RT_GROUP_SCHED=n
> will generate a warning using W=1,
> 
> kernel/sched/core.c: In function 'sched_init':
> kernel/sched/core.c:5906:32: warning: variable 'ptr' set but not used
> [-Wunused-but-set-variable]
>   unsigned long alloc_size = 0, ptr;
>                                 ^~~
> 
> It apparently the maintainers don't like the previous fix [1] which
> contains ugly idefs, so silence it by appending the __maybe_unused
> attribute for it instead.
> 
> [1] https://lore.kernel.org/lkml/1559681162-5385-1-git-send-email-cai@lca.pw/
> 
> Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
> 
> v2: Incorporate the feedback from Valentin.
> 
>  kernel/sched/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 874c427742a9..12b9b69c8a66 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -5903,7 +5903,8 @@ int in_sched_functions(unsigned long addr)
>  void __init sched_init(void)
>  {
>  	int i, j;
> -	unsigned long alloc_size = 0, ptr;
> +	unsigned long alloc_size = 0;
> +	unsigned long __maybe_unused ptr;
>  
>  	wait_bit_init();
>  

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] sched/core: silence a warning in sched_init()
  2019-06-25 15:57         ` Peter Zijlstra
@ 2019-07-18 20:44           ` Qian Cai
  0 siblings, 0 replies; 8+ messages in thread
From: Qian Cai @ 2019-07-18 20:44 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, Valentin Schneider, LKML



> On Jun 25, 2019, at 11:57 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> On Tue, Jun 25, 2019 at 11:07:09AM -0400, Qian Cai wrote:
>> On Tue, 2019-06-25 at 16:25 +0200, Peter Zijlstra wrote:
>>> On Tue, Jun 25, 2019 at 10:04:19AM -0400, Qian Cai wrote:
>>>> On Tue, 2019-06-25 at 15:52 +0200, Peter Zijlstra wrote:
>>>> Yes, -Wmissing-prototype makes no sense, but "-Wunused-but-set-variable" is
>>>> pretty valid to catch certain developer errors. For example,
>>>> 
>>>> https://lists.linuxfoundation.org/pipermail/iommu/2019-May/035680.html
>>>> 
>>>>> 
>>>>> As to this one, ideally the compiler would not be stupid, and understand
>>>>> the below, but alas.
>>>> 
>>>> Pretty sure that won't work, as the compiler will complain something like,
>>>> 
>>>> ISO C90 forbids mixed declarations and code
>>> 
>>> No, it builds just fine, it's a new block and C allows new variables at
>>> every block start -- with the scope of that block.
>> 
>> I remember I tried that before but recalled the error code wrong. Here it is,
>> 
>> kernel/sched/core.c:5940:17: warning: unused variable 'ptr' [-Wunused-variable]
>>                 unsigned long ptr = (unsigned long)kzalloc(alloc_size,
>> GFP_NOWAIT);
> 
> Yes, I know, I tried. And GCC is a moron because of it.

Actually, not only GCC but clang also don’t understand your patch.

# make CC=clang W=1 kernel/sched/core.o

kernel/sched/core.c:6384:17: warning: unused variable 'ptr' [-Wunused-variable]
                unsigned long ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);

Maybe adding a “__maybe_unused” until the day that compilers are getting smarter. 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-18 20:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25 12:44 [PATCH v2] sched/core: silence a warning in sched_init() Qian Cai
2019-06-25 13:52 ` Peter Zijlstra
2019-06-25 14:04   ` Qian Cai
2019-06-25 14:25     ` Peter Zijlstra
2019-06-25 15:07       ` Qian Cai
2019-06-25 15:57         ` Peter Zijlstra
2019-07-18 20:44           ` Qian Cai
2019-07-08 14:32 ` Qian Cai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).