From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Jemmy Wong <jemmywong512@gmail.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>,
Thomas Gleixner <tglx@linutronix.de>,
Andy Lutomirski <luto@kernel.org>, Kees Cook <kees@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched: Add _TIF_NEED_RESCHED_LAZY to __resched_curr check
Date: Mon, 29 Sep 2025 10:07:33 +0530 [thread overview]
Message-ID: <c8864652-d763-48a3-9292-24c29c25838d@amd.com> (raw)
In-Reply-To: <20250928151421.60919-1-jemmywong512@gmail.com>
Hello Jemmy,
On 9/28/2025 8:44 PM, Jemmy Wong wrote:
> The TIF_NEED_RESCHED_LAZY flag can be set multiple times in a single
> call path. For example:
>
> entity_tick()
> update_curr(cfs_rq);
> resched_curr_lazy(rq);
> resched_curr_lazy(rq_of(cfs_rq));
>
> Add a check in resched_curr_lazy() to return early if the flag is
> already set, avoiding redundant operations.
That would have been a decent idea but then you decided to put that
check in __resched_curr() which makes it plain wrong.
[..snip..]
> --- a/include/linux/thread_info.h
> +++ b/include/linux/thread_info.h
> @@ -67,6 +67,8 @@ enum syscall_work_bit {
> #define _TIF_NEED_RESCHED_LAZY _TIF_NEED_RESCHED
> #endif
>
> +#define _TIF_NEED_RESCHED_MUSK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
s/MUSK/MASK/g
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1108,7 +1108,7 @@ static void __resched_curr(struct rq *rq, int tif)
> if (is_idle_task(curr) && tif == TIF_NEED_RESCHED_LAZY)
> tif = TIF_NEED_RESCHED;
>
> - if (cti->flags & ((1 << tif) | _TIF_NEED_RESCHED))
> + if (cti->flags & ((1 << tif) | _TIF_NEED_RESCHED_MUSK))
> return;
__resched_curr() is used to set both TIF_NEED_RESCHED_LAZY and
TIF_NEED_RESCHED.
By putting this check here, any effort to set NEED_RESCHED and force an
early preemption will bail out if NEED_RESCHED_LAZY is already set which
will delay the preemption.
An example:
/* New fair task wakes up. */
check_preempt_wakeup_fair()
resched_curr_lazy()
__resched_curr(TIF_NEED_RESCHED_LAZY)
/* New RT task wakes up. */
wakeup_preempt()
resched_curr()
__resched_curr(TIF_NEED_RESCHED)
/* Sees NEED_RESCHED_LAZY is already set. */
/* Does not do a set_preempt_need_resched() */
... /* Added latency */
sched_tick()
if (tif_test_bit(TIF_NEED_RESCHED_LAZY))
resched_curr()
__resched_curr(TIF_NEED_RESCHED)
/* Again bails out early! */
... /* More latency! */
So, the tick doesn't even upgrade the LAZY flag to a full NEED_RESCHED
and the only time you actually schedule is either at exit to user mode
or if a kthread decides to yield.
Going back to your commit message, something like:
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7f1e5cb94c53..3275abce9ca2 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1164,6 +1164,9 @@ static __always_inline int get_lazy_tif_bit(void)
void resched_curr_lazy(struct rq *rq)
{
+ if (task_thread_info(rq->curr)->flags & TIF_NEED_RESCHED_MASK)
+ return;
+
__resched_curr(rq, get_lazy_tif_bit());
}
probably fits the bill better.
>
> cpu = cpu_of(rq);
> --
> 2.50.1 (Apple Git-155)
>
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2025-09-29 4:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-28 15:14 Jemmy Wong
2025-09-29 4:37 ` K Prateek Nayak [this message]
2025-09-29 17:40 ` Jemmy Wong
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=c8864652-d763-48a3-9292-24c29c25838d@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bigeasy@linutronix.de \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jemmywong512@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®