mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Elif Topuz <elif.topuz@arm.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	kprateek.nayak@amd.com, linux-kernel@vger.kernel.org,
	lukasz.luba@arm.com, rafael@kernel.org, linux-pm@vger.kernel.org,
	tj@kernel.org, void@manifault.com, arighi@nvidia.com,
	changwoo@igalia.com, sched-ext@lists.linux.dev,
	qyousef@layalina.io, christian.loehle@arm.com,
	pierre.gondois@arm.com, sshegde@linux.ibm.com,
	kayracizmeci@gmail.com, tim.c.chen@linux.intel.com,
	elif.topuz@arm.com
Subject: Re: [PATCH 01/20 v3] sched/eevdf: Decay positive lag of sleeping entities
Date: Tue, 24 Nov 2026 15:13:14 +0000	[thread overview]
Message-ID: <50f73e24-bf40-4fcf-a232-8747087ddbeb@arm.com> (raw)
In-Reply-To: <20261106151947.3991524-2-vincent.guittot@linaro.org>

Hi Vincent,

On 06/11/2026 15:19, Vincent Guittot wrote:
> Similarly to delayed dequeue, which enables an entity to decay its negative
> lag while sleeping, a task should not keep a positive lag forever.
> 
> The sleep duration and the weight are used to decay the positive lag at
> wakeup.
> 
> Apply the decay when enqueueing on prev rq for which we hold the lock to
> get rq_clock_task().
> 
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
>  kernel/sched/fair.c | 124 ++++++++++++++++++++++++++++++++------------
>  1 file changed, 90 insertions(+), 34 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 0feec172fd37..5cd171f830d8 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -897,6 +897,91 @@ bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
>  	return avruntime - vlag != se->vruntime;
>  }
>  
> +/*
> + * Signed add and clamp on underflow.
> + *
> + * Explicitly do a load-store to ensure the intermediate value never hits
> + * memory. This allows lockless observations without ever seeing the negative
> + * values.
> + */
> +#define add_positive(_ptr, _val) do {                           \
> +	typeof(_ptr) ptr = (_ptr);                              \
> +	__signed_scalar_typeof(*ptr) val = (_val);              \
> +	typeof(*ptr) res, var = READ_ONCE(*ptr);                \
> +								\
> +	res = var + val;                                        \
> +								\
> +	if (val < 0 && res > var)                               \
> +		res = 0;                                        \
> +								\
> +	WRITE_ONCE(*ptr, res);                                  \
> +} while (0)
> +
> +/*
> + * Remove and clamp on negative, from a local variable.
> + *
> + * A variant of sub_positive(), which does not use explicit load-store
> + * and is thus optimized for local variable updates.
> + */
> +#define lsub_positive(_ptr, _val) do {				\
> +	typeof(_ptr) ptr = (_ptr);				\
> +	*ptr -= min_t(typeof(*ptr), *ptr, _val);		\
> +} while (0)
> +
> +static inline unsigned long cfs_rq_load_avg(struct cfs_rq *cfs_rq);
> +static unsigned long task_h_load(struct task_struct *p);
> +
> +static __always_inline
> +void decay_entity_lag(struct cfs_rq *cfs_rq, struct task_struct *p, int flags)
> +{
> +	struct sched_entity *se = &p->se;
> +	s64 delta_exec, vlag = se->vlag;
> +	unsigned long cfs_load;
> +	struct rq *rq;
> +
> +	WARN_ON_ONCE(se->on_rq);
> +
> +	/* Negative lag is managed by delayed dequeue path */
> +	if (vlag <= 0)
> +		return;
> +
> +	rq = rq_of(cfs_rq);
> +
> +	/* No fast access to prev rq task clock */
> +	if (flags & ENQUEUE_MIGRATED)
> +		return;
> +
> +	/* Compute sleep time */
> +	delta_exec = rq_clock_task(rq) - se->exec_start;
> +	if (unlikely(delta_exec <= 0))
> +		return;
> +
> +	/* For anything above ~4 seconds, save computation and clear the lag */
> +	if (unlikely(delta_exec >> 32)) {
> +		se->vlag = 0;
> +		return;
> +	}
> +
> +	/*
> +	 * Use cfs' load and p's weight to estimate what would have been the
> +	 * share for p. task's load contribution to cfs' load is replaced by
> +	 * its weight.
> +	 */
> +	cfs_load = cfs_rq_load_avg(cfs_rq);
> +	lsub_positive(&cfs_load, task_h_load(p));
> +	if (cfs_load) {
> +		unsigned long weight = scale_load_down(se->h_load.weight);
> +
> +		delta_exec *= weight;
> +		delta_exec = div64_long(delta_exec, cfs_load + weight);
> +	}
> +
> +	vlag -= calc_delta_fair(delta_exec, se);
> +
> +	/* vlag can't become neg while sleeping */
> +	se->vlag = max(0, vlag);
> +}
> +
>  /*
>   * Entity is eligible once it received less service than it ought to have,
>   * eg. lag >= 0.
> @@ -4693,38 +4778,6 @@ account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
>  	cfs_rq->nr_queued--;
>  }
>  
> -/*
> - * Signed add and clamp on underflow.
> - *
> - * Explicitly do a load-store to ensure the intermediate value never hits
> - * memory. This allows lockless observations without ever seeing the negative
> - * values.
> - */
> -#define add_positive(_ptr, _val) do {                           \
> -	typeof(_ptr) ptr = (_ptr);                              \
> -	__signed_scalar_typeof(*ptr) val = (_val);              \
> -	typeof(*ptr) res, var = READ_ONCE(*ptr);                \
> -								\
> -	res = var + val;                                        \
> -								\
> -	if (val < 0 && res > var)                               \
> -		res = 0;                                        \
> -								\
> -	WRITE_ONCE(*ptr, res);                                  \
> -} while (0)
> -
> -/*
> - * Remove and clamp on negative, from a local variable.
> - *
> - * A variant of sub_positive(), which does not use explicit load-store
> - * and is thus optimized for local variable updates.
> - */
> -#define lsub_positive(_ptr, _val) do {				\
> -	typeof(_ptr) ptr = (_ptr);				\
> -	*ptr -= min_t(typeof(*ptr), *ptr, _val);		\
> -} while (0)
> -
> -
>  /*
>   * Because of rounding, se->util_sum might ends up being +1 more than
>   * cfs->util_sum. Although this is not a problem by itself, detaching
> @@ -8152,7 +8205,7 @@ static void
>  enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
>  {
>  	int rq_h_nr_queued = rq->cfs.h_nr_queued;
> -	int task_new = !(flags & ENQUEUE_WAKEUP);
> +	int task_wake = flags & ENQUEUE_WAKEUP;
>  	struct sched_entity *se = &p->se;
>  	struct cfs_rq *cfs_rq = &rq->cfs;
>  	unsigned long weight;
> @@ -8185,6 +8238,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
>  	if (p->in_iowait)
>  		cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT);
>  
> +	if (task_wake)
> +		decay_entity_lag(cfs_rq, p, flags);
> +
>  	curr = (cfs_rq->curr == se);
>  	/*
>  	 * This can actually happen with CFS_BANDWIDTH, a task can be throttled
> @@ -8225,7 +8281,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
>  	 * into account, but that is not straightforward to implement,
>  	 * and the following generally works well enough in practice.
>  	 */
> -	if (!task_new)
> +	if (task_wake)
>  		check_update_overutilized_status(rq);
>  
>  	assert_list_leaf_cfs_rq(rq);

