[PATCH] sched: Drop outdated compile-optimization comment

Brian Norris posted 1 patch 3 years, 11 months ago
kernel/sched/core.c | 4 ----
1 file changed, 4 deletions(-)
[PATCH] sched: Drop outdated compile-optimization comment
Posted by Brian Norris 3 years, 11 months ago
Looks like this exists from way back in 2011 (commit 095c0aa83e52
("sched: adjust scheduler cpu power for stolen time")), when there was a
little more aggressive use of #if around these variables. That #if is
gone, and the comment just confuses the reader now. (For one, we don't
call sched_rt_avg_update() directly any more either.)

Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 kernel/sched/core.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bfa7452ca92e..6dbe52d90bef 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -679,10 +679,6 @@ struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf)
 
 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...
- */
 	s64 __maybe_unused steal = 0, irq_delta = 0;
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
-- 
2.36.1.476.g0c4daa206d-goog
Re: [PATCH] sched: Drop outdated compile-optimization comment
Posted by Valentin Schneider 3 years, 11 months ago
On 15/06/22 15:27, Brian Norris wrote:
> Looks like this exists from way back in 2011 (commit 095c0aa83e52
> ("sched: adjust scheduler cpu power for stolen time")), when there was a
> little more aggressive use of #if around these variables. That #if is
> gone, and the comment just confuses the reader now. (For one, we don't
> call sched_rt_avg_update() directly any more either.)
>

So that sched_rt_avg_update() became update_irq_load_avg() with

  91c27493e78d ("sched/irq: Add IRQ utilization tracking")

and then the #ifdef configs were reorganized in

  11d4afd4ff66 ("sched/pelt: Fix warning and clean up IRQ PELT config")

I'd argue that comment is still somewhat relevant but it applies to that
block:

#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
	if ((irq_delta + steal) && sched_feat(NONTASK_CAPACITY))
		update_irq_load_avg(rq, irq_delta + steal);
#endif

if !CONFIG_HAVE_SCHED_AVG_IRQ then yes you'd expect the compiler to not
even add a call to update_irq_load_avg() in there, but compilers aren't the
most trustworthy things :-) If you feel like it, you could play with
GCC/clang and see what they emit if you remove those #ifdefs.
Re: [PATCH] sched: Drop outdated compile-optimization comment
Posted by Brian Norris 3 years, 10 months ago
On Fri, Jun 17, 2022 at 12:10:05PM +0100, Valentin Schneider wrote:
> I'd argue that comment is still somewhat relevant but it applies to that
> block:
> 
> #ifdef CONFIG_HAVE_SCHED_AVG_IRQ
> 	if ((irq_delta + steal) && sched_feat(NONTASK_CAPACITY))
> 		update_irq_load_avg(rq, irq_delta + steal);
> #endif

Eh, I suppose. The confusion still stands though ;)

> if !CONFIG_HAVE_SCHED_AVG_IRQ then yes you'd expect the compiler to not
> even add a call to update_irq_load_avg() in there, but compilers aren't the
> most trustworthy things :-) If you feel like it, you could play with
> GCC/clang and see what they emit if you remove those #ifdefs.

FWIW, update_irq_load_avg() is just "return 0" in that case. I think
that'd be considered excessive paranoia if you think a modern compiler
would still somehow produce a suboptimal result for that case :)

But anyway, I tried CONFIG_IRQ_TIME_ACCOUNTING=n +
CONFIG_PARAVIRT_TIME_ACCOUNTING=n with these compilers:

  x86 gcc 11.2.0 (Debian)
  x86 clang 13.0.1 (Debian)
  aarch64-linux-gnu-gcc 11.2.0 (Debian)

and they all dropped the update_irq_load_avg() even without the #ifdef.

I'll drop it in a v2, since that seems to be the consensus.

Brian
Re: [PATCH] sched: Drop outdated compile-optimization comment
Posted by Peter Zijlstra 3 years, 11 months ago
On Fri, Jun 17, 2022 at 12:10:05PM +0100, Valentin Schneider wrote:
> On 15/06/22 15:27, Brian Norris wrote:
> > Looks like this exists from way back in 2011 (commit 095c0aa83e52
> > ("sched: adjust scheduler cpu power for stolen time")), when there was a
> > little more aggressive use of #if around these variables. That #if is
> > gone, and the comment just confuses the reader now. (For one, we don't
> > call sched_rt_avg_update() directly any more either.)
> >
> 
> So that sched_rt_avg_update() became update_irq_load_avg() with
> 
>   91c27493e78d ("sched/irq: Add IRQ utilization tracking")
> 
> and then the #ifdef configs were reorganized in
> 
>   11d4afd4ff66 ("sched/pelt: Fix warning and clean up IRQ PELT config")
> 
> I'd argue that comment is still somewhat relevant but it applies to that
> block:
> 
> #ifdef CONFIG_HAVE_SCHED_AVG_IRQ
> 	if ((irq_delta + steal) && sched_feat(NONTASK_CAPACITY))
> 		update_irq_load_avg(rq, irq_delta + steal);
> #endif
> 
> if !CONFIG_HAVE_SCHED_AVG_IRQ then yes you'd expect the compiler to not
> even add a call to update_irq_load_avg() in there, but compilers aren't the
> most trustworthy things :-) If you feel like it, you could play with
> GCC/clang and see what they emit if you remove those #ifdefs.

Mostly I think it was the jump_label stuff getting them confused. I
suspect that's fixed in todays compilers tho, so yeah, it might be good
to get rid of it.