Re: [PATCH] sched: Warn on long periods of pending need_resched

From: Ingo Molnar
Date: Wed Mar 17 2021 - 04:32:21 EST



* Josh Don <joshdon@xxxxxxxxxx> wrote:

> +static inline u64 resched_latency_check(struct rq *rq)
> +{
> + int latency_warn_ms = READ_ONCE(sysctl_resched_latency_warn_ms);
> + bool warn_only_once = (latency_warn_ms == RESCHED_DEFAULT_WARN_LATENCY_MS);
> + u64 need_resched_latency, now = rq_clock(rq);
> + static bool warned_once;
> +
> + if (warn_only_once && warned_once)
> + return 0;
> +
> + if (!need_resched() || latency_warn_ms < 2)
> + return 0;
> +
> + /* Disable this warning for the first few mins after boot */
> + if (now < RESCHED_BOOT_QUIET_SEC * NSEC_PER_SEC)
> + return 0;
> +
> + if (!rq->last_seen_need_resched_ns) {
> + rq->last_seen_need_resched_ns = now;
> + rq->ticks_without_resched = 0;
> + return 0;
> + }
> +
> + rq->ticks_without_resched++;

So AFAICS this will only really do something useful on full-nohz
kernels with sufficiently long scheduler ticks, right?

On other kernels the scheduler tick interrupt, when it returns to
user-space, will trigger a reschedule if it sees a need_resched.

Thanks,

Ingo