From: Prakash Sangappa <prakash.sangappa@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, rostedt@goodmis.org,
mathieu.desnoyers@efficios.com, tglx@linutronix.de,
bigeasy@linutronix.de, kprateek.nayak@amd.com
Subject: [PATCH V3 2/4] Sched: Tunable to specify duration of time slice extension
Date: Fri, 2 May 2025 01:59:53 +0000 [thread overview]
Message-ID: <20250502015955.3146733-3-prakash.sangappa@oracle.com> (raw)
In-Reply-To: <20250502015955.3146733-1-prakash.sangappa@oracle.com>
Add a tunable to specify duration of scheduler time slice extension.
The default will be set to 50us and the max value that can be specified
is 100us. Setting it to 0, disables scheduler time slice extension.
Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
---
include/linux/sched.h | 3 +++
include/uapi/linux/rseq.h | 6 +++---
kernel/rseq.c | 7 +++++--
kernel/sched/core.c | 16 ++++++++++++++++
4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 14bf0508bfca..cce3a0496703 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -407,6 +407,9 @@ static inline void sched_domains_mutex_lock(void) { }
static inline void sched_domains_mutex_unlock(void) { }
#endif
+/* Scheduler time slice extension */
+extern unsigned int sysctl_sched_preempt_delay_us;
+
struct sched_param {
int sched_priority;
};
diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h
index 900cb75f6a88..2aa9029325c2 100644
--- a/include/uapi/linux/rseq.h
+++ b/include/uapi/linux/rseq.h
@@ -132,9 +132,9 @@ struct rseq {
* Inhibit instruction sequence block restart on migration for
* this thread.
* - RSEQ_CS_DELAY_RESCHED
- * Request by user task to try delaying preemption. With
- * use of a timer, extra cpu time upto 50us is granted for this
- * thread before being rescheduled.
+ * Request by user task to try delaying its preemption. With
+ * use of a timer, extra cpu time upto 'sched_preempt_delay_us'
+ * is granted for this thread before being rescheduled.
*/
__u32 flags;
diff --git a/kernel/rseq.c b/kernel/rseq.c
index 0ecd16e01712..0cfdaf5b6c8e 100644
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -456,6 +456,8 @@ bool rseq_delay_resched(void)
if (!IS_ENABLED(CONFIG_SCHED_HRTICK))
return false;
+ if (!sysctl_sched_preempt_delay_us)
+ return false;
if (!t->rseq)
return false;
@@ -489,8 +491,9 @@ void rseq_delay_resched_fini(void)
* If your critical section is longer than 50 us you get to keep the
* pieces.
*/
- if (t->sched_time_delay)
- hrtick_local_start(50 * NSEC_PER_USEC);
+ if (sysctl_sched_preempt_delay_us && t->sched_time_delay)
+ hrtick_local_start(sysctl_sched_preempt_delay_us *
+ NSEC_PER_USEC);
#endif
}
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8c8960245ec0..05a952ec15ae 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -148,6 +148,13 @@ __read_mostly int sysctl_resched_latency_warn_once = 1;
*/
__read_mostly unsigned int sysctl_sched_nr_migrate = SCHED_NR_MIGRATE_BREAK;
+/*
+ * Scheduler time slice extension, duration in microsecs.
+ * Max value allowed 100us, default 50us
+ * If set to 0, scheduler time slice extension is disabled.
+ */
+__read_mostly unsigned int sysctl_sched_preempt_delay_us = 50;
+
__read_mostly int scheduler_running;
#ifdef CONFIG_SCHED_CORE
@@ -4711,6 +4718,15 @@ static const struct ctl_table sched_core_sysctls[] = {
.extra2 = SYSCTL_FOUR,
},
#endif /* CONFIG_NUMA_BALANCING */
+ {
+ .procname = "sched_preempt_delay_us",
+ .data = &sysctl_sched_preempt_delay_us,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE_HUNDRED,
+ },
};
static int __init sched_core_sysctl_init(void)
{
--
2.43.5
next prev parent reply other threads:[~2025-05-02 2:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 1:59 [PATCH V3 0/4] Scheduler " Prakash Sangappa
2025-05-02 1:59 ` [PATCH V3 1/4] Sched: " Prakash Sangappa
2025-05-02 9:05 ` Peter Zijlstra
2025-05-02 13:06 ` Steven Rostedt
2025-05-05 1:51 ` Prakash Sangappa
2025-05-05 14:48 ` Steven Rostedt
2025-05-05 15:58 ` Prakash Sangappa
2025-05-05 16:34 ` Steven Rostedt
2025-05-05 16:45 ` Steven Rostedt
2025-05-06 1:23 ` Prakash Sangappa
2025-05-06 13:13 ` Steven Rostedt
2025-05-02 15:39 ` Mathieu Desnoyers
2025-05-05 1:46 ` Prakash Sangappa
2025-05-05 1:42 ` Prakash Sangappa
2025-05-02 12:34 ` Sebastian Andrzej Siewior
2025-05-02 14:35 ` Peter Zijlstra
2025-05-02 15:27 ` Sebastian Andrzej Siewior
2025-05-02 1:59 ` Prakash Sangappa [this message]
2025-05-02 1:59 ` [PATCH V3 3/4] Sched: Add scheduler stat for cpu " Prakash Sangappa
2025-05-02 1:59 ` [PATCH V3 4/4] Sched: Add tracepoint for sched " Prakash Sangappa
2025-05-02 9:14 ` Peter Zijlstra
2025-05-02 11:02 ` Sebastian Andrzej Siewior
2025-05-02 11:10 ` Peter Zijlstra
2025-05-02 12:31 ` Sebastian Andrzej Siewior
2025-05-05 1:43 ` Prakash Sangappa
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=20250502015955.3146733-3-prakash.sangappa@oracle.com \
--to=prakash.sangappa@oracle.com \
--cc=bigeasy@linutronix.de \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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®