Re: [PATCH v2 20/23] sched/cache: Add user control to adjust the parameters of cache-aware scheduling

From: Peter Zijlstra
Date: Wed Dec 10 2025 - 12:03:40 EST


On Wed, Dec 03, 2025 at 03:07:39PM -0800, Tim Chen wrote:

> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 466ba8b7398c..95bf080bbbf0 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -2436,9 +2436,11 @@ extern void migrate_enable(void);
> DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable())
>
> #ifdef CONFIG_SCHED_CACHE
> +DECLARE_STATIC_KEY_FALSE(sched_cache_on);
> +
> static inline bool sched_cache_enabled(void)
> {
> - return false;
> + return static_branch_unlikely(&sched_cache_on);
> }
> #endif
>
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 02e16b70a790..cde324672103 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -169,6 +169,53 @@ static const struct file_operations sched_feat_fops = {
> .release = single_release,
> };
>
> +#ifdef CONFIG_SCHED_CACHE
> +#define SCHED_CACHE_CREATE_CONTROL(name, max) \
> +static ssize_t sched_cache_write_##name(struct file *filp, \
> + const char __user *ubuf, \
> + size_t cnt, loff_t *ppos) \
> +{ \
> + char buf[16]; \
> + unsigned int val; \
> + if (cnt > 15) \
> + cnt = 15; \
> + if (copy_from_user(&buf, ubuf, cnt)) \
> + return -EFAULT; \
> + buf[cnt] = '\0'; \


> + if (kstrtouint(buf, 10, &val)) \
> + return -EINVAL; \
> + if (val > (max)) \
> + return -EINVAL; \
> + llc_##name = val; \
> + if (!strcmp(#name, "enabled")) \
> + sched_cache_set(false); \

Oh gawd :-(

Please just write out all the various write methods and use
kstrtoul_from_user() and kstrtobool_from_user() where applicable.

> + *ppos += cnt; \
> + return cnt; \
> +} \
> +static int sched_cache_show_##name(struct seq_file *m, void *v) \
> +{ \
> + seq_printf(m, "%d\n", llc_##name); \
> + return 0; \
> +} \
> +static int sched_cache_open_##name(struct inode *inode, \
> + struct file *filp) \
> +{ \
> + return single_open(filp, sched_cache_show_##name, NULL); \
> +} \
> +static const struct file_operations sched_cache_fops_##name = { \
> + .open = sched_cache_open_##name, \
> + .write = sched_cache_write_##name, \
> + .read = seq_read, \
> + .llseek = seq_lseek, \
> + .release = single_release, \
> +}
> +
> +SCHED_CACHE_CREATE_CONTROL(overload_pct, 100);
> +SCHED_CACHE_CREATE_CONTROL(imb_pct, 100);
> +SCHED_CACHE_CREATE_CONTROL(aggr_tolerance, 100);
> +SCHED_CACHE_CREATE_CONTROL(enabled, 1);