* [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs
@ 2018-09-08 19:05 Miguel Ojeda
2018-09-09 9:36 ` Borislav Petkov
0 siblings, 1 reply; 10+ messages in thread
From: Miguel Ojeda @ 2018-09-08 19:05 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra; +Cc: linux-kernel
On non-SMP configs, when only one of CONFIG_{PARAVIRT,IRQ_TIME}_ACCOUNTING
is defined, we are declaring a variable (irq_delta or steal) which
is not used:
kernel/sched/core.c: In function ‘update_rq_clock_task’:
kernel/sched/core.c:139:17: warning: unused variable ‘irq_delta’ [-Wunused-variable]
s64 steal = 0, irq_delta = 0;
The reason is that CONFIG_SMP guards HAVE_SCHED_AVG_IRQ, which in turn
disables the code guarded by HAVE_SCHED_AVG_IRQ.
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
---
kernel/sched/core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 625bc9897f62..d662d1e11843 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -135,8 +135,11 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
* In theory, the compile should just see 0 here, and optimize out the call
* to sched_rt_avg_update. But I don't trust it...
*/
-#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
- s64 steal = 0, irq_delta = 0;
+#if defined(HAVE_SCHED_AVG_IRQ) || defined(CONFIG_IRQ_TIME_ACCOUNTING)
+ s64 irq_delta = 0;
+#endif
+#if defined(HAVE_SCHED_AVG_IRQ) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
+ s64 steal = 0;
#endif
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time;
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-08 19:05 [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs Miguel Ojeda @ 2018-09-09 9:36 ` Borislav Petkov 2018-09-09 14:48 ` Miguel Ojeda 0 siblings, 1 reply; 10+ messages in thread From: Borislav Petkov @ 2018-09-09 9:36 UTC (permalink / raw) To: Miguel Ojeda; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel On Sat, Sep 08, 2018 at 09:05:53PM +0200, Miguel Ojeda wrote: > On non-SMP configs, when only one of CONFIG_{PARAVIRT,IRQ_TIME}_ACCOUNTING > is defined, we are declaring a variable (irq_delta or steal) which > is not used: > > kernel/sched/core.c: In function ‘update_rq_clock_task’: > kernel/sched/core.c:139:17: warning: unused variable ‘irq_delta’ [-Wunused-variable] > s64 steal = 0, irq_delta = 0; > > The reason is that CONFIG_SMP guards HAVE_SCHED_AVG_IRQ, which in turn > disables the code guarded by HAVE_SCHED_AVG_IRQ. > > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Peter Zijlstra <peterz@infradead.org> > Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> > --- > kernel/sched/core.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 625bc9897f62..d662d1e11843 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -135,8 +135,11 @@ static void update_rq_clock_task(struct rq *rq, s64 delta) > * In theory, the compile should just see 0 here, and optimize out the call > * to sched_rt_avg_update. But I don't trust it... > */ > -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) > - s64 steal = 0, irq_delta = 0; > +#if defined(HAVE_SCHED_AVG_IRQ) || defined(CONFIG_IRQ_TIME_ACCOUNTING) > + s64 irq_delta = 0; > +#endif > +#if defined(HAVE_SCHED_AVG_IRQ) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) > + s64 steal = 0; > #endif > #ifdef CONFIG_IRQ_TIME_ACCOUNTING > irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time; > -- Alternatively, if you don't want to let the crazy ifdeffery in that function grow even more, you can simply do: --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 625bc9897f62..1728743360d4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -136,7 +136,7 @@ static void update_rq_clock_task(struct rq *rq, s64 delta) * to sched_rt_avg_update. But I don't trust it... */ #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) - s64 steal = 0, irq_delta = 0; + s64 steal __maybe_unused = 0, irq_delta = 0; #endif #ifdef CONFIG_IRQ_TIME_ACCOUNTING irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time; -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply. ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-09 9:36 ` Borislav Petkov @ 2018-09-09 14:48 ` Miguel Ojeda 2018-09-09 16:06 ` Borislav Petkov 0 siblings, 1 reply; 10+ messages in thread From: Miguel Ojeda @ 2018-09-09 14:48 UTC (permalink / raw) To: Borislav Petkov; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel On Sun, Sep 9, 2018 at 11:36 AM, Borislav Petkov <bp@alien8.de> wrote: > > Alternatively, if you don't want to let the crazy ifdeffery in that > function grow even more, you can simply do: > > --- > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 625bc9897f62..1728743360d4 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -136,7 +136,7 @@ static void update_rq_clock_task(struct rq *rq, s64 delta) > * to sched_rt_avg_update. But I don't trust it... > */ > #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) > - s64 steal = 0, irq_delta = 0; > + s64 steal __maybe_unused = 0, irq_delta = 0; > #endif Indeed. But note that the attribute needs to be written before the variable name so that it applies to both variables (or write it twice) --- see https://godbolt.org/z/cwOeXZ Also, if we go that route, I would simply remove the #ifdef entirely. Cheers, Miguel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-09 14:48 ` Miguel Ojeda @ 2018-09-09 16:06 ` Borislav Petkov 2018-09-09 16:36 ` Miguel Ojeda 0 siblings, 1 reply; 10+ messages in thread From: Borislav Petkov @ 2018-09-09 16:06 UTC (permalink / raw) To: Miguel Ojeda; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel On Sun, Sep 09, 2018 at 04:48:19PM +0200, Miguel Ojeda wrote: > Indeed. But note that the attribute needs to be written before the > variable name so that it applies to both variables (or write it twice) It warns only about 'steal' - not the other one. > Also, if we go that route, I would simply remove the #ifdef entirely. Even better. The less ifdeffery the better. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-09 16:06 ` Borislav Petkov @ 2018-09-09 16:36 ` Miguel Ojeda 2018-09-09 16:45 ` Borislav Petkov 0 siblings, 1 reply; 10+ messages in thread From: Miguel Ojeda @ 2018-09-09 16:36 UTC (permalink / raw) To: Borislav Petkov; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel Hi Borislav, On Sun, Sep 9, 2018 at 6:06 PM, Borislav Petkov <bp@alien8.de> wrote: > On Sun, Sep 09, 2018 at 04:48:19PM +0200, Miguel Ojeda wrote: >> Indeed. But note that the attribute needs to be written before the >> variable name so that it applies to both variables (or write it twice) > > It warns only about 'steal' - not the other one. No, you get a different warning depending on whether you have enabled CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING. In other words, !SMP && IRQ warns about "steal", while !SMP && PARAVIRT warns about "irq_delta" (the example warning I posted is for this last case). Cheers, Miguel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-09 16:36 ` Miguel Ojeda @ 2018-09-09 16:45 ` Borislav Petkov 2018-09-09 16:59 ` Miguel Ojeda 0 siblings, 1 reply; 10+ messages in thread From: Borislav Petkov @ 2018-09-09 16:45 UTC (permalink / raw) To: Miguel Ojeda; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel On Sun, Sep 09, 2018 at 06:36:01PM +0200, Miguel Ojeda wrote: > No, you get a different warning depending on whether you have enabled > CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING. Ok. Still, adding __maybe_unused to both (or writing it before the name, whatever works!) and dropping the ifdeffery is still better for readability's sake than having more ifdeffery, IMO. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-09 16:45 ` Borislav Petkov @ 2018-09-09 16:59 ` Miguel Ojeda 2018-09-10 7:00 ` Vincent Guittot 0 siblings, 1 reply; 10+ messages in thread From: Miguel Ojeda @ 2018-09-09 16:59 UTC (permalink / raw) To: Borislav Petkov; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel On Sun, Sep 9, 2018 at 6:45 PM, Borislav Petkov <bp@alien8.de> wrote: > On Sun, Sep 09, 2018 at 06:36:01PM +0200, Miguel Ojeda wrote: >> No, you get a different warning depending on whether you have enabled >> CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING. > > Ok. > > Still, adding __maybe_unused to both (or writing it before the name, > whatever works!) and dropping the ifdeffery is still better for > readability's sake than having more ifdeffery, IMO. Agreed, it is quite confusing already. I tried to keep the style of the code, but Ingo/Peter might prefer the cleanup. Let's see... Cheers, Miguel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-09 16:59 ` Miguel Ojeda @ 2018-09-10 7:00 ` Vincent Guittot 2018-09-10 10:32 ` Miguel Ojeda 0 siblings, 1 reply; 10+ messages in thread From: Vincent Guittot @ 2018-09-10 7:00 UTC (permalink / raw) To: miguel.ojeda.sandonis Cc: Borislav Petkov, Ingo Molnar, Peter Zijlstra, linux-kernel On Sun, 9 Sep 2018 at 19:00, Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Sun, Sep 9, 2018 at 6:45 PM, Borislav Petkov <bp@alien8.de> wrote: > > On Sun, Sep 09, 2018 at 06:36:01PM +0200, Miguel Ojeda wrote: > >> No, you get a different warning depending on whether you have enabled > >> CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING. > > > > Ok. > > > > Still, adding __maybe_unused to both (or writing it before the name, > > whatever works!) and dropping the ifdeffery is still better for > > readability's sake than having more ifdeffery, IMO. > > Agreed, it is quite confusing already. I tried to keep the style of > the code, but Ingo/Peter might prefer the cleanup. Let's see... FYI, another patch has already been sent for this warning https://lkml.org/lkml/2018/8/10/22 > > Cheers, > Miguel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-10 7:00 ` Vincent Guittot @ 2018-09-10 10:32 ` Miguel Ojeda 2018-09-10 12:34 ` Vincent Guittot 0 siblings, 1 reply; 10+ messages in thread From: Miguel Ojeda @ 2018-09-10 10:32 UTC (permalink / raw) To: Vincent Guittot Cc: Borislav Petkov, Ingo Molnar, Peter Zijlstra, linux-kernel Hi Vincent, On Mon, Sep 10, 2018 at 9:00 AM, Vincent Guittot <vincent.guittot@linaro.org> wrote: > On Sun, 9 Sep 2018 at 19:00, Miguel Ojeda > <miguel.ojeda.sandonis@gmail.com> wrote: >> >> On Sun, Sep 9, 2018 at 6:45 PM, Borislav Petkov <bp@alien8.de> wrote: >> > On Sun, Sep 09, 2018 at 06:36:01PM +0200, Miguel Ojeda wrote: >> >> No, you get a different warning depending on whether you have enabled >> >> CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING. >> > >> > Ok. >> > >> > Still, adding __maybe_unused to both (or writing it before the name, >> > whatever works!) and dropping the ifdeffery is still better for >> > readability's sake than having more ifdeffery, IMO. >> >> Agreed, it is quite confusing already. I tried to keep the style of >> the code, but Ingo/Peter might prefer the cleanup. Let's see... > > FYI, another patch has already been sent for this warning > https://lkml.org/lkml/2018/8/10/22 Indeed -- sorry, I didn't notice. The patches are different in behavior, though; is the block there supposed to be there in non-SMP cases? (I guess so, since originally it was there, but asking just in case). Cheers, Miguel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs 2018-09-10 10:32 ` Miguel Ojeda @ 2018-09-10 12:34 ` Vincent Guittot 0 siblings, 0 replies; 10+ messages in thread From: Vincent Guittot @ 2018-09-10 12:34 UTC (permalink / raw) To: Miguel Ojeda Cc: Borislav Petkov, Ingo Molnar, Peter Zijlstra, linux-kernel, douly.fnst On Mon, 10 Sep 2018 at 12:32, Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > Hi Vincent, > > On Mon, Sep 10, 2018 at 9:00 AM, Vincent Guittot > <vincent.guittot@linaro.org> wrote: > > On Sun, 9 Sep 2018 at 19:00, Miguel Ojeda > > <miguel.ojeda.sandonis@gmail.com> wrote: > >> > >> On Sun, Sep 9, 2018 at 6:45 PM, Borislav Petkov <bp@alien8.de> wrote: > >> > On Sun, Sep 09, 2018 at 06:36:01PM +0200, Miguel Ojeda wrote: > >> >> No, you get a different warning depending on whether you have enabled > >> >> CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING. > >> > > >> > Ok. > >> > > >> > Still, adding __maybe_unused to both (or writing it before the name, > >> > whatever works!) and dropping the ifdeffery is still better for > >> > readability's sake than having more ifdeffery, IMO. > >> > >> Agreed, it is quite confusing already. I tried to keep the style of > >> the code, but Ingo/Peter might prefer the cleanup. Let's see... > > > > FYI, another patch has already been sent for this warning > > https://lkml.org/lkml/2018/8/10/22 > > Indeed -- sorry, I didn't notice. The patches are different in > behavior, though; is the block there supposed to be there in non-SMP > cases? (I guess so, since originally it was there, but asking just in > case). Yes, i think it's worth keeping it for !SMP That being said, the original goal of the code is to compute the amount of capacity stolen to a guest or by interrupt in order to reflect that int the CPU capacity. But on !SMP, the cpu_capacity is not used as there is no load balance decision between CPU to do. Now, the code has being recently updated and the irq time is now also used in schedutil when selecting frequency which can also benefit to !SMP But the enable of irq tracking for !SMP hasn't been sent yet Regards, Vincent > > Cheers, > Miguel ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-09-10 12:34 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-09-08 19:05 [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs Miguel Ojeda 2018-09-09 9:36 ` Borislav Petkov 2018-09-09 14:48 ` Miguel Ojeda 2018-09-09 16:06 ` Borislav Petkov 2018-09-09 16:36 ` Miguel Ojeda 2018-09-09 16:45 ` Borislav Petkov 2018-09-09 16:59 ` Miguel Ojeda 2018-09-10 7:00 ` Vincent Guittot 2018-09-10 10:32 ` Miguel Ojeda 2018-09-10 12:34 ` Vincent Guittot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox