From: Peter Zijlstra <peterz@infradead.org>
To: Li kunyu <likunyu10@163.com>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, 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
Subject: Re: [PATCH v2] kernel/sched/fair: Fix the issue of virtual runtime conversion error
Date: Wed, 27 May 2026 13:59:35 +0200 [thread overview]
Message-ID: <20260527115935.GU3126523@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260527072113.359604-1-likunyu10@163.com>
On Wed, May 27, 2026 at 03:21:13PM +0800, Li kunyu wrote:
> The logic of the function here should be to convert the virtual runtime
> into actual time by combining it with the weight of the scheduling
> entity.
> However, it cannot be converted by simply converting actual time into
> virtual running time. A reverse conversion is required to obtain the
> correct time.
>
> Signed-off-by: Li kunyu <likunyu10@163.com>
> ---
> v2: Use the div64_ul function to perform division operation
>
> kernel/sched/fair.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 69361c63353a..53f3373c1735 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7033,7 +7033,9 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
> resched_curr(rq);
> return;
> }
> - delta = (se->load.weight * vdelta) / NICE_0_LOAD;
> +
> + if (unlikely(se->load.weight != NICE_0_LOAD))
> + delta = div64_ul(NICE_0_LOAD * vdelta, se->load.weight);
>
> /*
> * Correct for instantaneous load of other classes.
This seems wrong. Note that calc_delta_fair() does:
vdelta := (delta * NICE_0_LOAD) / se->load.weight
which gets us time -> vtime. Therefore the vtime -> time transform is
the inverse of that:
delta := (vdelta * se->load.weight) / NICE_0_LOAD;
which is exactly what the current code does.
Specifically:
NICE_0_LOAD se->load.weight
(delta * ---------------) * --------------- = delta
se->load.weight NICE_0_LOAD
next prev parent reply other threads:[~2026-05-27 11:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 7:15 [PATCH] kernel/sched/fair: Fix the issue of virtual runtime conversion error Li kunyu
2026-05-27 1:16 ` kernel test robot
2026-05-27 6:48 ` Geert Uytterhoeven
2026-05-27 7:21 ` [PATCH v2] " Li kunyu
2026-05-27 11:59 ` Peter Zijlstra [this message]
2026-05-28 6:07 ` Li kunyu
2026-05-28 9:58 ` kernel test robot
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=20260527115935.GU3126523@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=likunyu10@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--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