[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250724161625.2360309-9-prakash.sangappa@oracle.com>
Date: Thu, 24 Jul 2025 16:16:22 +0000
From: Prakash Sangappa <prakash.sangappa@...cle.com>
To: linux-kernel@...r.kernel.org
Cc: peterz@...radead.org, rostedt@...dmis.org, mathieu.desnoyers@...icios.com,
tglx@...utronix.de, bigeasy@...utronix.de, kprateek.nayak@....com,
vineethr@...ux.ibm.com, prakash.sangappa@...cle.com
Subject: [PATCH V7 08/11] sched: Add TIF_NEED_RESCHED_NODELAY infrastructure
Add basic infrastructure to introduce a bit for nodelay resched.
This is mainly used by RT threads to indicate it should not be delayed
to be scheduled, by the thread running on the cpu that has requested
extending its cpu time slice.
Suggested-by: Thomas Gleixner <tglx@...utronix.de>
Signed-off-by: Prakash Sangappa <prakash.sangappa@...cle.com>
---
include/linux/entry-common.h | 4 ++--
include/linux/entry-kvm.h | 4 ++--
include/linux/sched.h | 3 ++-
include/linux/thread_info.h | 11 ++++++++++-
kernel/entry/common.c | 3 ++-
kernel/entry/kvm.c | 3 ++-
kernel/sched/core.c | 4 ++--
7 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index 7b258d2510f8..79510895f87a 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -66,8 +66,8 @@
#define EXIT_TO_USER_MODE_WORK \
(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | \
- _TIF_PATCH_PENDING | _TIF_NOTIFY_SIGNAL | \
- ARCH_EXIT_TO_USER_MODE_WORK)
+ _TIF_NEED_RESCHED_NODELAY |_TIF_PATCH_PENDING | \
+ _TIF_NOTIFY_SIGNAL | ARCH_EXIT_TO_USER_MODE_WORK)
/**
* arch_enter_from_user_mode - Architecture specific sanity check for user mode regs
diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h
index 16149f6625e4..eb59f8185f42 100644
--- a/include/linux/entry-kvm.h
+++ b/include/linux/entry-kvm.h
@@ -18,8 +18,8 @@
#define XFER_TO_GUEST_MODE_WORK \
(_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | _TIF_SIGPENDING | \
- _TIF_NOTIFY_SIGNAL | _TIF_NOTIFY_RESUME | \
- ARCH_XFER_TO_GUEST_MODE_WORK)
+ _TIF_NEED_RESCHED_NODELAY | _TIF_NOTIFY_SIGNAL | \
+ _TIF_NOTIFY_RESUME | ARCH_XFER_TO_GUEST_MODE_WORK)
struct kvm_vcpu;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3e8eb64658d1..af3bf1923509 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2093,7 +2093,8 @@ 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 | _TIF_NEED_RESCHED_LAZY |
+ _TIF_NEED_RESCHED_NODELAY,
(atomic_long_t *)&task_thread_info(tsk)->flags);
}
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index dd925d84fa46..ee7fa1f8f242 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -67,6 +67,14 @@ enum syscall_work_bit {
#define _TIF_NEED_RESCHED_LAZY _TIF_NEED_RESCHED
#endif
+#ifndef TIF_NEED_RESCHED_NODELAY
+#ifdef CONFIG_ARCH_HAS_PREEMPT_NODELAY
+#error Inconsistent PREEMPT_NODELAY
+#endif
+#define TIF_NEED_RESCHED_NODELAY TIF_NEED_RESCHED
+#define _TIF_NEED_RESCHED_NODELAY _TIF_NEED_RESCHED
+#endif
+
#ifdef __KERNEL__
#ifndef arch_set_restart_data
@@ -205,7 +213,8 @@ static __always_inline bool tif_test_bit(int bit)
static __always_inline bool tif_need_resched(void)
{
- return tif_test_bit(TIF_NEED_RESCHED);
+ return (tif_test_bit(TIF_NEED_RESCHED) ||
+ tif_test_bit(TIF_NEED_RESCHED_NODELAY));
}
#ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 2635fecb83ff..15ddf335ad4a 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -118,7 +118,8 @@ __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 | _TIF_NEED_RESCHED_LAZY |
+ _TIF_NEED_RESCHED_NODELAY)) {
if (likely(!irq || !rseq_delay_resched(ti_work)))
schedule();
}
diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c
index 8485f63863af..f4c10bbb42ac 100644
--- a/kernel/entry/kvm.c
+++ b/kernel/entry/kvm.c
@@ -13,7 +13,8 @@ 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 | _TIF_NEED_RESCHED_LAZY |
+ _TIF_NEED_RESCHED_NODELAY))
schedule();
if (ti_work & _TIF_NOTIFY_RESUME)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1ddb45b4b46a..035eec8911c2 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1141,13 +1141,13 @@ static void __resched_curr(struct rq *rq, int tif)
if (cpu == smp_processor_id()) {
set_ti_thread_flag(cti, tif);
- if (tif == TIF_NEED_RESCHED)
+ if (tif & (TIF_NEED_RESCHED | _TIF_NEED_RESCHED_NODELAY))
set_preempt_need_resched();
return;
}
if (set_nr_and_not_polling(cti, tif)) {
- if (tif == TIF_NEED_RESCHED)
+ if (tif & (TIF_NEED_RESCHED | _TIF_NEED_RESCHED_NODELAY))
smp_send_reschedule(cpu);
} else {
trace_sched_wake_idle_without_ipi(cpu);
--
2.43.5
Powered by blists - more mailing lists