I have tested the patchset with cyclictest and rtapp like you mentioned in your
cover letter. I have used Ampere Altra with 160 cpus.

I run these sets:
- cyclictest with a 3777 us period and default slice with 2xNR_CPUS rt-app tasks
that run continuously with default slice.
- cyclictest with a 3777 us period and 8ms slice with 2xNR_CPUS rt-app tasks
that run continuously with a 16ms slice.
- cyclictest with a 3777 us period and default slice with 2xNR_CPUS rt-app tasks
run periodically with default slice.
- cyclictest with a 3777 us period and 8ms slice with 2xNR_CPUS rt-app tasks run
periodically with a 16ms slice.
I have also run them 130 seconds.

Cases with continuous rt-app:

| Kernel   | Slice   |   Samples |   P50 |   P90 |   P99 |   P99.9 |   Max |
|:---------|:--------|----------:|------:|------:|------:|--------:|------:|
| base     | Default |     34403 |    53 |    54 |    56 |     287 |  3996 |
| patch    | Default |     26748 |  1979 |  5637 |  7119 |    9264 | 10895 |
| base     | 8/16 ms |     34406 |    53 |    54 |    56 |     269 | 11880 |
| patch    | 8/16 ms |     34256 |    53 |    54 |    62 |    9126 | 15429 |

Percentage differences:
                                        base |                  patch
slice                                default |                default
99th Percentile                           56 |         7119 (-12612%)
99.9th Percentile                        287 |          9264 (-3128%)
Maximum                                 3996 |          10895 (-173%)

                                        base |                  patch
slice                               8ms/16ms |               8ms/16ms
99th Percentile                           56 |              62 (-11%)
99.9th Percentile                        269 |          9126 (-3293%)
Maximum                                11880 |           15429 (-30%)


Cases with periodic rt-app:

| Kernel   | Slice   |   Samples |   P50 |   P90 |   P99 |   P99.9 |   Max |
|:---------|:--------|----------:|------:|------:|------:|--------:|------:|
| base     | Default |     33795 |    56 |   901 |  4366 |    6156 |  9039 |
| patch    | Default |     33081 |    60 |  2734 |  5055 |    6395 |  9165 |
| base     | 8/16 ms |     34419 |    56 |    61 |    86 |     291 |   554 |
| patch    | 8/16 ms |     34419 |    56 |    59 |    77 |     161 |   540 |

Percentage differences:
                                        base |                  patch
slice                                default |                default
99th Percentile                         4366 |            5055 (-16%)
99.9th Percentile                       6156 |             6395 (-4%)
Maximum                                 9039 |             9165 (-1%)

                                        base |                  patch
slice                               8ms/16ms |               8ms/16ms
99th Percentile                           86 |              77 (+10%)
99.9th Percentile                        291 |             161 (+45%)
Maximum                                  554 |              540 (+3%)

With the periodic rt-app the difference between base and patches are lower, and
using custom slices I can see the improvement. However, when using continuous
rt-app, especially with the default slice case, I see the worst latency. I have
noticed that this difference is coming from "decay_entity_lag()". If I
understand correctly, most of the time cyclictest's lag reduced to zero after
decay_entity_lag(), and it cannot preempt the rt-app tasks.

I have also run hackbench with continuous NR_CPUS rt-app tasks with default
slices and custom slices (hackbench with a 8ms slice and rt-app with a 16ms
slice). Both threads-pipe and process-pipe for g=1 and f=160 gave around 50%
worst execution time with default slice. When using custom slice, this
difference is much lower.

Default slice:
MODE    IPC      G  FD |    Base(s)/CV |   Patch(s)/CV |   diff%
----------------------------------------------------------------
process pipe     1  10 |   0.172/10.9% |   0.077/25.6% |  +55.4%
process pipe     1  20 |    0.409/6.7% |   0.558/18.9% |  -36.6%
process pipe     1  40 |   1.145/23.1% |   2.176/15.1% |  -90.1%
process pipe     1  80 |    5.326/7.5% |    7.248/8.6% |  -36.1%
process pipe     1 160 |   14.105/4.5% |   21.404/6.1% |  -51.7%
process socket   1  10 |  0.055/113.9% |   0.176/35.8% | -221.8%
process socket   1  20 |    0.467/3.5% |   0.454/21.0% |   +2.9%
process socket   1  40 |    1.014/5.6% |    1.062/5.4% |   -4.6%
process socket   1  80 |   2.584/10.8% |   2.820/16.9% |   -9.1%
process socket   1 160 |    6.786/7.7% |   7.525/13.1% |  -10.9%
threads pipe     1  10 |   0.050/10.9% |   0.148/14.5% | -198.0%
threads pipe     1  20 |   0.283/65.4% |   0.650/10.1% | -129.2%
threads pipe     1  40 |   1.285/53.5% |    2.269/7.9% |  -76.5%
threads pipe     1  80 |    5.702/5.7% |    7.727/8.2% |  -35.5%
threads pipe     1 160 |   14.412/5.7% |   22.659/8.4% |  -57.2%
threads socket   1  10 |   0.218/13.2% |   0.237/23.6% |   -9.1%
threads socket   1  20 |    0.528/3.3% |    0.533/6.3% |   -1.0%
threads socket   1  40 |    1.085/2.7% |   1.269/20.3% |  -17.0%
threads socket   1  80 |    2.549/8.0% |   3.258/22.7% |  -27.8%
threads socket   1 160 |    7.241/7.0% |   7.909/12.3% |   -9.2%

Custom slice:
MODE    IPC      G  FD |    Base(s)/CV |   Patch(s)/CV |   diff%
----------------------------------------------------------------
process pipe     1  10 |   0.053/54.7% |   0.040/40.9% |  +25.6%
process pipe     1  20 |   0.373/48.3% |   0.318/13.1% |  +14.7%
process pipe     1  40 |   1.130/40.4% |   1.704/23.1% |  -50.8%
process pipe     1  80 |   4.570/14.0% |   3.558/15.2% |  +22.2%
process pipe     1 160 |  11.877/10.9% |  13.374/17.3% |  -12.6%
process socket   1  10 |   0.068/15.1% |   0.095/34.8% |  -39.5%
process socket   1  20 |    0.222/8.1% |    0.278/2.1% |  -25.2%
process socket   1  40 |    0.716/2.7% |    0.660/4.6% |   +7.8%
process socket   1  80 |    3.261/9.6% |    1.768/5.7% |  +45.8%
process socket   1 160 |    8.099/3.9% |    6.134/9.7% |  +24.3%
threads pipe     1  10 |   0.048/31.6% |   0.060/29.8% |  -26.1%
threads pipe     1  20 |   0.264/15.0% |   0.232/17.2% |  +12.0%
threads pipe     1  40 |   0.838/20.9% |   1.558/25.6% |  -86.0%
threads pipe     1  80 |   5.794/15.9% |   3.933/23.3% |  +32.1%
threads pipe     1 160 |   14.666/7.7% |  12.614/16.4% |  +14.0%
threads socket   1  10 |   0.068/14.2% |   0.111/27.1% |  -62.7%
threads socket   1  20 |    0.232/8.2% |   0.334/12.1% |  -43.9%
threads socket   1  40 |    0.753/5.9% |   0.983/14.5% |  -30.5%
threads socket   1  80 |    3.655/6.3% |   2.585/21.5% |  +29.3%
threads socket   1 160 |    8.959/4.6% |    8.628/3.8% |   +3.7%

I have also used g=[1, 4, 8, 16] and f=20, but didn't see much difference
between the base and the patchset.

