Re: [PATCH v3] sched/core: introduce sched_core_idle_cpu()

From: Frederic Weisbecker
Date: Thu Jun 29 2023 - 06:15:11 EST


On Thu, Jun 29, 2023 at 12:02:04PM +0800, Cruz Zhao wrote:
> As core scheduling introduced, a new state of idle is defined as
> force idle, running idle task but nr_running greater than zero.
>
> If a cpu is in force idle state, idle_cpu() will return zero. This
> result makes sense in some scenarios, e.g., load balance,
> showacpu when dumping, and judge the RCU boost kthread is starving.
>
> But this will cause error in other scenarios, e.g., tick_irq_exit():
> When force idle, rq->curr == rq->idle but rq->nr_running > 0, results
> that idle_cpu() returns 0. In function tick_irq_exit(), if idle_cpu()
> is 0, tick_nohz_irq_exit() will not be called, and ts->idle_active will
> not become 1, which became 0 in tick_nohz_irq_enter().
> ts->idle_sleeptime won't update in function update_ts_time_stats(), if
> ts->idle_active is 0, which should be 1. And this bug will result that
> ts->idle_sleeptime is less than the actual value, and finally will
> result that the idle time in /proc/stat is less than the actual value.
>
> To solve this problem, we introduce sched_core_idle_cpu(), which
> returns 1 when force idle. We audit all users of idle_cpu(), and
> change idle_cpu() into sched_core_idle_cpu() in function
> tick_irq_exit().
>
> v2-->v3: Only replace idle_cpu() with sched_core_idle_cpu() in
> function tick_irq_exit(). And modify the corresponding commit log.
>
> Signed-off-by: Cruz Zhao <CruzZhao@xxxxxxxxxxxxxxxxx>
> Reviewed-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Reviewed-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
> Reviewed-by: Joel Fernandes <joel@xxxxxxxxxxxxxxxxx>

Please wait for people to actually provide you with their Reviewed-by: tags
before writing it.

Aside of that, the patch looks good so you can put this one:

Reviewed-by: Frederic Weisbecker <frederic@xxxxxxxxxx>