Skip to contentSkip to conversation

kernel/sched/core.c: Avoid unused variable on non-SMP configs

PATCH In review Miguel Ojeda 3 participants 10 messages Sep 8, 2018 – Sep 10, 2018 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/sched/core.c: Avoid unused variable on non-SMP configs

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 <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/sched/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/sched/core.c +5 -2
index 625bc9897f62..d662d1e11843 100644
@@ -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;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 27 lines · Miguel Ojeda

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 <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/sched/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/sched/core.c +0 -0
index 625bc9897f62..d662d1e11843 100644
@@ -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...
  */

kernel/sched/core.c static void update_rq_clock_task(struct rq *rq, s64 delta) · line 145

Quoted 10 lines
kernel/sched/core.c +5 -2
-#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:

---

kernel/sched/core.c +1 -1
index 625bc9897f62..1728743360d4 100644
@@ -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;
Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#2 lore raw
Quoted 10 lines · Borislav Petkov

Alternatively, if you don't want to let the crazy ifdeffery in that function grow even more, you can simply do:

---

kernel/sched/core.c +0 -0
index 625bc9897f62..1728743360d4 100644

kernel/sched/core.c static void update_rq_clock_task(struct rq *rq, s64 delta) · line 140

Quoted 6 lines
kernel/sched/core.c +1 -1
@@ -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

#3 lore raw
Quoted 2 lines · Miguel Ojeda

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.

Quoted 1 line

Also, if we go that route, I would simply remove the #ifdef entirely.

Even better. The less ifdeffery the better.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#4 lore raw

Hi Borislav,

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Miguel Ojeda

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

#5 lore raw
Quoted 2 lines · Miguel Ojeda

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.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#6 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Miguel Ojeda

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

maintainer
#7 lore raw
Quoted 6 lines · Miguel Ojeda
Quoted 4 lines · Borislav Petkov
Quoted 2 lines · Miguel Ojeda

No, you get a different warning depending on whether you have enabled CONFIG_PARAVIRT_TIME_ACCOUNTING or CONFIG_IRQ_TIME_ACCOUNTING.

Quoted 8 lines
Quoted 5 lines

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

Quoted 3 lines

Cheers,
Miguel

#8 lore raw

Hi Vincent,

Quoted 14 lines · Vincent Guittot
Quoted 12 lines · Miguel Ojeda
Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Miguel Ojeda

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.

Quoted 5 lines
Quoted 2 lines

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

maintainer
#9 lore raw
Quoted 22 lines · Miguel Ojeda

Hi Vincent,

Quoted 17 lines · Vincent Guittot
Quoted 14 lines · Miguel Ojeda
Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Miguel Ojeda

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...

Quoted 7 lines
Quoted 2 lines

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

Quoted 3 lines

Cheers,
Miguel