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: Wed, 25 Nov 2026 16:05:08 +0000 [thread overview]
Message-ID: <17853c0e-9981-47f2-a62e-8ac4b2a192a6@arm.com> (raw)
In-Reply-To: <CAKfTPtDJFkSJm67CzoB=p5PCc60eVToEcy-=bxaThLXr5KGd7A@mail.gmail.com>
Hi Vincent,
On 25/11/2026 08:17, Vincent Guittot wrote:
> Hi Elif,
>
> On Tue, 24 Nov 2026 at 16:13, Elif Topuz <elif.topuz@arm.com> wrote:
>>
>> 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 |
>
> the p99.9 increase is somewhat expected and related to patches 1-4
> because we soften the capacity of short task to preempt current when
> they have the same slice
>
>> | base | 8/16 ms | 34406 | 53 | 54 | 56 | 269 | 11880 |
>> | patch | 8/16 ms | 34256 | 53 | 54 | 62 | 9126 | 15429 |
>
> The p99.9 value is not expected. Is it something that you can
> repeatedly reproduce? Also, what was the slice of other tasks on your
> system? if they stay to default 2.8ms they can disturb your test by
> preventing cyclictest to preempt rt-app. I noticed that when rt or
> deadline threads (like sugov) woke up simultaneously it could disturb
> cyclictest preemption. I'm working on fixing this for the next version
> I will look more deeply at this case while preparing the next version
yes, I have run the same experiment few more times and got the similar results.
As you said other tasks stayed to default 2.8ms in the system.
>
>>
>> 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 |
>
> Thise results are more aligned with my expectations
>
>>
>> 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.
>
> yes, patches 1-4 have the benefit to reduce preemption between tasks
> using the same slice but at the cost of scheduling latency for short
> sleeping 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.
>
> I haven't run those tests but will look into them. Have you tried
> hackbench alone and did you see some differences?
When running alone, the results are similar.
Default slice:
MODE IPC G FD | Base(s)/CV | Patch(s)/CV | diff%
----------------------------------------------------------------
process pipe 1 10 | 0.028/40.1% | 0.034/48.5% | -22.9%
process pipe 1 20 | 0.093/38.5% | 0.081/57.2% | +13.0%
process pipe 1 40 | 0.281/20.5% | 0.286/25.7% | -1.9%
process pipe 1 80 | 0.824/4.8% | 0.844/5.3% | -2.5%
process pipe 1 160 | 3.429/4.8% | 2.558/9.6% | +25.4%
process socket 1 10 | 0.069/59.9% | 0.073/42.7% | -5.3%
process socket 1 20 | 0.208/26.4% | 0.191/36.2% | +8.4%
process socket 1 40 | 0.445/4.4% | 0.445/4.7% | +0.2%
process socket 1 80 | 1.034/6.4% | 1.040/7.4% | -0.5%
process socket 1 160 | 2.983/1.7% | 2.895/0.8% | +2.9%
threads pipe 1 10 | 0.048/40.1% | 0.055/37.2% | -15.3%
threads pipe 1 20 | 0.107/39.3% | 0.135/31.8% | -26.5%
threads pipe 1 40 | 0.269/36.7% | 0.260/33.9% | +3.5%
threads pipe 1 80 | 0.706/21.3% | 0.929/4.9% | -31.6%
threads pipe 1 160 | 2.523/5.9% | 2.705/5.4% | -7.2%
threads socket 1 10 | 0.110/8.7% | 0.099/22.2% | +10.2%
threads socket 1 20 | 0.215/8.0% | 0.230/11.1% | -6.9%
threads socket 1 40 | 0.423/39.2% | 0.420/29.7% | +0.7%
threads socket 1 80 | 1.134/2.7% | 1.043/5.3% | +8.1%
threads socket 1 160 | 3.111/2.1% | 3.036/1.1% | +2.4%
[...]
Thanks,
Elif
next prev parent reply other threads:[~2026-11-25 16:05 UTC|newest]
Thread overview: 72+ 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
2026-11-25 8:17 ` Vincent Guittot
2026-11-25 16:05 ` 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-25 7:59 ` Vincent Guittot
2026-11-24 17:31 ` Kayra Cizmeci
2026-11-25 8:02 ` Vincent Guittot
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=17853c0e-9981-47f2-a62e-8ac4b2a192a6@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®