Thanks,
Elif


  parent reply	other threads:[~2026-11-24 15:13 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 15:19 [PATCH 00/18 v3] Improving latency of short slice tasks Vincent Guittot
2026-11-06 15:19 ` [PATCH 01/20 v3] sched/eevdf: Decay positive lag of sleeping entities Vincent Guittot
2026-11-16 13:57   ` Kayra Cizmeci
2026-11-18  9:20     ` Vincent Guittot
2026-11-18 10:58       ` Kayra Cizmeci
2026-11-18 11:21         ` Vincent Guittot
2026-11-18 12:32           ` Kayra Cizmeci
2026-11-24 15:13   ` Elif Topuz [this message]
2026-11-06 15:19 ` [PATCH 02/20 v3] sched/eevdf: Reset lag at wakeup when prev CPU has been idle Vincent Guittot
2026-11-06 16:22   ` Kayra Cizmeci
2026-11-09 15:27     ` Vincent Guittot
2026-11-09 15:45       ` Peter Zijlstra
2026-11-09 16:27         ` Vincent Guittot
2026-11-11  9:03           ` Peter Zijlstra
2026-11-12  7:02             ` Vincent Guittot
2026-11-11 10:04   ` K Prateek Nayak
2026-11-12  7:33     ` Vincent Guittot
2026-11-06 15:19 ` [PATCH 03/20 v3] sched/eevdf: Reset lag at wakeup when migrating and prev " Vincent Guittot
2026-11-06 18:05   ` Kayra Cizmeci
2026-11-06 15:19 ` [PATCH 04/20 v3] sched/eevdf: Reset lag when waking up on idle cpu Vincent Guittot
2026-11-06 18:39   ` Kayra Cizmeci
2026-11-06 15:19 ` [PATCH 05/20 v3] sched/eevdf: Add per cpu cached min_slice Vincent Guittot
2026-11-07  6:53   ` Kayra Cizmeci
2026-11-09 15:27     ` Vincent Guittot
2026-11-06 15:19 ` [PATCH 06/20 v3] sched/eevdf: Add min slice check when selecting CPU Vincent Guittot
2026-11-07  8:57   ` Kayra Cizmeci
2026-11-09 13:55     ` Peter Zijlstra
2026-11-09 14:15       ` Kayra Cizmeci
2026-11-09 15:37         ` Vincent Guittot
2026-11-09 15:34     ` Vincent Guittot
2026-11-09 15:55     ` Vincent Guittot
2026-11-09 19:56       ` Kayra Cizmeci
2026-11-10 13:32         ` Vincent Guittot
2026-11-06 15:19 ` [PATCH 07/20 v3] sched/fair: Prepare select_task_rq_fair() to be called for new cases Vincent Guittot
2026-11-06 15:19 ` [PATCH 08/20 v3] sched/fair: Add push task mechanism for fair Vincent Guittot
2026-11-09 14:43   ` Peter Zijlstra
2026-11-09 16:07     ` Vincent Guittot
2026-11-11  8:59       ` Peter Zijlstra
2026-11-12  7:01         ` Vincent Guittot
2026-11-09 15:54   ` Peter Zijlstra
2026-11-09 16:14     ` Vincent Guittot
2026-11-11  9:01       ` Peter Zijlstra
2026-11-12  7:01         ` Vincent Guittot
2026-11-12  7:36           ` Vincent Guittot
2026-11-12  9:49           ` Peter Zijlstra
2026-11-12 11:29             ` Vincent Guittot
2026-11-12 12:19               ` Peter Zijlstra
2026-11-13  8:47   ` Li kunyu
2026-11-13  9:06     ` Vincent Guittot
2026-11-06 15:19 ` [PATCH 09/20 v3] sched/fair: Optimize " Vincent Guittot
2026-11-06 15:19 ` [PATCH 10/20 v3] sched/core: Add rq flag to tick parameters Vincent Guittot
2026-11-06 15:19 ` [PATCH 11/20 v3] sched/fair: Add force push task mechanism for fair Vincent Guittot
2026-11-06 15:19 ` [PATCH 12/20 v3] sched/fair: Support not wakeup case in select_idle_sibling Vincent Guittot
2026-11-13  5:31   ` kernel test robot
2026-11-06 15:19 ` [PATCH 13/20] sched/eevdf: Try to push short slice task on a better CPU Vincent Guittot
2026-11-13  9:25   ` Li kunyu
2026-11-13 10:49     ` Vincent Guittot
2026-11-13 11:20       ` Li kunyu
2026-11-06 15:19 ` [PATCH 14/20 v3] sched/eevdf: Push short slice task that are not picked Vincent Guittot
2026-11-06 15:19 ` [PATCH 15/20 v3] sched/fair: Enable push task for preempt short Vincent Guittot
2026-11-06 15:19 ` [PATCH 16/20 v3] energy model: Add a get previous state function Vincent Guittot
2026-11-10 19:55   ` Rafael J. Wysocki (Intel)
2026-11-06 15:19 ` [PATCH 17/20 v3] sched/fair: Rework feec() to use cost instead of spare capacity Vincent Guittot
2026-11-06 15:19 ` [PATCH 18/20 v3] energy model: Remove unused em_cpu_energy() Vincent Guittot
2026-11-06 15:19 ` [PATCH 19/20 v3] sched/fair: Take into account slice in EAS Vincent Guittot
2026-11-06 15:19 ` [PATCH 20/20 v3] sched/fair: Fix tasks stacking on same idle CPU Vincent Guittot
2026-11-23 14:05 ` [PATCH 00/18 v3] Improving latency of short slice tasks Qiliang Yuan
2026-11-24 17:31 ` Kayra Cizmeci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50f73e24-bf40-4fcf-a232-8747087ddbeb@arm.com \
    --to=elif.topuz@arm.com \
    --cc=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=christian.loehle@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kayracizmeci@gmail.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pierre.gondois@arm.com \
    --cc=qyousef@layalina.io \
    --cc=rafael@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=sshegde@linux.ibm.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®