Re: [PATCH 03/10] cpuidle: Report illegal tick stopped while polling

From: Rafael J. Wysocki
Date: Fri Aug 11 2023 - 13:38:10 EST


On Fri, Aug 11, 2023 at 7:01 PM Frederic Weisbecker <frederic@xxxxxxxxxx> wrote:
>
> poll_idle() can't be called while the tick is stopped because it enables
> interrupts and only polls on TIF_NEED_RESCHED, which doesn't tell if an
> interrupt queues a timer that would require a tick re-programming.
>
> There is no point anyway to poll with the tick stopped so add a check
> to make sure it never happens.

I'd rather update governors so they never use polling states when the
tick has been stopped and then add the WARN_ON().

> Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
> ---
> drivers/cpuidle/poll_state.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c
> index 9b6d90a72601..009f46f121ae 100644
> --- a/drivers/cpuidle/poll_state.c
> +++ b/drivers/cpuidle/poll_state.c
> @@ -7,6 +7,7 @@
> #include <linux/sched.h>
> #include <linux/sched/clock.h>
> #include <linux/sched/idle.h>
> +#include <linux/tick.h>
>
> #define POLL_IDLE_RELAX_COUNT 200
>
> @@ -19,6 +20,13 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev,
>
> dev->poll_time_limit = false;
>
> + /*
> + * This re-enables IRQs and only polls on TIF_NEED_RESCHED.
> + * A timer queued by an interrupt here may go unnoticed if
> + * the tick is stopped.
> + */
> + WARN_ON_ONCE(tick_nohz_tick_stopped());
> +
> raw_local_irq_enable();
> if (!current_set_polling_and_test()) {
> unsigned int loop_count = 0;
> --
> 2.34.1
>