[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250502015955.3146733-3-prakash.sangappa@oracle.com>
Date: Fri, 2 May 2025 01:59:53 +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
Subject: [PATCH V3 2/4] Sched: Tunable to specify duration of time slice extension
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@...cle.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
Powered by blists - more mailing lists