Re: [PATCH RESEND] sched/nohz: Affine unpinned timers to housekeepers
From: Frederic Weisbecker
Date: Sun Aug 23 2015 - 21:46:02 EST
On Sun, Aug 23, 2015 at 07:40:32AM +0200, Ingo Molnar wrote:
> So I almost applied this yesterday, but had the following question: what ensures
> that housekeeping_mask isn't empty? If it's empty then housekeeping_any_cpu()
> returns cpumask_any_and() of an empty cpumask - which returns an out of range
> index AFAICS - which will crash and burn in:
>
> kernel/time/hrtimer.c: return &per_cpu(hrtimer_bases, get_nohz_timer_target());
> kernel/time/timer.c: return per_cpu_ptr(&tvec_bases, get_nohz_timer_target());
>
> housekeeping_mask itself is derived from tick_nohz_full_mask (it's the inverse of
> it in essence), and tick_nohz_full_mask is set via two methods, either via a boot
> parameter:
>
> if (cpulist_parse(str, tick_nohz_full_mask) < 0) {
>
> in tick_nohz_full_setup(). What ensures here that tick_nohz_full_mask is not
> completely full - making housekeeping_mask empty?
>
> The other method is via CONFIG_NO_HZ_FULL_ALL:
>
> cpumask_setall(tick_nohz_full_mask);
>
> here it's fully set - triggering the bug I'm worried about. So what am I missing,
> what prevents CONFIG_NO_HZ_FULL_ALL from crashing?
Legitimate worry and I should have explained that in the changelog.
Like Paul replied, we make sure that at least the boot CPU is excluded
from tick_nohz_full_mask in tick_nohz_init(). Then housekeeping_mask,
by reverse effect, contains that boot CPU at least.
And we also make sure that the boot CPU can't get offline
(tick_nohz_cpu_down_callback()).
Now we should really document and check that assumption so here is a
second patch below. The sched patch depends on tip:sched/core (to avoid
conflicts with sched changes) and the following one is based on
tip:timer/nohz but should be applicable to sched/core without conflict.
Both are standalone anyway.
Thanks!
---
From: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Date: Sun, 23 Aug 2015 19:34:31 +0200
Subject: [PATCH] nohz: Assert existing housekeepers when nohz full enabled
The code ensures that at least the boot CPU serves as a housekeeper.
Let's assert this assumption to make sure that we have CPUs to handle
unbound jobs like workqueues and timers while nohz full CPUs run
undisturbed.
Signed-off-by: Frederic Weisbecker <fweisbec@xxxxxxxxx>
---
kernel/time/tick-sched.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 3319e16..cc9884f 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -370,6 +370,12 @@ void __init tick_nohz_init(void)
cpu_notifier(tick_nohz_cpu_down_callback, 0);
pr_info("NO_HZ: Full dynticks CPUs: %*pbl.\n",
cpumask_pr_args(tick_nohz_full_mask));
+
+ /*
+ * We need at least one CPU to handle housekeeping work such
+ * as timekeeping, unbound timers, workqueues, ...
+ */
+ WARN_ON_ONCE(cpumask_empty(housekeeping_mask));
}
#endif
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/