From: Peter Zijlstra <peterz@infradead.org>
To: Chengfeng Lin <lin2530632123@gmail.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC] sched/fair: avoid redundant updates for unchanged default slices
Date: Mon, 12 Oct 2026 12:59:53 +0200 [thread overview]
Message-ID: <20261012105953.GR4121339@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CANGjgdnO3HXAxA33cT_rv=on6Qwyf95jgicj6cZKA86Q6tv0Sg@mail.gmail.com>
On Fri, Oct 09, 2026 at 11:49:40PM +0800, Chengfeng Lin wrote:
> Hi,
>
> Repeated sched_setparam() calls with unchanged parameters still take the
> parameter-update path for a SCHED_OTHER task using the default slice.
> A small prototype reduced this cost from 618.18 to 163.23 ns per call on
> v7.2, saving about 455 ns (73.6%). I would appreciate feedback on this
> optimization.
>
> This
> matters after an RT priority-inheritance boost has ended. Existing
> permission and LSM checks remain before the shortcut; explicit uclamp
> updates and reset-on-fork handling are unchanged.
Pff, so much text to filter just to find the issue. So you're saying
that you saw PI cost increase due to this change?
> Would this be a useful shortcut, or are there other updates that this
> unchanged-parameter case must retain?
>
> Thanks,
> Chengfeng
>
> Assisted-by: LLM
>
> ---
> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
> @@ -491,6 +491,39 @@ req_priv:
> return 0;
> }
>
> +static bool fair_params_changed(struct task_struct *p,
> + const struct sched_attr *attr)
> +{
> + if (attr->sched_nice != task_nice(p))
> + return true;
> +
> + if (attr->sched_runtime == p->se.slice)
> + return false;
> +
> + /* Preserve the existing path for PI-boosted and sched_ext tasks. */
> + if (p->sched_class != &fair_sched_class)
> + return true;
> +
> +#ifdef CONFIG_UCLAMP_TASK
> + /*
> + * Unchanged fair parameters can still require an implicit clamp reset,
> + * for example after a task was PI-boosted into the RT class.
> + */
> + if ((!p->uclamp_req[UCLAMP_MIN].user_defined &&
> + p->uclamp_req[UCLAMP_MIN].value != uclamp_none(UCLAMP_MIN)) ||
> + (!p->uclamp_req[UCLAMP_MAX].user_defined &&
> + p->uclamp_req[UCLAMP_MAX].value != uclamp_none(UCLAMP_MAX)))
> + return true;
> +#endif
> +
> + /*
> + * A zero runtime requests the default slice, whereas se.slice stores
> + * its actual duration. Keep the update if the mode or default changed.
> + */
> + return attr->sched_runtime || p->se.custom_slice ||
> + p->se.slice != READ_ONCE(sysctl_sched_base_slice);
> +}
Egads, this is unreadable. Also, perhaps wrong. Suppose the case where
attr->sched_runtime == se->slice, but !se->custom_slice. Or suppose the
slice matches, but you still need the change due to uclamp.
Anyway, are you trying to say something like so?
if (!!attr->sched_runtime != !!se->custom_slice)
return true;
if (attr->sched_runtime && attr->sched_runtime != se->slice)
return true;
next prev parent reply other threads:[~2026-10-12 10:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 15:49 Chengfeng Lin
2026-10-09 16:09 ` Chengfeng Lin
2026-10-12 10:59 ` Peter Zijlstra [this message]
2026-10-13 9:58 ` Chengfeng Lin
2026-10-13 11:31 ` Peter Zijlstra
2026-10-13 14:53 ` Chengfeng Lin
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=20261012105953.GR4121339@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=lin2530632123@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=vincent.guittot@linaro.org \
/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®