Messages in this thread | | | From | Vineeth Pillai <> | Date | Mon, 9 Oct 2023 14:33:30 -0400 | Subject | Re: [PATCH RFC] sched/fair: Avoid unnecessary IPIs for ILB |
| |
On Sun, Oct 8, 2023 at 1:35 PM Joel Fernandes <joel@joelfernandes.org> wrote: > [...snip...] > > The patch does make _nohz_idle_balance() run more parallel, as previously > > it would be generally run by the first-idle CPU in nohz.idle_cpus_mask (at > > least for next_balance updates), but I think it's still SMP-safe, as all > > key data structure updates are already rq-locked AFAICS. > > One thing I am confused about in the original code is: > > tick_nohz_idle_stop_tick() is what sets the nohz.idle_cpus_mask. > However, nohz_run_idle_balance() is called before that can happen, in > do_idle(). So it is possible that NOHZ_NEWILB_KICK is set for a CPU but it is > not yet in the mask. > > So will this code in _nohz_idle_balance() really run in such a scenario? > > if (flags & NOHZ_STATS_KICK) > has_blocked_load |= update_nohz_stats(rq); > > AFAICS, this loop may not select the CPU due to its absence from the mask: > for_each_cpu_wrap(balance_cpu, nohz.idle_cpus_mask, this_cpu+1) > I have traced this a bit further. As Joel mentioned, the nohz.idle_cpus_mask shouldn't contain this cpu when nohz_run_idle_balance () is called from do_idle(), but on tracing I have seen that it does have it mostly with HIGHRES. And I feel this is a bug. We call nohz_balance_enter_idle() when we turn off the tick, but we don't always call nohz_balance_exit_idle() when we turn the tick back on. We call it only on the next tick on this cpu in nohz_balancer_kick. If a wakeup happens on this cpu while the tick is off, we re-enable the tick, but do not remove ourselves from the nohz.idle_cpus_mask. So, ILB will consider this cpu to be a valid pick until the next tick on this cpu where it gets removed. I am not sure if this is intentional.
If this is a bug and we fix it by calling nohz_balance_exit_idle during restart_tick, then we might not probably need NOHZ_NEWIDLE_KICK flag and could use NOHZ_STATS_KICK as there will not be any overlap between nohz_run_idle_balance and nohz_idle_balance.
Thanks, Vineeth
| |