Skip to content

Commit e1d7f54

Browse files
author
Peter Zijlstra
committed
rseq: Move slice_ext_nsec to debugfs
Move changing the slice ext duration to debugfs, a sliglty less permanent interface. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260121143207.923520192@infradead.org
1 parent d620024 commit e1d7f54

3 files changed

Lines changed: 49 additions & 35 deletions

File tree

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,17 +1248,6 @@ reboot-cmd (SPARC only)
12481248
ROM/Flash boot loader. Maybe to tell it what to do after
12491249
rebooting. ???
12501250

1251-
rseq_slice_extension_nsec
1252-
=========================
1253-
1254-
A task can request to delay its scheduling if it is in a critical section
1255-
via the prctl(PR_RSEQ_SLICE_EXTENSION_SET) mechanism. This sets the maximum
1256-
allowed extension in nanoseconds before scheduling of the task is enforced.
1257-
Default value is 10000ns (10us). The possible range is 10000ns (10us) to
1258-
50000ns (50us).
1259-
1260-
This value has a direct correlation to the worst case scheduling latency;
1261-
increment at your own risk.
12621251

12631252
sched_energy_aware
12641253
==================

Documentation/userspace-api/rseq.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ slice extension by setting rseq::slice_ctrl::request to 1. If the thread is
7979
interrupted and the interrupt results in a reschedule request in the
8080
kernel, then the kernel can grant a time slice extension and return to
8181
userspace instead of scheduling out. The length of the extension is
82-
determined by the ``rseq_slice_extension_nsec`` sysctl.
82+
determined by debugfs:rseq/slice_ext_nsec. The default value is 10 usec; which
83+
is the minimum value. It can be incremented to 50 usecs, however doing so
84+
can/will affect the minimum scheduling latency.
8385

8486
The kernel indicates the grant by clearing rseq::slice_ctrl::request and
8587
setting rseq::slice_ctrl::granted to 1. If there is a reschedule of the

kernel/rseq.c

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ void __rseq_trace_ip_fixup(unsigned long ip, unsigned long start_ip,
123123
}
124124
#endif /* CONFIG_TRACEPOINTS */
125125

126-
#ifdef CONFIG_DEBUG_FS
127126
#ifdef CONFIG_RSEQ_STATS
128127
DEFINE_PER_CPU(struct rseq_stats, rseq_stats);
129128

@@ -222,16 +221,19 @@ static const struct file_operations debug_ops = {
222221
.release = single_release,
223222
};
224223

224+
static void rseq_slice_ext_init(struct dentry *root_dir);
225+
225226
static int __init rseq_debugfs_init(void)
226227
{
227228
struct dentry *root_dir = debugfs_create_dir("rseq", NULL);
228229

229230
debugfs_create_file("debug", 0644, root_dir, NULL, &debug_ops);
230231
rseq_stats_init(root_dir);
232+
if (IS_ENABLED(CONFIG_RSEQ_SLICE_EXTENSION))
233+
rseq_slice_ext_init(root_dir);
231234
return 0;
232235
}
233236
__initcall(rseq_debugfs_init);
234-
#endif /* CONFIG_DEBUG_FS */
235237

236238
static bool rseq_set_ids(struct task_struct *t, struct rseq_ids *ids, u32 node_id)
237239
{
@@ -515,7 +517,9 @@ struct slice_timer {
515517
void *cookie;
516518
};
517519

518-
unsigned int rseq_slice_ext_nsecs __read_mostly = 10 * NSEC_PER_USEC;
520+
static const unsigned int rseq_slice_ext_nsecs_min = 10 * NSEC_PER_USEC;
521+
static const unsigned int rseq_slice_ext_nsecs_max = 50 * NSEC_PER_USEC;
522+
unsigned int rseq_slice_ext_nsecs __read_mostly = rseq_slice_ext_nsecs_min;
519523
static DEFINE_PER_CPU(struct slice_timer, slice_timer);
520524
DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key);
521525

@@ -761,30 +765,48 @@ SYSCALL_DEFINE0(rseq_slice_yield)
761765
return yielded;
762766
}
763767

764-
#ifdef CONFIG_SYSCTL
765-
static const unsigned int rseq_slice_ext_nsecs_min = 10 * NSEC_PER_USEC;
766-
static const unsigned int rseq_slice_ext_nsecs_max = 50 * NSEC_PER_USEC;
768+
static int rseq_slice_ext_show(struct seq_file *m, void *p)
769+
{
770+
seq_printf(m, "%d\n", rseq_slice_ext_nsecs);
771+
return 0;
772+
}
773+
774+
static ssize_t rseq_slice_ext_write(struct file *file, const char __user *ubuf,
775+
size_t count, loff_t *ppos)
776+
{
777+
unsigned int nsecs;
778+
779+
if (kstrtouint_from_user(ubuf, count, 10, &nsecs))
780+
return -EINVAL;
781+
782+
if (nsecs < rseq_slice_ext_nsecs_min)
783+
return -ERANGE;
767784

768-
static const struct ctl_table rseq_slice_ext_sysctl[] = {
769-
{
770-
.procname = "rseq_slice_extension_nsec",
771-
.data = &rseq_slice_ext_nsecs,
772-
.maxlen = sizeof(unsigned int),
773-
.mode = 0644,
774-
.proc_handler = proc_douintvec_minmax,
775-
.extra1 = (unsigned int *)&rseq_slice_ext_nsecs_min,
776-
.extra2 = (unsigned int *)&rseq_slice_ext_nsecs_max,
777-
},
785+
if (nsecs > rseq_slice_ext_nsecs_max)
786+
return -ERANGE;
787+
788+
rseq_slice_ext_nsecs = nsecs;
789+
790+
return count;
791+
}
792+
793+
static int rseq_slice_ext_open(struct inode *inode, struct file *file)
794+
{
795+
return single_open(file, rseq_slice_ext_show, inode->i_private);
796+
}
797+
798+
static const struct file_operations slice_ext_ops = {
799+
.open = rseq_slice_ext_open,
800+
.read = seq_read,
801+
.write = rseq_slice_ext_write,
802+
.llseek = seq_lseek,
803+
.release = single_release,
778804
};
779805

780-
static void rseq_slice_sysctl_init(void)
806+
static void rseq_slice_ext_init(struct dentry *root_dir)
781807
{
782-
if (rseq_slice_extension_enabled())
783-
register_sysctl_init("kernel", rseq_slice_ext_sysctl);
808+
debugfs_create_file("slice_ext_nsec", 0644, root_dir, NULL, &slice_ext_ops);
784809
}
785-
#else /* CONFIG_SYSCTL */
786-
static inline void rseq_slice_sysctl_init(void) { }
787-
#endif /* !CONFIG_SYSCTL */
788810

789811
static int __init rseq_slice_cmdline(char *str)
790812
{
@@ -807,8 +829,9 @@ static int __init rseq_slice_init(void)
807829
hrtimer_setup(per_cpu_ptr(&slice_timer.timer, cpu), rseq_slice_expired,
808830
CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED_HARD);
809831
}
810-
rseq_slice_sysctl_init();
811832
return 0;
812833
}
813834
device_initcall(rseq_slice_init);
835+
#else
836+
static void rseq_slice_ext_init(struct dentry *root_dir) { }
814837
#endif /* CONFIG_RSEQ_SLICE_EXTENSION */

0 commit comments

Comments
 (0)