[tip/core/rcu,02/12] timer: Report ignored local enqueue in nohz mode
diff mbox series

Message ID 20210304002311.23655-2-paulmck@kernel.org
State New, archived
Headers show
Series
  • NOCB updates for v5.13
Related show

Commit Message

Paul E. McKenney March 4, 2021, 12:23 a.m. UTC
From: Frederic Weisbecker <frederic@kernel.org>

Enqueuing a local timer after the tick has been stopped will result in
the timer being ignored until the next random interrupt.

Perform sanity checks to report these situations.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar<mingo@kernel.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 kernel/sched/core.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Rafael J. Wysocki March 4, 2021, 11:58 a.m. UTC | #1
On 3/4/2021 1:23 AM, paulmck@kernel.org wrote:
> From: Frederic Weisbecker <frederic@kernel.org>
>
> Enqueuing a local timer after the tick has been stopped will result in
> the timer being ignored until the next random interrupt.
>
> Perform sanity checks to report these situations.
>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar<mingo@kernel.org>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


> ---
>   kernel/sched/core.c | 24 +++++++++++++++++++++++-
>   1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ca2bb62..4822371 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -674,6 +674,26 @@ int get_nohz_timer_target(void)
>   	return cpu;
>   }
>   
> +static void wake_idle_assert_possible(void)
> +{
> +#ifdef CONFIG_SCHED_DEBUG
> +	/* Timers are re-evaluated after idle IRQs */
> +	if (in_hardirq())
> +		return;
> +	/*
> +	 * Same as hardirqs, assuming they are executing
> +	 * on IRQ tail. Ksoftirqd shouldn't reach here
> +	 * as the timer base wouldn't be idle. And inline
> +	 * softirq processing after a call to local_bh_enable()
> +	 * within idle loop sound too fun to be considered here.
> +	 */
> +	if (in_serving_softirq())
> +		return;
> +
> +	WARN_ON_ONCE("Late timer enqueue may be ignored\n");
> +#endif
> +}
> +
>   /*
>    * When add_timer_on() enqueues a timer into the timer wheel of an
>    * idle CPU then this timer might expire before the next timer event
> @@ -688,8 +708,10 @@ static void wake_up_idle_cpu(int cpu)
>   {
>   	struct rq *rq = cpu_rq(cpu);
>   
> -	if (cpu == smp_processor_id())
> +	if (cpu == smp_processor_id()) {
> +		wake_idle_assert_possible();
>   		return;
> +	}
>   
>   	if (set_nr_and_not_polling(rq->idle))
>   		smp_send_reschedule(cpu);
Paul E. McKenney March 4, 2021, 8:06 p.m. UTC | #2
On Thu, Mar 04, 2021 at 12:58:54PM +0100, Rafael J. Wysocki wrote:
> On 3/4/2021 1:23 AM, paulmck@kernel.org wrote:
> > From: Frederic Weisbecker <frederic@kernel.org>
> > 
> > Enqueuing a local timer after the tick has been stopped will result in
> > the timer being ignored until the next random interrupt.
> > 
> > Perform sanity checks to report these situations.
> > 
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar<mingo@kernel.org>
> > Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> 
> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Applied, thank you!

							Thanx, Paul

> > ---
> >   kernel/sched/core.c | 24 +++++++++++++++++++++++-
> >   1 file changed, 23 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index ca2bb62..4822371 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -674,6 +674,26 @@ int get_nohz_timer_target(void)
> >   	return cpu;
> >   }
> > +static void wake_idle_assert_possible(void)
> > +{
> > +#ifdef CONFIG_SCHED_DEBUG
> > +	/* Timers are re-evaluated after idle IRQs */
> > +	if (in_hardirq())
> > +		return;
> > +	/*
> > +	 * Same as hardirqs, assuming they are executing
> > +	 * on IRQ tail. Ksoftirqd shouldn't reach here
> > +	 * as the timer base wouldn't be idle. And inline
> > +	 * softirq processing after a call to local_bh_enable()
> > +	 * within idle loop sound too fun to be considered here.
> > +	 */
> > +	if (in_serving_softirq())
> > +		return;
> > +
> > +	WARN_ON_ONCE("Late timer enqueue may be ignored\n");
> > +#endif
> > +}
> > +
> >   /*
> >    * When add_timer_on() enqueues a timer into the timer wheel of an
> >    * idle CPU then this timer might expire before the next timer event
> > @@ -688,8 +708,10 @@ static void wake_up_idle_cpu(int cpu)
> >   {
> >   	struct rq *rq = cpu_rq(cpu);
> > -	if (cpu == smp_processor_id())
> > +	if (cpu == smp_processor_id()) {
> > +		wake_idle_assert_possible();
> >   		return;
> > +	}
> >   	if (set_nr_and_not_polling(rq->idle))
> >   		smp_send_reschedule(cpu);
> 
>

Patch
diff mbox series

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ca2bb62..4822371 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -674,6 +674,26 @@  int get_nohz_timer_target(void)
 	return cpu;
 }
 
+static void wake_idle_assert_possible(void)
+{
+#ifdef CONFIG_SCHED_DEBUG
+	/* Timers are re-evaluated after idle IRQs */
+	if (in_hardirq())
+		return;
+	/*
+	 * Same as hardirqs, assuming they are executing
+	 * on IRQ tail. Ksoftirqd shouldn't reach here
+	 * as the timer base wouldn't be idle. And inline
+	 * softirq processing after a call to local_bh_enable()
+	 * within idle loop sound too fun to be considered here.
+	 */
+	if (in_serving_softirq())
+		return;
+
+	WARN_ON_ONCE("Late timer enqueue may be ignored\n");
+#endif
+}
+
 /*
  * When add_timer_on() enqueues a timer into the timer wheel of an
  * idle CPU then this timer might expire before the next timer event
@@ -688,8 +708,10 @@  static void wake_up_idle_cpu(int cpu)
 {
 	struct rq *rq = cpu_rq(cpu);
 
-	if (cpu == smp_processor_id())
+	if (cpu == smp_processor_id()) {
+		wake_idle_assert_possible();
 		return;
+	}
 
 	if (set_nr_and_not_polling(rq->idle))
 		smp_send_reschedule(cpu);