Re: [PATCH v7 1/9] sched/fair: fix unfairness at wakeup

From: Chen Yu
Date: Sat Nov 05 2022 - 10:33:15 EST


On 2022-10-28 at 11:33:55 +0200, Vincent Guittot wrote:
[snip]
> +static inline unsigned long get_latency_max(void)
> +{
> + unsigned long thresh = get_sched_latency(false);
> +
> + thresh -= sysctl_sched_min_granularity;
> +
May I know why we substract sysctl_sched_min_granularity above?
I thought thresh -= 1 would be enough to let the waking task preempt
the current one, because:
When a long sleeping task is enqueued on this rq, its vruntime is set
to cfs_rq->min_vtime - latency, so
diff = curr->vtime - cfs_rq->min_vtime + latency,
since (curr->vtime - cfs_rq->min_vtime) >= 0, if we set the thresh to
(latency - 1), the diff is guaranteed to be bigger than thresh and
the waking task can preempt current task.

thanks,
Chenyu
> + return thresh;
> +}