mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched: Add _TIF_NEED_RESCHED_LAZY to __resched_curr check
@ 2025-09-28 15:14 Jemmy Wong
  2025-09-29  4:37 ` K Prateek Nayak
  0 siblings, 1 reply; 3+ messages in thread
From: Jemmy Wong @ 2025-09-28 15:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, Thomas Gleixner, Andy Lutomirski, Kees Cook,
	Sebastian Andrzej Siewior, Jemmy Wong, linux-kernel

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.

Signed-off-by: Jemmy Wong <jemmywong512@gmail.com>

---
 include/linux/sched.h       | 2 +-
 include/linux/thread_info.h | 2 ++
 kernel/entry/common.c       | 2 +-
 kernel/entry/kvm.c          | 2 +-
 kernel/sched/core.c         | 2 +-
 5 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index e4ce0a76831e..5946434b2dc4 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2041,7 +2041,7 @@ static inline void set_tsk_need_resched(struct task_struct *tsk)

 static inline void clear_tsk_need_resched(struct task_struct *tsk)
 {
-	atomic_long_andnot(_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY,
+	atomic_long_andnot(_TIF_NEED_RESCHED_MUSK,
 			  (atomic_long_t *)&task_thread_info(tsk)->flags);
 }

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index dd925d84fa46..a7512ab612ad 100644
--- 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)
+
 #ifdef __KERNEL__

 #ifndef arch_set_restart_data
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 408d28b5179d..ac6eff43d07e 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -27,7 +27,7 @@ __always_inline unsigned long exit_to_user_mode_loop(struct pt_regs *regs,

 		local_irq_enable_exit_to_user(ti_work);

-		if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY))
+		if (ti_work & _TIF_NEED_RESCHED_MUSK)
 			schedule();

 		if (ti_work & _TIF_UPROBE)
diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c
index 8485f63863af..cacb24f0fc86 100644
--- a/kernel/entry/kvm.c
+++ b/kernel/entry/kvm.c
@@ -13,7 +13,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
 			return -EINTR;
 		}

-		if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY))
+		if (ti_work & _TIF_NEED_RESCHED_MUSK)
 			schedule();

 		if (ti_work & _TIF_NOTIFY_RESUME)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ccba6fc3c3fe..15bf4b132153 100644
--- 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;

 	cpu = cpu_of(rq);
--
2.50.1 (Apple Git-155)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-29 17:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-28 15:14 [PATCH] sched: Add _TIF_NEED_RESCHED_LAZY to __resched_curr check Jemmy Wong
2025-09-29  4:37 ` K Prateek Nayak
2025-09-29 17:40   ` Jemmy Wong

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®