From: Andrea Righi <arighi@nvidia.com>
To: Zhimin Feng <fengzhimin@bytedance.com>
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Emil Tsalapatis <etsal@meta.com>,
Cheng-Yang Chou <yphbchou0911@gmail.com>,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org,
Chengming Zhou <zhouchengming@bytedance.com>
Subject: Re: [PATCH sched_ext] sched/ext: Keep tick enabled for finite-slice tasks
Date: Thu, 16 Jul 2026 07:14:35 +0200 [thread overview]
Message-ID: <alhou5r8pMyp-tqU@gpd4> (raw)
In-Reply-To: <20260716023746.3289089-1-fengzhimin@bytedance.com>
Hi Zhimin,
On Thu, Jul 16, 2026 at 10:37:46AM +0800, Zhimin Feng wrote:
> SCX tasks with finite slices need the scheduler tick to make forward
> progress on slice expiration. However, set_next_task_scx() used to refresh
> the nohz dependency through sched_update_tick_dependency(), which evaluates
> sched_can_stop_tick() using rq->curr.
>
> When switching from idle, RT, CFS, or another previous task to a
> finite-slice SCX task on a nohz_full CPU, rq->curr may still point at
> the previous task while set_next_task_scx() is running. If that previous
> task allows the tick to stop, the scheduler dependency can remain
> cleared even though the next SCX task has p->scx.slice != SCX_SLICE_INF.
>
> CFS does not hit the same gap for bandwidth-constrained tasks because its
> pick path has a next-task based check: sched_fair_update_stop_tick()
> explicitly sets TICK_DEP_BIT_SCHED when the selected CFS task needs
> bandwidth accounting on a nohz_full CPU.
>
> Add a helper to set the scheduler tick dependency directly and use it from
> set_next_task_scx() whenever the next SCX task has a finite slice.
> This avoids basing the finite-slice decision on the old rq->curr while
> preserving the existing tickless behavior for SCX_SLICE_INF tasks.
>
> Signed-off-by: Zhimin Feng <fengzhimin@bytedance.com>
> Co-developed-by: Chengming Zhou <zhouchengming@bytedance.com>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
This should already be fixed upstream by commit 4ec10f38ff901 ("sched_ext:
Enable tick for finite slices on nohz_full"):
See also:
https://lore.kernel.org/all/20260708074812.1041434-1-arighi@nvidia.com/
Thanks,
-Andrea
> ---
> kernel/sched/ext/ext.c | 21 ++++++++++++++++++---
> kernel/sched/sched.h | 11 +++++++++++
> 2 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 691d53fe0f64..6c0c805d489a 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -2950,6 +2950,8 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
> static void set_next_task_scx(struct rq *rq, struct task_struct *p, bool first)
> {
> struct scx_sched *sch = scx_task_sched(p);
> + bool can_stop_tick;
> + bool tick_state_changed;
>
> if (p->scx.flags & SCX_TASK_QUEUED) {
> /*
> @@ -2972,15 +2974,28 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, bool first)
> * @p is getting newly scheduled or got kicked after someone updated its
> * slice. Refresh whether tick can be stopped. See scx_can_stop_tick().
> */
> - if ((p->scx.slice == SCX_SLICE_INF) !=
> - (bool)(rq->scx.flags & SCX_RQ_CAN_STOP_TICK)) {
> - if (p->scx.slice == SCX_SLICE_INF)
> + can_stop_tick = p->scx.slice == SCX_SLICE_INF;
> + tick_state_changed = can_stop_tick !=
> + (bool)(rq->scx.flags & SCX_RQ_CAN_STOP_TICK);
> + if (tick_state_changed) {
> + if (can_stop_tick)
> rq->scx.flags |= SCX_RQ_CAN_STOP_TICK;
> else
> rq->scx.flags &= ~SCX_RQ_CAN_STOP_TICK;
> + }
>
> + /*
> + * If @p has a finite slice, it needs the scheduler tick to make
> + * forward progress on slice expiration. Don't rely on
> + * sched_update_tick_dependency() here because rq->curr may still be
> + * the previous task while set_next_task_scx() is running.
> + */
> + if (!can_stop_tick)
> + sched_set_tick_dependency(rq);
> + else if (tick_state_changed)
> sched_update_tick_dependency(rq);
>
> + if (tick_state_changed) {
> /*
> * For now, let's refresh the load_avgs just when transitioning
> * in and out of nohz. In the future, we might want to add a
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 56acf502ba26..d692d92fc095 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2998,9 +2998,20 @@ static inline void sched_update_tick_dependency(struct rq *rq)
> else
> tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
> }
> +
> +static inline void sched_set_tick_dependency(struct rq *rq)
> +{
> + int cpu = cpu_of(rq);
> +
> + if (!tick_nohz_full_cpu(cpu))
> + return;
> +
> + tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
> +}
> #else /* !CONFIG_NO_HZ_FULL: */
> static inline int sched_tick_offload_init(void) { return 0; }
> static inline void sched_update_tick_dependency(struct rq *rq) { }
> +static inline void sched_set_tick_dependency(struct rq *rq) { }
> #endif /* !CONFIG_NO_HZ_FULL */
>
> static inline void add_nr_running(struct rq *rq, unsigned count)
> --
> 2.39.5
next prev parent reply other threads:[~2026-07-16 5:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 2:37 Zhimin Feng
2026-07-16 5:14 ` Andrea Righi [this message]
2026-07-16 11:29 ` 冯志敏
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=alhou5r8pMyp-tqU@gpd4 \
--to=arighi@nvidia.com \
--cc=bsegall@google.com \
--cc=changwoo@igalia.com \
--cc=dietmar.eggemann@arm.com \
--cc=etsal@meta.com \
--cc=fengzhimin@bytedance.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=void@manifault.com \
--cc=vschneid@redhat.com \
--cc=yphbchou0911@gmail.com \
--cc=zhouchengming@bytedance.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®