* [PATCH V2 0/2] sched: Reduce the default slice to avoid tasks getting an extra tick
@ 2025-02-07 6:09 zihan zhou
2025-02-07 6:14 ` [PATCH V2 1/2] " zihan zhou
2025-02-07 6:24 ` [PATCH V2 2/2] " zihan zhou
0 siblings, 2 replies; 7+ messages in thread
From: zihan zhou @ 2025-02-07 6:09 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, vschneid
Cc: linux-kernel, zihan zhou
The old default value for slice is 0.75 msec * (1 + ilog(ncpus)) which
means that we have a default slice of
0.75 for 1 cpu
1.50 up to 3 cpus
2.25 up to 7 cpus
3.00 for 8 cpus and above.
For HZ=250 and HZ=100, because of the tick accuracy, the runtime of
tasks is far higher than their slice.
For HZ=1000 with 8 cpus or more, the accuracy of tick is already
satisfactory, but there is still an issue that tasks will get an extra
tick because the tick often arrives a little faster than expected. In this
case, the task can only wait until the next tick to consider that it has
reached its deadline, and will run 1ms longer.
vruntime + sysctl_sched_base_slice = deadline
|-----------|-----------|-----------|-----------|
1ms 1ms 1ms 1ms
^ ^ ^ ^
tick1 tick2 tick3 tick4(nearly 4ms)
There are two reasons for tick error: clockevent precision and the
CONFIG_IRQ_TIME_ACCOUNTING/CONFIG_PARAVIRT_TIME_ACCOUNTING.
with CONFIG_IRQ_TIME_ACCOUNTING every tick will be less than 1ms, but
even
without it, because of clockevent precision, tick still often less than
1ms.
In order to make scheduling more precise, we changed 0.75 to 0.70,
Using 0.70 instead of 0.75 should not change much for other configs
and would fix this issue:
0.70 for 1 cpu
1.40 up to 3 cpus
2.10 up to 7 cpus
2.8 for 8 cpus and above.
This does not guarantee that tasks can run the slice time accurately
every
time, but occasionally running an extra tick has little impact.
Changes from v1:
- update sysctl_sched_base_slice with debugfs, limit its value and
update normalized_sysctl_sched_base_slice.
zihan zhou (2):
sched/fair: reduce the default slice.
sched/debug: update sysctl_sched_base_slice with debugfs.
kernel/sched/debug.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
kernel/sched/fair.c | 47 ++++++++++++++++++++++++++++++++++++----
2 files changed, 93 insertions(+), 5 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V2 1/2] sched: Reduce the default slice to avoid tasks getting an extra tick
2025-02-07 6:09 [PATCH V2 0/2] sched: Reduce the default slice to avoid tasks getting an extra tick zihan zhou
@ 2025-02-07 6:14 ` zihan zhou
2025-02-07 13:46 ` Vincent Guittot
2025-02-07 6:24 ` [PATCH V2 2/2] " zihan zhou
1 sibling, 1 reply; 7+ messages in thread
From: zihan zhou @ 2025-02-07 6:14 UTC (permalink / raw)
To: 15645113830zzh
Cc: bsegall, dietmar.eggemann, juri.lelli, linux-kernel, mgorman,
mingo, peterz, rostedt, vincent.guittot, vschneid
Reduce the default slice, add a comment explaining why this modification
was made.
Signed-off-by: zihan zhou <15645113830zzh@gmail.com>
---
kernel/sched/fair.c | 47 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 43 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 26958431deb7..754b0785eaa0 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -71,10 +71,49 @@ unsigned int sysctl_sched_tunable_scaling = SCHED_TUNABLESCALING_LOG;
/*
* Minimal preemption granularity for CPU-bound tasks:
*
- * (default: 0.75 msec * (1 + ilog(ncpus)), units: nanoseconds)
- */
-unsigned int sysctl_sched_base_slice = 750000ULL;
-static unsigned int normalized_sysctl_sched_base_slice = 750000ULL;
+ * (default: 0.70 msec * (1 + ilog(ncpus)), units: nanoseconds)
+ *
+ * The old default value for slice is 0.75 msec * (1 + ilog(ncpus)) which
+ * means that we have a default slice of
+ * 0.75 for 1 cpu
+ * 1.50 up to 3 cpus
+ * 2.25 up to 7 cpus
+ * 3.00 for 8 cpus and above.
+ *
+ * For HZ=250 and HZ=100, because of the tick accuracy, the runtime of tasks
+ * is far higher than their slice.
+ * For HZ=1000 with 8 cpus or more, the accuracy of tick is already
+ * satisfactory, but there is still an issue that tasks will get an extra
+ * tick because the tick often arrives a little faster than expected. In this
+ * case, the task can only wait until the next tick to consider that it has
+ * reached its deadline, and will run 1ms longer.
+ *
+ * vruntime + sysctl_sched_base_slice = deadline
+ * |-----------|-----------|-----------|-----------|
+ * 1ms 1ms 1ms 1ms
+ * ^ ^ ^ ^
+ * tick1 tick2 tick3 tick4(nearly 4ms)
+ *
+ * There are two reasons for tick error: clockevent precision and the
+ * CONFIG_IRQ_TIME_ACCOUNTING/CONFIG_PARAVIRT_TIME_ACCOUNTING.
+ * with CONFIG_IRQ_TIME_ACCOUNTING every tick will be less than 1ms, but even
+ * without it, because of clockevent precision, tick still often less than
+ * 1ms.
+ *
+ * In order to make scheduling more precise, we changed 0.75 to 0.70,
+ * Using 0.70 instead of 0.75 should not change much for other configs
+ * and would fix this issue:
+ * 0.70 for 1 cpu
+ * 1.40 up to 3 cpus
+ * 2.10 up to 7 cpus
+ * 2.8 for 8 cpus and above.
+ *
+ * This does not guarantee that tasks can run the slice time accurately every
+ * time, but occasionally running an extra tick has little impact.
+ *
+ */
+unsigned int sysctl_sched_base_slice = 700000ULL;
+static unsigned int normalized_sysctl_sched_base_slice = 700000ULL;
const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
--
2.33.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH V2 2/2] sched: Reduce the default slice to avoid tasks getting an extra tick
2025-02-07 6:09 [PATCH V2 0/2] sched: Reduce the default slice to avoid tasks getting an extra tick zihan zhou
2025-02-07 6:14 ` [PATCH V2 1/2] " zihan zhou
@ 2025-02-07 6:24 ` zihan zhou
2025-02-08 1:04 ` kernel test robot
2025-02-08 5:59 ` kernel test robot
1 sibling, 2 replies; 7+ messages in thread
From: zihan zhou @ 2025-02-07 6:24 UTC (permalink / raw)
To: 15645113830zzh
Cc: bsegall, dietmar.eggemann, juri.lelli, linux-kernel, mgorman,
mingo, peterz, rostedt, vincent.guittot, vschneid
update sysctl_sched_base_slice with debugfs, limit its value and
update normalized_sysctl_sched_base_slice.
Signed-off-by: zihan zhou <15645113830zzh@gmail.com>
---
kernel/sched/debug.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index fd7e85220715..70dda949a69a 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -166,6 +166,55 @@ static const struct file_operations sched_feat_fops = {
.release = single_release,
};
+
+static ssize_t sched_base_slice_write(struct file *filp, const char __user *ubuf,
+ size_t cnt, loff_t *ppos)
+{
+ char buf[16];
+ unsigned int base_slice;
+
+ if (cnt > 15)
+ cnt = 15;
+
+ if (copy_from_user(&buf, ubuf, cnt))
+ return -EFAULT;
+ buf[cnt] = '\0';
+
+ if (kstrtouint(buf, 10, &base_slice))
+ return -EINVAL;
+
+
+ base_slice = clamp_t(u64, base_slice,
+ NSEC_PER_MSEC/10, /* HZ=1000 * 10 */
+ NSEC_PER_MSEC*100); /* HZ=100 / 10 */
+
+ sysctl_sched_base_slice = base_slice;
+
+ sched_update_scaling();
+
+ *ppos += cnt;
+ return cnt;
+}
+
+static int sched_base_slice_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "%d\n", sysctl_sched_base_slice);
+ return 0;
+}
+
+static int sched_base_slice_open(struct inode *inode, struct file *filp)
+{
+ return single_open(filp, sched_base_slice_show, NULL);
+}
+
+static const struct file_operations sched_base_slice_fops = {
+ .open = sched_base_slice_open,
+ .write = sched_base_slice_write,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
#ifdef CONFIG_SMP
static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
@@ -505,7 +554,7 @@ static __init int sched_init_debug(void)
debugfs_create_file("preempt", 0644, debugfs_sched, NULL, &sched_dynamic_fops);
#endif
- debugfs_create_u32("base_slice_ns", 0644, debugfs_sched, &sysctl_sched_base_slice);
+ debugfs_create_file("base_slice_ns", 0644, debugfs_sched, NULL, &sched_base_slice_fops);
debugfs_create_u32("latency_warn_ms", 0644, debugfs_sched, &sysctl_resched_latency_warn_ms);
debugfs_create_u32("latency_warn_once", 0644, debugfs_sched, &sysctl_resched_latency_warn_once);
--
2.33.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/2] sched: Reduce the default slice to avoid tasks getting an extra tick
2025-02-07 6:14 ` [PATCH V2 1/2] " zihan zhou
@ 2025-02-07 13:46 ` Vincent Guittot
2025-02-08 8:51 ` zihan zhou
0 siblings, 1 reply; 7+ messages in thread
From: Vincent Guittot @ 2025-02-07 13:46 UTC (permalink / raw)
To: zihan zhou
Cc: bsegall, dietmar.eggemann, juri.lelli, linux-kernel, mgorman,
mingo, peterz, rostedt, vschneid
On Fri, 7 Feb 2025 at 07:15, zihan zhou <15645113830zzh@gmail.com> wrote:
>
> Reduce the default slice, add a comment explaining why this modification
> was made.
>
> Signed-off-by: zihan zhou <15645113830zzh@gmail.com>
> ---
> kernel/sched/fair.c | 47 +++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 43 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 26958431deb7..754b0785eaa0 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -71,10 +71,49 @@ unsigned int sysctl_sched_tunable_scaling = SCHED_TUNABLESCALING_LOG;
> /*
> * Minimal preemption granularity for CPU-bound tasks:
> *
> - * (default: 0.75 msec * (1 + ilog(ncpus)), units: nanoseconds)
> - */
> -unsigned int sysctl_sched_base_slice = 750000ULL;
> -static unsigned int normalized_sysctl_sched_base_slice = 750000ULL;
> + * (default: 0.70 msec * (1 + ilog(ncpus)), units: nanoseconds)
> + *
> + * The old default value for slice is 0.75 msec * (1 + ilog(ncpus)) which
> + * means that we have a default slice of
> + * 0.75 for 1 cpu
> + * 1.50 up to 3 cpus
> + * 2.25 up to 7 cpus
> + * 3.00 for 8 cpus and above.
> + *
> + * For HZ=250 and HZ=100, because of the tick accuracy, the runtime of tasks
> + * is far higher than their slice.
> + * For HZ=1000 with 8 cpus or more, the accuracy of tick is already
> + * satisfactory, but there is still an issue that tasks will get an extra
> + * tick because the tick often arrives a little faster than expected. In this
> + * case, the task can only wait until the next tick to consider that it has
> + * reached its deadline, and will run 1ms longer.
> + *
> + * vruntime + sysctl_sched_base_slice = deadline
> + * |-----------|-----------|-----------|-----------|
> + * 1ms 1ms 1ms 1ms
> + * ^ ^ ^ ^
> + * tick1 tick2 tick3 tick4(nearly 4ms)
> + *
> + * There are two reasons for tick error: clockevent precision and the
> + * CONFIG_IRQ_TIME_ACCOUNTING/CONFIG_PARAVIRT_TIME_ACCOUNTING.
> + * with CONFIG_IRQ_TIME_ACCOUNTING every tick will be less than 1ms, but even
> + * without it, because of clockevent precision, tick still often less than
> + * 1ms.
> + *
> + * In order to make scheduling more precise, we changed 0.75 to 0.70,
> + * Using 0.70 instead of 0.75 should not change much for other configs
> + * and would fix this issue:
> + * 0.70 for 1 cpu
> + * 1.40 up to 3 cpus
> + * 2.10 up to 7 cpus
> + * 2.8 for 8 cpus and above.
> + *
> + * This does not guarantee that tasks can run the slice time accurately every
> + * time, but occasionally running an extra tick has little impact.
The explanation above about why you change sysctl_sched_base_slice
from 0.75 to 0.70 should be put in commit message instead of the code
With this change:
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> + *
> + */
> +unsigned int sysctl_sched_base_slice = 700000ULL;
> +static unsigned int normalized_sysctl_sched_base_slice = 700000ULL;
>
> const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
>
> --
> 2.33.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 2/2] sched: Reduce the default slice to avoid tasks getting an extra tick
2025-02-07 6:24 ` [PATCH V2 2/2] " zihan zhou
@ 2025-02-08 1:04 ` kernel test robot
2025-02-08 5:59 ` kernel test robot
1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2025-02-08 1:04 UTC (permalink / raw)
To: zihan zhou
Cc: oe-kbuild-all, bsegall, dietmar.eggemann, juri.lelli,
linux-kernel, mgorman, mingo, peterz, rostedt, vincent.guittot,
vschneid
Hi zihan,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/sched/core]
[also build test ERROR on peterz-queue/sched/core linus/master v6.14-rc1 next-20250207]
[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/zihan-zhou/sched-Reduce-the-default-slice-to-avoid-tasks-getting-an-extra-tick/20250207-142556
base: tip/sched/core
patch link: https://lore.kernel.org/r/20250207062402.33725-1-15645113830zzh%40gmail.com
patch subject: [PATCH V2 2/2] sched: Reduce the default slice to avoid tasks getting an extra tick
config: i386-randconfig-141-20250208 (https://download.01.org/0day-ci/archive/20250208/202502080831.VwRnAlxo-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250208/202502080831.VwRnAlxo-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/202502080831.VwRnAlxo-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from kernel/sched/build_utility.c:72:
>> kernel/sched/debug.c:193:2: error: call to undeclared function 'sched_update_scaling'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
193 | sched_update_scaling();
| ^
1 error generated.
vim +/sched_update_scaling +193 kernel/sched/debug.c
168
169
170 static ssize_t sched_base_slice_write(struct file *filp, const char __user *ubuf,
171 size_t cnt, loff_t *ppos)
172 {
173 char buf[16];
174 unsigned int base_slice;
175
176 if (cnt > 15)
177 cnt = 15;
178
179 if (copy_from_user(&buf, ubuf, cnt))
180 return -EFAULT;
181 buf[cnt] = '\0';
182
183 if (kstrtouint(buf, 10, &base_slice))
184 return -EINVAL;
185
186
187 base_slice = clamp_t(u64, base_slice,
188 NSEC_PER_MSEC/10, /* HZ=1000 * 10 */
189 NSEC_PER_MSEC*100); /* HZ=100 / 10 */
190
191 sysctl_sched_base_slice = base_slice;
192
> 193 sched_update_scaling();
194
195 *ppos += cnt;
196 return cnt;
197 }
198
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 2/2] sched: Reduce the default slice to avoid tasks getting an extra tick
2025-02-07 6:24 ` [PATCH V2 2/2] " zihan zhou
2025-02-08 1:04 ` kernel test robot
@ 2025-02-08 5:59 ` kernel test robot
1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2025-02-08 5:59 UTC (permalink / raw)
To: zihan zhou
Cc: oe-kbuild-all, bsegall, dietmar.eggemann, juri.lelli,
linux-kernel, mgorman, mingo, peterz, rostedt, vincent.guittot,
vschneid
Hi zihan,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/sched/core]
[also build test ERROR on peterz-queue/sched/core linus/master v6.14-rc1 next-20250207]
[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/zihan-zhou/sched-Reduce-the-default-slice-to-avoid-tasks-getting-an-extra-tick/20250207-142556
base: tip/sched/core
patch link: https://lore.kernel.org/r/20250207062402.33725-1-15645113830zzh%40gmail.com
patch subject: [PATCH V2 2/2] sched: Reduce the default slice to avoid tasks getting an extra tick
config: x86_64-randconfig-072-20250208 (https://download.01.org/0day-ci/archive/20250208/202502081304.ujyIUca2-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250208/202502081304.ujyIUca2-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/202502081304.ujyIUca2-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from kernel/sched/build_utility.c:72:
kernel/sched/debug.c: In function 'sched_base_slice_write':
>> kernel/sched/debug.c:193:9: error: implicit declaration of function 'sched_update_scaling'; did you mean 'sched_update_numa'? [-Werror=implicit-function-declaration]
193 | sched_update_scaling();
| ^~~~~~~~~~~~~~~~~~~~
| sched_update_numa
cc1: some warnings being treated as errors
vim +193 kernel/sched/debug.c
168
169
170 static ssize_t sched_base_slice_write(struct file *filp, const char __user *ubuf,
171 size_t cnt, loff_t *ppos)
172 {
173 char buf[16];
174 unsigned int base_slice;
175
176 if (cnt > 15)
177 cnt = 15;
178
179 if (copy_from_user(&buf, ubuf, cnt))
180 return -EFAULT;
181 buf[cnt] = '\0';
182
183 if (kstrtouint(buf, 10, &base_slice))
184 return -EINVAL;
185
186
187 base_slice = clamp_t(u64, base_slice,
188 NSEC_PER_MSEC/10, /* HZ=1000 * 10 */
189 NSEC_PER_MSEC*100); /* HZ=100 / 10 */
190
191 sysctl_sched_base_slice = base_slice;
192
> 193 sched_update_scaling();
194
195 *ppos += cnt;
196 return cnt;
197 }
198
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/2] sched: Reduce the default slice to avoid tasks getting an extra tick
2025-02-07 13:46 ` Vincent Guittot
@ 2025-02-08 8:51 ` zihan zhou
0 siblings, 0 replies; 7+ messages in thread
From: zihan zhou @ 2025-02-08 8:51 UTC (permalink / raw)
To: vincent.guittot
Cc: 15645113830zzh, bsegall, dietmar.eggemann, juri.lelli,
linux-kernel, mgorman, mingo, peterz, rostedt, vschneid
Thank you for your reply!
> The explanation above about why you change sysctl_sched_base_slice
> from 0.75 to 0.70 should be put in commit message instead of the code
>
> With this change:
>
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Thank you for your guidance! I have submitted patch v3:
https://lore.kernel.org/all/20250208074821.11832-1-15645113830zzh@gmail.com/
Looking forward to your review.
Thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-02-08 8:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-07 6:09 [PATCH V2 0/2] sched: Reduce the default slice to avoid tasks getting an extra tick zihan zhou
2025-02-07 6:14 ` [PATCH V2 1/2] " zihan zhou
2025-02-07 13:46 ` Vincent Guittot
2025-02-08 8:51 ` zihan zhou
2025-02-07 6:24 ` [PATCH V2 2/2] " zihan zhou
2025-02-08 1:04 ` kernel test robot
2025-02-08 5:59 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox