[PATCH V7 11/11] sched: Add kernel parameter to enable delaying RT threads

Prakash Sangappa posted 11 patches 2 months, 1 week ago
[PATCH V7 11/11] sched: Add kernel parameter to enable delaying RT threads
Posted by Prakash Sangappa 2 months, 1 week ago
Add a kernel parameter to enable or disable delaying a RT thread from being
scheduled on the cpu, if a thread running on cpu has requested extending its
time slice.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
---
 include/linux/sched.h |  1 +
 kernel/entry/common.c |  7 ++++++-
 kernel/sched/core.c   | 14 ++++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index af3bf1923509..2e65aafeef23 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -412,6 +412,7 @@ static inline void sched_domains_mutex_unlock(void) { }
 #ifdef CONFIG_RSEQ_RESCHED_DELAY
 /* Scheduler time slice extension duration */
 extern unsigned int sysctl_sched_preempt_delay_us;
+extern unsigned int sysctl_sched_delay_rt;
 #endif
 
 struct sched_param {
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 15ddf335ad4a..912565a24cca 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -85,13 +85,18 @@ void __weak arch_do_signal_or_restart(struct pt_regs *regs) { }
 
 static inline bool rseq_delay_resched(unsigned long ti_work)
 {
+	unsigned long tiflag;
+
 	if (!IS_ENABLED(CONFIG_RSEQ_RESCHED_DELAY))
 		return false;
 
 	if (unlikely(current->rseq_delay_resched != RSEQ_RESCHED_DELAY_PROBE))
 		return false;
 
-	if (!(ti_work & (_TIF_NEED_RESCHED|_TIF_NEED_RESCHED_LAZY)))
+	tiflag = sysctl_sched_delay_rt ? _TIF_NEED_RESCHED|_TIF_NEED_RESCHED_LAZY :
+		 _TIF_NEED_RESCHED_LAZY;
+
+	if (!(ti_work & tiflag))
 		return false;
 
 	if (__rseq_delay_resched()) {
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index e9be8a6b8851..bf16e11a3c27 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -157,6 +157,11 @@ __read_mostly unsigned int sysctl_sched_nr_migrate = SCHED_NR_MIGRATE_BREAK;
  */
 #define SCHED_PREEMPT_DELAY_DEFAULT_US	30
 __read_mostly unsigned int sysctl_sched_preempt_delay_us = SCHED_PREEMPT_DELAY_DEFAULT_US;
+
+/*
+ * Scheduler time slice extension - Enable delaying RT threads. Disabled by default.
+ */
+__read_mostly unsigned int sysctl_sched_delay_rt = 0;
 #endif
 
 __read_mostly int scheduler_running;
@@ -4785,6 +4790,15 @@ static const struct ctl_table sched_core_sysctls[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE_HUNDRED,
 	},
+	{
+		.procname	= "sched_delay_rt",
+		.data		= &sysctl_sched_delay_rt,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1         = SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE,
+	},
 #endif /* CONFIG_RSEQ_RESCHED_DELAY */
 };
 static int __init sched_core_sysctl_init(void)
-- 
2.43.5
Re: [PATCH V7 11/11] sched: Add kernel parameter to enable delaying RT threads
Posted by kernel test robot 2 months, 1 week ago
Hi Prakash,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on linus/master v6.16-rc7]
[cannot apply to tip/sched/core tip/core/entry next-20250725]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Prakash-Sangappa/sched-Scheduler-time-slice-extension/20250725-002052
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20250724161625.2360309-12-prakash.sangappa%40oracle.com
patch subject: [PATCH V7 11/11] sched: Add kernel parameter to enable delaying RT threads
config: riscv-randconfig-001-20250725 (https://download.01.org/0day-ci/archive/20250725/202507252357.llkbFyOC-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250725/202507252357.llkbFyOC-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507252357.llkbFyOC-lkp@intel.com/

All errors (new ones prefixed by >>):

   kernel/entry/common.c: In function 'rseq_delay_resched':
>> kernel/entry/common.c:96:11: error: 'sysctl_sched_delay_rt' undeclared (first use in this function)
      96 |  tiflag = sysctl_sched_delay_rt ? _TIF_NEED_RESCHED|_TIF_NEED_RESCHED_LAZY :
         |           ^~~~~~~~~~~~~~~~~~~~~
   kernel/entry/common.c:96:11: note: each undeclared identifier is reported only once for each function it appears in


vim +/sysctl_sched_delay_rt +96 kernel/entry/common.c

    85	
    86	static inline bool rseq_delay_resched(unsigned long ti_work)
    87	{
    88		unsigned long tiflag;
    89	
    90		if (!IS_ENABLED(CONFIG_RSEQ_RESCHED_DELAY))
    91			return false;
    92	
    93		if (unlikely(current->rseq_delay_resched != RSEQ_RESCHED_DELAY_PROBE))
    94			return false;
    95	
  > 96		tiflag = sysctl_sched_delay_rt ? _TIF_NEED_RESCHED|_TIF_NEED_RESCHED_LAZY :
    97			 _TIF_NEED_RESCHED_LAZY;
    98	
    99		if (!(ti_work & tiflag))
   100			return false;
   101	
   102		if (__rseq_delay_resched()) {
   103			clear_tsk_need_resched(current);
   104			trace_sched_delay_resched(current, ti_work);
   105			return true;
   106		}
   107		return false;
   108	}
   109	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki