nohz: Move nohz kick out of scheduler IPI, v6
Subsystems (2)
cover nohz: Move nohz kick out of scheduler IPI, v6
This version implements separate lists for tick and IPI works. As such it simplifies the IPI raise decision.
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/nohz-irq-work-v4
Thanks,
Frederic
---
Frederic Weisbecker (5):
irq_work: Split raised and lazy lists
irq_work: Shorten a bit irq_work_needs_cpu()
irq_work: Implement remote queueing
nohz: Move full nohz kick to its own IPI
nohz: Use IPI implicit full barrier against rq->nr_running r/w
include/linux/irq_work.h | 2 ++ include/linux/tick.h | 9 +++++- kernel/irq_work.c | 74 +++++++++++++++++++++++++++--------------------- kernel/sched/core.c | 14 ++++----- kernel/sched/sched.h | 12 ++++++-- kernel/smp.c | 4 +++ kernel/time/tick-sched.c | 10 ++++--- 7 files changed, 76 insertions(+), 49 deletions(-)
PATCH 1/5 irq_work: Split raised and lazy lists
An irq work can be handled from two places: from the tick if the work carries the "lazy" flag and the tick is periodic, or from a self IPI.
We merge all these works in a single list and we use some per cpu latch to avoid raising a self-IPI when one is already pending.
Now we could do away with this ugly latch if only the list was only made of non-lazy works. Just enqueueing a work on the empty list would be enough to know if we need to raise an IPI or not.
Also we are going to implement remote irq work queuing. Then the per CPU latch will need to become atomic in the global scope. That's too bad because, here as well, just enqueueing a work on an empty list of non-lazy works would be enough to know if we need to raise an IPI or not.
So lets take a way out of this: split the works in two distinct lists, one for the works that can be handled by the next tick and another one for those handled by the IPI. Just checking if the latter is empty when we queue a new work is enough to know if we need to raise an IPI.
--- kernel/irq_work.c | 58 +++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 32 deletions(-)
kernel/irq_work.c +26 -32
@@ -19,8 +19,8 @@#include <asm/processor.h> -static DEFINE_PER_CPU(struct llist_head, irq_work_list); -static DEFINE_PER_CPU(int, irq_work_raised); +static DEFINE_PER_CPU(struct llist_head, raised_list); +static DEFINE_PER_CPU(struct llist_head, lazy_list);/* * Claim the entry so that no one else will poke at it.
@@ -63,26 +63,24 @@ void __weak arch_irq_work_raise(void)*/ bool irq_work_queue (struct irq_work *work) { +unsigned long flags; +/* Only queue if not already pending */ if (!irq_work_claim (work))return false; -/* Queue the entry and raise the IPI if needed. */ -preempt_disable (); +/* Check dynticks safely */ +local_irq_save (flags); -llist_add (&work->llnode, &__get_cpu_var (irq_work_list)); - -/* -* If the work is not "lazy" or the tick is stopped, raise the irq -* work interrupt (if supported by the arch), otherwise, just wait -* for the next tick. -*/ -if (!(work->flags &IRQ_WORK_LAZY ) ||tick_nohz_tick_stopped ()) { -if (!this_cpu_cmpxchg (irq_work_raised,0 ,1 )) +/* If the work is "lazy", handle it from next tick if any */ +if ((work->flags &IRQ_WORK_LAZY ) && !tick_nohz_tick_stopped ()) { +llist_add (&work->llnode, &__get_cpu_var (lazy_list)); + }else { +if (llist_add (&work->llnode, &__get_cpu_var (raised_list)))arch_irq_work_raise (); } -preempt_enable (); +local_irq_restore (flags);return true; }
@@ -90,10 +88,10 @@ EXPORT_SYMBOL_GPL(irq_work_queue);bool irq_work_needs_cpu (void ) { -struct llist_head *this_list; +struct llist_head *list; - this_list = &__get_cpu_var (irq_work_list); -if (llist_empty (this_list)) + list = &__get_cpu_var (lazy_list); +if (llist_empty (list))return false;/* All work should have been flushed before going offline */
@@ -102,28 +100,18 @@ bool irq_work_needs_cpu(void)return true; } -static void __irq_work_run (void ) +static void irq_work_run_list (struct llist_head *list) {unsigned long flags;struct irq_work *work; -struct llist_head *this_list;struct llist_node *llnode; - -/* -* Reset the "raised" state right before we check the list because -* an NMI may enqueue after we find the list empty from the runner. -*/ -__this_cpu_write (irq_work_raised,0 ); -barrier (); - - this_list = &__get_cpu_var (irq_work_list); -if (llist_empty (this_list)) -return ; -BUG_ON (!irqs_disabled ()); - llnode =llist_del_all (this_list); +if (llist_empty (list)) +return ; + + llnode =llist_del_all (list);while (llnode !=NULL ) { work = llist_entry(llnode, struct irq_work, llnode);
@@ -148,6 +136,12 @@ static void __irq_work_run(void) } } +static void __irq_work_run (void ) +{ +irq_work_run_list (&__get_cpu_var (raised_list)); +irq_work_run_list (&__get_cpu_var (lazy_list)); +} +/* * Run the irq_work entries on this cpu. Requires to be ran from hardirq * context with local IRQs disabled.
Signature · 1 line
1.8.3.1
Peter Zijlstra
maintainerRe: [PATCH 1/5] irq_work: Split raised and lazy lists
Quoted 15 lines · Frederic Weisbecker
An irq work can be handled from two places: from the tick if the work carries the "lazy" flag and the tick is periodic, or from a self IPI.
We merge all these works in a single list and we use some per cpu latch to avoid raising a self-IPI when one is already pending.
Now we could do away with this ugly latch if only the list was only made of non-lazy works. Just enqueueing a work on the empty list would be enough to know if we need to raise an IPI or not.
Also we are going to implement remote irq work queuing. Then the per CPU latch will need to become atomic in the global scope. That's too bad because, here as well, just enqueueing a work on an empty list of non-lazy works would be enough to know if we need to raise an IPI or not.
Quoted 4 lines
So lets take a way out of this: split the works in two distinct lists, one for the works that can be handled by the next tick and another one for those handled by the IPI. Just checking if the latter is empty when we queue a new work is enough to know if we need to raise an IPI.
That ^
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 73
Quoted 12 lines
bool
irq_work_queue(struct irq_work *work)
{kernel/irq_work.c +4
-2+unsigned long flags; +/* Only queue if not already pending */ if (!irq_work_claim (work))return false; -/* Queue the entry and raise the IPI if needed. */ -preempt_disable (); +/* Check dynticks safely */ +local_irq_save (flags);
Does not mention this ^
'sup?
Re: [PATCH 1/5] irq_work: Split raised and lazy lists
Quoted 31 lines · Peter Zijlstra
Quoted 15 lines · Frederic Weisbecker
An irq work can be handled from two places: from the tick if the work carries the "lazy" flag and the tick is periodic, or from a self IPI.
We merge all these works in a single list and we use some per cpu latch to avoid raising a self-IPI when one is already pending.
Now we could do away with this ugly latch if only the list was only made of non-lazy works. Just enqueueing a work on the empty list would be enough to know if we need to raise an IPI or not.
Also we are going to implement remote irq work queuing. Then the per CPU latch will need to become atomic in the global scope. That's too bad because, here as well, just enqueueing a work on an empty list of non-lazy works would be enough to know if we need to raise an IPI or not.
Quoted 4 lines
So lets take a way out of this: split the works in two distinct lists, one for the works that can be handled by the next tick and another one for those handled by the IPI. Just checking if the latter is empty when we queue a new work is enough to know if we need to raise an IPI.
That ^
Quoted 8 lines
bool
irq_work_queue(struct irq_work *work)
{kernel/irq_work.c +2
-0+unsigned long flags; +/* Only queue if not already pending */ if (!irq_work_claim (work))return false;
Quoted 8 lines
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 73
Quoted 4 lines
kernel/irq_work.c +2
-2-/* Queue the entry and raise the IPI if needed. */ -preempt_disable (); +/* Check dynticks safely */ +local_irq_save (flags);Does not mention this ^
'sup?
Because it's really just a technical detail.
If we enqueue before checking for tick stopped, we can avoid disabling irqs because it's fine if we just raced with an irq in-between.
But now that we enqueue _after_, we can't afford an IRQ in between.
Should I update the comments maybe?
Peter Zijlstra
maintainerRe: [PATCH 1/5] irq_work: Split raised and lazy lists
Quoted 41 lines · Frederic Weisbecker
Quoted 31 lines · Peter Zijlstra
Quoted 15 lines · Frederic Weisbecker
An irq work can be handled from two places: from the tick if the work carries the "lazy" flag and the tick is periodic, or from a self IPI.
We merge all these works in a single list and we use some per cpu latch to avoid raising a self-IPI when one is already pending.
Now we could do away with this ugly latch if only the list was only made of non-lazy works. Just enqueueing a work on the empty list would be enough to know if we need to raise an IPI or not.
Also we are going to implement remote irq work queuing. Then the per CPU latch will need to become atomic in the global scope. That's too bad because, here as well, just enqueueing a work on an empty list of non-lazy works would be enough to know if we need to raise an IPI or not.
Quoted 4 lines
So lets take a way out of this: split the works in two distinct lists, one for the works that can be handled by the next tick and another one for those handled by the IPI. Just checking if the latter is empty when we queue a new work is enough to know if we need to raise an IPI.
That ^
Quoted 8 lines
bool
irq_work_queue(struct irq_work *work)
{kernel/irq_work.c +2
-0+unsigned long flags; +/* Only queue if not already pending */ if (!irq_work_claim (work))return false;Quoted 8 lines
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 73
Quoted 4 lines
kernel/irq_work.c +2
-2-/* Queue the entry and raise the IPI if needed. */ -preempt_disable (); +/* Check dynticks safely */ +local_irq_save (flags);Does not mention this ^
'sup?
Quoted 7 lines
Because it's really just a technical detail.
If we enqueue before checking for tick stopped, we can avoid disabling irqs because it's fine if we just raced with an irq in-between.But now that we enqueue _after_, we can't afford an IRQ in between.
Should I update the comments maybe?
Well, yes because it was entirely non-obvious, but maybe we can write it such that we can avoid the irq disable, because they're expensive.
How about something like:
if (work->flags & IRQ_WORK_LAZY) {
if (llist_add(&work->llnode, __get_cpu_var(lazy_list)) &&
tick_nohz_tick_stopped())
arch_irq_work_raise();
} else {
if (llist_add(&work->llnode, __get_cpu_var(raise_list)))
arch_irq_work_raise();
}That way we check it after the enqueue.
Re: [PATCH 1/5] irq_work: Split raised and lazy lists
Quoted 64 lines · Peter Zijlstra
Quoted 41 lines · Frederic Weisbecker
Quoted 31 lines · Peter Zijlstra
Quoted 15 lines · Frederic Weisbecker
An irq work can be handled from two places: from the tick if the work carries the "lazy" flag and the tick is periodic, or from a self IPI.
We merge all these works in a single list and we use some per cpu latch to avoid raising a self-IPI when one is already pending.
Now we could do away with this ugly latch if only the list was only made of non-lazy works. Just enqueueing a work on the empty list would be enough to know if we need to raise an IPI or not.
Also we are going to implement remote irq work queuing. Then the per CPU latch will need to become atomic in the global scope. That's too bad because, here as well, just enqueueing a work on an empty list of non-lazy works would be enough to know if we need to raise an IPI or not.
Quoted 4 lines
So lets take a way out of this: split the works in two distinct lists, one for the works that can be handled by the next tick and another one for those handled by the IPI. Just checking if the latter is empty when we queue a new work is enough to know if we need to raise an IPI.
That ^
Quoted 8 lines
bool
irq_work_queue(struct irq_work *work)
{kernel/irq_work.c +2
-0+unsigned long flags; +/* Only queue if not already pending */ if (!irq_work_claim (work))return false;Quoted 8 lines
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 73
Quoted 4 lines
kernel/irq_work.c +2
-2-/* Queue the entry and raise the IPI if needed. */ -preempt_disable (); +/* Check dynticks safely */ +local_irq_save (flags);Does not mention this ^
'sup?
Quoted 7 lines
Because it's really just a technical detail.
If we enqueue before checking for tick stopped, we can avoid disabling irqs because it's fine if we just raced with an irq in-between.But now that we enqueue _after_, we can't afford an IRQ in between.
Should I update the comments maybe?
Well, yes because it was entirely non-obvious, but maybe we can write it such that we can avoid the irq disable, because they're expensive.
How about something like:
if (work->flags & IRQ_WORK_LAZY) { if (llist_add(&work->llnode, __get_cpu_var(lazy_list)) && tick_nohz_tick_stopped()) arch_irq_work_raise(); } else { if (llist_add(&work->llnode, __get_cpu_var(raise_list))) arch_irq_work_raise(); }
Quoted 1 line
That way we check it after the enqueue.
Hmm, ok.
PATCH 2/5 irq_work: Shorten a bit irq_work_needs_cpu()
In reply to Frederic WeisbeckerJust a small cleanup.
--- kernel/irq_work.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/irq_work.c +1 -4
@@ -88,10 +88,7 @@ EXPORT_SYMBOL_GPL(irq_work_queue);bool irq_work_needs_cpu (void ) { -struct llist_head *list; - - list = &__get_cpu_var (lazy_list); -if (llist_empty (list)) +if (llist_empty (&__get_cpu_var (lazy_list)))return false;/* All work should have been flushed before going offline */
Signature · 1 line
1.8.3.1
PATCH 3/5 irq_work: Implement remote queueing
In reply to Frederic Weisbeckerirq work currently only supports local callbacks. However its code is mostly ready to run remote callbacks and we have some potential user.
The full nohz subsystem currently open codes its own remote irq work on top of the scheduler ipi when it wants a CPU to reevaluate its next tick. However this ad hoc solution bloats the scheduler IPI.
Lets just extend the irq work subsystem to support remote queuing on top of the generic SMP IPI to handle this kind of user. This shouldn't add noticeable overhead.
--- include/linux/irq_work.h | 2 ++ kernel/irq_work.c | 19 ++++++++++++++++++- kernel/smp.c | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-)
include/linux/irq_work.h +2 -0
@@ -33,6 +33,8 @@ void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))#define DEFINE_IRQ_WORK (name, _f) struct irq_work name = { .func = (_f), }bool irq_work_queue (struct irq_work *work); +bool irq_work_queue_on (struct irq_work *work,int cpu); +void irq_work_run (void );void irq_work_sync (struct irq_work *work);
kernel/irq_work.c +18 -1
@@ -56,11 +56,28 @@ void __weak arch_irq_work_raise(void) }/* -* Enqueue the irq_work @entry unless it's already pending +* Enqueue the irq_work @work on @cpu unless it's already pending * somewhere. * * Can be re-enqueued while the callback is still in progress. */ +bool irq_work_queue_on (struct irq_work *work,int cpu) +{ +/* Only queue if not already pending */ +if (!irq_work_claim (work)) +return false; + +/* All work should have been flushed before going offline */ +WARN_ON_ONCE (cpu_is_offline (cpu)); + +if (llist_add (&work->llnode, &per_cpu (raised_list, cpu))) +native_send_call_func_single_ipi (cpu); + +return true; +} +EXPORT_SYMBOL_GPL (irq_work_queue_on); + +/* Enqueue the irq work @work on the current CPU */ bool irq_work_queue (struct irq_work *work) {unsigned long flags;
kernel/smp.c +4 -0
@@ -3,6 +3,7 @@* * (C) Jens Axboe <[email protected]> 2008 */ +#include <linux/irq_work.h> #include <linux/rcupdate.h> #include <linux/rculist.h> #include <linux/kernel.h>
@@ -198,6 +199,9 @@ void generic_smp_call_function_single_interrupt(void) csd->func (csd->info);csd_unlock (csd); } + +/* Handle irq works queued remotely by irq_work_queue_on() */ +irq_work_run (); }/*
Signature · 1 line
1.8.3.1
Peter Zijlstra
maintainerRe: [PATCH 3/5] irq_work: Implement remote queueing
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 71
Quoted 8 lines · Frederic Weisbecker
kernel/irq_work.c +8
-0+bool irq_work_queue_on (struct irq_work *work,int cpu) +{ +/* Only queue if not already pending */ +if (!irq_work_claim (work)) +return false; + +/* All work should have been flushed before going offline */ +WARN_ON_ONCE (cpu_is_offline (cpu));
WARN_ON_ONCE(in_nmi());
Also, I would do both these checks before the claim thing.
Quoted 7 lines
kernel/irq_work.c +7
-0+ +if (llist_add (&work->llnode, &per_cpu (raised_list, cpu))) +native_send_call_func_single_ipi (cpu); + +return true; +} +EXPORT_SYMBOL_GPL (irq_work_queue_on);
Re: [PATCH 3/5] irq_work: Implement remote queueing
Quoted 10 lines · Peter Zijlstra
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 71
Quoted 8 lines · Frederic Weisbecker
kernel/irq_work.c +8
-0+bool irq_work_queue_on (struct irq_work *work,int cpu) +{ +/* Only queue if not already pending */ +if (!irq_work_claim (work)) +return false; + +/* All work should have been flushed before going offline */ +WARN_ON_ONCE (cpu_is_offline (cpu));WARN_ON_ONCE(in_nmi());
But it's actually NMI safe, isn't it?
Quoted 3 lines
Also, I would do both these checks before the claim thing.
Right, I'll move the check.
Quoted 10 lines
Quoted 8 lines
kernel/irq_work.c +7
-0+ +if (llist_add (&work->llnode, &per_cpu (raised_list, cpu))) +native_send_call_func_single_ipi (cpu); + +return true; +} +EXPORT_SYMBOL_GPL (irq_work_queue_on);
Peter Zijlstra
maintainerRe: [PATCH 3/5] irq_work: Implement remote queueing
Quoted 12 lines · Frederic Weisbecker
Quoted 10 lines · Peter Zijlstra
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 71
Quoted 8 lines · Frederic Weisbecker
kernel/irq_work.c +8
-0+bool irq_work_queue_on (struct irq_work *work,int cpu) +{ +/* Only queue if not already pending */ +if (!irq_work_claim (work)) +return false; + +/* All work should have been flushed before going offline */ +WARN_ON_ONCE (cpu_is_offline (cpu));WARN_ON_ONCE(in_nmi());
Quoted 1 line
But it's actually NMI safe, isn't it?
Deja-vu:
lkml.kernel.org/r/[email protected]
Re: [PATCH 3/5] irq_work: Implement remote queueing
Quoted 13 lines · Peter Zijlstra
Quoted 12 lines · Frederic Weisbecker
Quoted 10 lines · Peter Zijlstra
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 71
Quoted 8 lines · Frederic Weisbecker
kernel/irq_work.c +8
-0+bool irq_work_queue_on (struct irq_work *work,int cpu) +{ +/* Only queue if not already pending */ +if (!irq_work_claim (work)) +return false; + +/* All work should have been flushed before going offline */ +WARN_ON_ONCE (cpu_is_offline (cpu));WARN_ON_ONCE(in_nmi());
Quoted 5 lines
Quoted 1 line
But it's actually NMI safe, isn't it?
Deja-vu:
lkml.kernel.org/r/[email protected]
Doh!
PATCH 4/5 nohz: Move full nohz kick to its own IPI
In reply to Frederic WeisbeckerNow that the irq work subsystem can queue remote callbacks, it's a perfect fit to safely queue IPIs when interrupts are disabled without worrying about concurrent callers.
Lets use it for the full dynticks kick to notify a CPU that it's exiting single task mode.
This unbloats a bit the scheduler IPI that the nohz code was abusing for its cool "callable anywhere/anytime" properties.
--- include/linux/tick.h | 9 ++++++++- kernel/sched/core.c | 5 +---- kernel/sched/sched.h | 2 +- kernel/time/tick-sched.c | 10 ++++++---- 4 files changed, 16 insertions(+), 10 deletions(-)
include/linux/tick.h +8 -1
@@ -181,7 +181,13 @@ static inline bool tick_nohz_full_cpu(int cpu)extern void tick_nohz_init (void );extern void __tick_nohz_full_check (void ); -extern void tick_nohz_full_kick (void ); +extern void tick_nohz_full_kick_cpu (int cpu); + +static inline void tick_nohz_full_kick (void ) +{ +tick_nohz_full_kick_cpu (smp_processor_id ()); +} +extern void tick_nohz_full_kick_all (void );extern void __tick_nohz_task_switch (struct task_struct *tsk);#else
@@ -189,6 +195,7 @@ static inline void tick_nohz_init(void) { }static inline bool tick_nohz_full_enabled (void ) {return false; }static inline bool tick_nohz_full_cpu (int cpu) {return false; }static inline void __tick_nohz_full_check (void ) { } +static inline void tick_nohz_full_kick_cpu (int cpu) { }static inline void tick_nohz_full_kick (void ) { }static inline void tick_nohz_full_kick_all (void ) { }static inline void __tick_nohz_task_switch (struct task_struct *tsk) { }
kernel/sched/core.c +1 -4
@@ -1500,9 +1500,7 @@ void scheduler_ipi(void)*/ preempt_fold_need_resched (); -if (llist_empty (&this_rq ()->wake_list) - && !tick_nohz_full_cpu (smp_processor_id ()) - && !got_nohz_idle_kick ()) +if (llist_empty (&this_rq ()->wake_list) && !got_nohz_idle_kick ())return ;/*
@@ -1519,7 +1517,6 @@ void scheduler_ipi(void)* somewhat pessimize the simple resched case. */ irq_enter (); -tick_nohz_full_check ();sched_ttwu_pending ();/*
kernel/sched/sched.h +1 -1
@@ -1225,7 +1225,7 @@ static inline void inc_nr_running(struct rq *rq)if (tick_nohz_full_cpu (rq->cpu)) {/* Order rq->nr_running write against the IPI */ smp_wmb (); -smp_send_reschedule (rq->cpu); +tick_nohz_full_kick_cpu (rq->cpu); } }#endif
kernel/time/tick-sched.c +6 -4
@@ -224,13 +224,15 @@ static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = { };/* -* Kick the current CPU if it's full dynticks in order to force it to +* Kick the CPU if it's full dynticks in order to force it to * re-evaluate its dependency on the tick and restart it if necessary. */ -void tick_nohz_full_kick (void ) +void tick_nohz_full_kick_cpu (int cpu) { -if (tick_nohz_full_cpu (smp_processor_id ())) -irq_work_queue (&__get_cpu_var (nohz_full_kick_work)); +if (!tick_nohz_full_cpu (cpu)) +return ; + +irq_work_queue_on (&per_cpu (nohz_full_kick_work, cpu), cpu); }static void nohz_full_kick_ipi (void *info)
Signature · 1 line
1.8.3.1
PATCH 5/5 nohz: Use IPI implicit full barrier against rq->nr_running r/w
In reply to Frederic WeisbeckerA full dynticks CPU is allowed to stop its tick when a single task runs. Meanwhile when a new task gets enqueued, the CPU must be notified so that it can restart its tick to maintain local fairness and other accounting details.
This notification is performed by way of an IPI. Then when the target receives the IPI, we expect it to see the new value of rq->nr_running.
Hence the following ordering scenario:
CPU 0 CPU 1
write rq->running get IPI smp_wmb() smp_rmb() send IPI read rq->nr_running
But Paul Mckenney says that nowadays IPIs imply a full barrier on all architectures. So we can safely remove this pair and rely on the implicit barriers that come along IPI send/receive. Lets just comment on this new assumption.
--- kernel/sched/core.c | 9 +++++---- kernel/sched/sched.h | 10 ++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-)
kernel/sched/core.c +5 -4
@@ -670,10 +670,11 @@ bool sched_can_stop_tick(void) rq =this_rq (); -/* Make sure rq->nr_running update is visible after the IPI */ -smp_rmb (); - -/* More than one running task need preemption */ +/* +* More than one running task need preemption. +* nr_running update is assumed to be visible +* after IPI is sent from wakers. +*/ if (rq->nr_running >1 )return false;
kernel/sched/sched.h +8 -2
@@ -1223,8 +1223,14 @@ static inline void inc_nr_running(struct rq *rq)#ifdef CONFIG_NO_HZ_FULL if (rq->nr_running ==2 ) {if (tick_nohz_full_cpu (rq->cpu)) { -/* Order rq->nr_running write against the IPI */ -smp_wmb (); +/* +* Tick is needed if more than one task runs on a CPU. +* Send the target an IPI to kick it out of nohz mode. +* +* We assume that IPI implies full memory barrier and the +* new value of rq->nr_running is visible on reception +* from the target. +*/ tick_nohz_full_kick_cpu (rq->cpu); } }
Signature · 1 line
1.8.3.1