sched/fair: Don't let task_tick_cache() IPI dyntick CPUs
Valentin Schneider
reviewerPATCH 1/1 sched/fair: Don't let task_tick_cache() IPI dyntick CPUs
While testing some CPU isolation / NOHZ_FULL stuff I stumbled on something like so:
kworker/u289:5-241489 [001] d..3. 2963.728734: ipi_send_cpu: cpu=6 callsite=task_work_add+0x84 callback=0x0 kworker/u289:5-241489 [001] d..3. 2963.728735: kernel_stack: <stack trace >
=> trace_event_raw_event_ipi_send_cpu (ffffffffa6d7ba45) => kick_process (ffffffffa6d827a2)
=> task_work_add (ffffffffa6d645c4)
=> task_tick_fair (ffffffffa6d9cfbe)
=> sched_tick_remote (ffffffffa6d84c69)
=> process_one_work (ffffffffa6d5d57b)
=> worker_thread (ffffffffa6d5e1af)
=> kthread (ffffffffa6d66e85)
=> ret_from_fork (ffffffffa6cb3f2b)
=> ret_from_fork_asm (ffffffffa6c7741a)
In this case CPU6 is isolated via isolcpus=, and is executing a single pure userspace task, so should be fully leveraging dynticks.
However, because that task is SCHED_OTHER, housekeeping CPUs periodically handle a sched_tick_remote() on its behalf, and end up kicking that task out of userspace to run the task_cache_work().
Let task_tick_cache() recognize when it is invoked via a remote tick, and bail out rather than disturb dyntick CPUs.
--- kernel/sched/fair.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/sched/fair.c +7 -0
@@ -1925,6 +1925,13 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p) !grp->pcpu_sched)return ; +/* +* We got here from a sched_tick_remote(), meaning @p is making use of +* NOHZ_FULL. Don't disturb it with a task_work() IPI. +*/ +if (cpu_of (rq) !=smp_processor_id ()) +return ; + epoch = rq->cpu_epoch;/* avoid moving backwards */ if (time_after_eq (grp->epoch, epoch))
Signature · 1 line
2.56.1
Peter Zijlstra
maintainerQuoted 39 lines · Valentin Schneider
While testing some CPU isolation /
NOHZ_FULLstuff I stumbled on something like so:kworker/u289:5-241489 [001] d..3. 2963.728734: ipi_send_cpu: cpu=6 callsite=task_work_add+0x84 callback=0x0 kworker/u289:5-241489 [001] d..3. 2963.728735: kernel_stack: <stack trace >=>
trace_event_raw_event_ipi_send_cpu(ffffffffa6d7ba45) =>kick_process(ffffffffa6d827a2)
=>task_work_add(ffffffffa6d645c4)
=>task_tick_fair(ffffffffa6d9cfbe)
=>sched_tick_remote(ffffffffa6d84c69)
=>process_one_work(ffffffffa6d5d57b)
=>worker_thread(ffffffffa6d5e1af)
=> kthread (ffffffffa6d66e85)
=>ret_from_fork(ffffffffa6cb3f2b)
=>ret_from_fork_asm(ffffffffa6c7741a)In this case CPU6 is isolated via isolcpus=, and is executing a single pure userspace task, so should be fully leveraging dynticks.
However, because that task is
SCHED_OTHER, housekeeping CPUs periodically handle asched_tick_remote()on its behalf, and end up kicking that task out of userspace to run thetask_cache_work().Let
task_tick_cache()recognize when it is invoked via a remote tick, and bail out rather than disturb dyntick CPUs.Signed-off-by Valentin Schneider <[email protected]>--- kernel/sched/fair.c | 7 +++++++ 1 file changed, 7 insertions(+)kernel/sched/fair.c +0
-0@@ -1925,6 +1925,13 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p) !grp->pcpu_sched)return ;
kernel/sched/fair.c static void task_tick_cache(struct rq *rq, struct task_struct *p) · line 1937
Quoted 10 lines
kernel/sched/fair.c +7
-0+/* +* We got here from a sched_tick_remote(), meaning @p is making use of +* NOHZ_FULL. Don't disturb it with a task_work() IPI. +*/ +if (cpu_of (rq) !=smp_processor_id ()) +return ; + epoch = rq->cpu_epoch;/* avoid moving backwards */ if (time_after_eq (grp->epoch, epoch))
Its early, and I definitely need more wake-up juice, but how is task_tick_numa() different here?
Also, I'm not sure sched_tick_remote() is the right condition here. But perhaps something like so? Does this make sense?
---
arch/x86/include/asm/stop_machine.h deleted +0 -0
kernel/sched/fair.c +12 -4
@@ -4588,6 +4588,9 @@ static void task_tick_numa(struct rq *rq, struct task_struct *curr)struct callback_head *work = &curr->numa_work;u64 period, now; +if (!static_branch_unlikely (&sched_numa_balancing)) +return ; +/* * We don't care about NUMA placement if we don't have memory. */
@@ -15401,15 +15404,20 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int hrtick)if (hrtick)return ; -if (static_branch_unlikely (&sched_numa_balancing)) -task_tick_numa (rq, curr); +task_tick_core (rq, curr); +/* +* If there is no root domain; there is no balancing, and none of this +* matters. +*/ +if (!rq->rd) +return ; + +task_tick_numa (rq, curr);task_tick_cache (rq, curr);update_misfit_status (curr, rq);check_update_overutilized_status (task_rq (curr)); - -task_tick_core (rq, curr); }/*
Valentin Schneider
reviewerQuoted 5 lines · Peter Zijlstra
Quoted 4 lines · Valentin Schneider
(quoted diff) +0
-0@@ -1925,6 +1925,13 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p) !grp->pcpu_sched) return;
Quoted 15 lines
Review static void task_tick_cache(struct rq *rq, struct task_struct *p) · line 1937
Quoted 10 lines
(quoted diff) +7
-0+ /* + * We got here from a sched_tick_remote(), meaning @p is making use of + * NOHZ_FULL. Don't disturb it with a task_work() IPI. + */ + if (cpu_of(rq) != smp_processor_id()) + return; + epoch = rq->cpu_epoch; /* avoid moving backwards */ if (time_after_eq(grp->epoch, epoch))Its early, and I definitely need more wake-up juice, but how is
task_tick_numa()different here?
It shouldn't be too different, I just can't get it to trigger on my QEMU setup; I'm done running stuff on the machine I caught this on so I can start digging there.
Quoted 5 lines
kernel/sched/fair.c +0
-1@@ -15401,15 +15404,20 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int hrtick)if (hrtick)return ; -if (static_branch_unlikely (&sched_numa_balancing))
kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int hrtick) · line 15415
Quoted 10 lines
kernel/sched/fair.c +8
-1-task_tick_numa (rq, curr); +task_tick_core (rq, curr); +/* +* If there is no root domain; there is no balancing, and none of this +* matters. +*/ +if (!rq->rd) +return ; +
What if the setup involves a separate root domain where all the CPUs are in dynticks mode?
Methinks the signal we want is:
is that task on a NOHZ_FULL CPU with the tick disabled?
If so then we shouldn't do anything about it. Let the other CPUs in its LLC / RD run some balancing. If they're all dynticks, well then there is nothing to do is there?
And that should also apply to the NUMA stuff like you pointed out.
Quoted 10 lines
kernel/sched/fair.c +1
-2+task_tick_numa (rq, curr);task_tick_cache (rq, curr);update_misfit_status (curr, rq);check_update_overutilized_status (task_rq (curr)); - -task_tick_core (rq, curr); }/*
Peter Zijlstra
maintainerQuoted 13 lines · Valentin Schneider
kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int hrtick) · line 15415
Quoted 7 lines
kernel/sched/fair.c +7
-0+/* +* If there is no root domain; there is no balancing, and none of this +* matters. +*/ +if (!rq->rd) +return ; +What if the setup involves a separate root domain where all the CPUs are in dynticks mode?
Methinks the signal we want is:
Quoted 7 lines
is that task on a
NOHZ_FULLCPU with the tick disabled?If so then we shouldn't do anything about it. Let the other CPUs in its LLC / RD run some balancing. If they're all dynticks, well then there is nothing to do is there?
And that should also apply to the NUMA stuff like you pointed out.
If you have a root domain with more than 1 CPU in it, you get balancing, deal with it.
Valentin Schneider
reviewerQuoted 16 lines · Peter Zijlstra
Quoted 15 lines · Valentin Schneider
kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int hrtick) · line 15415
Quoted 7 lines
kernel/sched/fair.c +7
-0+/* +* If there is no root domain; there is no balancing, and none of this +* matters. +*/ +if (!rq->rd) +return ; +What if the setup involves a separate root domain where all the CPUs are in dynticks mode?
Methinks the signal we want is:
is that task on a
NOHZ_FULLCPU with the tick disabled?
Quoted 8 lines
Quoted 5 lines
If so then we shouldn't do anything about it. Let the other CPUs in its LLC / RD run some balancing. If they're all dynticks, well then there is nothing to do is there?
And that should also apply to the NUMA stuff like you pointed out.
If you have a root domain with more than 1 CPU in it, you get balancing, deal with it.
I think I can live with that. It means we mandate complete CPU isolation for NOHZ_FULL to work, but then again that's what you should do in a sane setup.