From nobody Sun Feb 8 02:55:52 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA1694949E8 for ; Wed, 21 Jan 2026 14:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005982; cv=none; b=j6DE8UAyy0xXIpgiiaeNMIyeJI0y9EzO82p0k5/Gej2LofpeDcIeRhEQ9qjUMaYEazUb7/mLMDSjFmOxNkghVexhzR2fFzR7tbiZ7xp7Pj9WZS/js0yBfJkKN0+6LxGEeFbZjBDcVDORbAb9kkNl2mEkTQOZXRONYHLtpwWpHZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005982; c=relaxed/simple; bh=B9SbX4WYbGs76vMLFe+NouI0mAzbHh0eu5BPhCtuhfM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Dk0othvX6urB6MR8IiIoI3ioc05Cv6wr5601TeS+dzrvzUEtMGdTigQr5v1mE1T3/iLgtNKM37UW9h/QqE6NkqcRyzzCHluuOuoNMwyJWQlwppJnthefnInGFrDWxVO3zJOPihsjbqANcsM6jC7V/TesZuVTiioiYqzWIJXBbKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=GuiwRe+v; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GuiwRe+v" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=UtBtm/u4go1XmuqVciveuo53WUevG8gCdMXQb2Gp7lk=; b=GuiwRe+vyn6ALh48s8CDu/fvu6 1bmw8z/7+oQ0NA1QxXOGqwk3MNezgddWYt8FRlJ2Tkcmmqg0NFbgJtVxFOrAerfMjgawM+xR5TXXo Lx/A4T59V/LcvIDnKYUxEaRN2/OrfzmniNBwopkeWGtlOJUV88SYyFwqjnM5DZJPhOoBYUeo6tqXX YQJpP06YaV3WG9p57XMlLM5A4KtmyJzRmbcUCtFQyp8l4n6Iqxl6sSz4sRadnewAOCdO1cd8eqvOy vQTLJAA8QUDpFa2uOgR02y3qwGJ0HC5DO8Snh9d2c4FCA8gosYsEf5Tb23rSFgKbgXkzK/cEcbSeg aV678JhQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1viZGF-0000000GCYH-00rH; Wed, 21 Jan 2026 14:32:47 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 885403007E1; Wed, 21 Jan 2026 15:32:42 +0100 (CET) Message-ID: <20260121143207.814193010@infradead.org> User-Agent: quilt/0.68 Date: Wed, 21 Jan 2026 15:24:58 +0100 From: Peter Zijlstra To: tglx@linutronix.de, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, paulmck@kernel.org, boqun.feng@gmail.com, corbet@lwn.net, prakash.sangappa@oracle.com, vineethr@linux.ibm.com, kprateek.nayak@amd.com, rostedt@goodmis.org, bigeasy@linutronix.de, arnd@arndb.de, rdunlap@infradead.org, rongevarg@gmail.com, longman@redhat.com Subject: [PATCH 1/5] rseq: Allow registering RSEQ with slice extension References: <20260121142457.242071831@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since glibc cares about the number of syscalls required to initialize a new thread, allow initializing rseq with slice extension on. This avoids having= to do another prctl(). Requested-by: Mathieu Desnoyers Signed-off-by: Peter Zijlstra (Intel) --- include/uapi/linux/rseq.h | 3 ++- kernel/rseq.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) --- a/include/uapi/linux/rseq.h +++ b/include/uapi/linux/rseq.h @@ -19,7 +19,8 @@ enum rseq_cpu_id_state { }; =20 enum rseq_flags { - RSEQ_FLAG_UNREGISTER =3D (1 << 0), + RSEQ_FLAG_UNREGISTER =3D (1 << 0), + RSEQ_FLAG_SLICE_EXT_DEFAULT_ON =3D (1 << 1), }; =20 enum rseq_cs_flags_bit { --- a/kernel/rseq.c +++ b/kernel/rseq.c @@ -424,7 +424,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user return 0; } =20 - if (unlikely(flags)) + if (unlikely(flags & ~(RSEQ_FLAG_SLICE_EXT_DEFAULT_ON))) return -EINVAL; =20 if (current->rseq.usrptr) { @@ -459,8 +459,12 @@ SYSCALL_DEFINE4(rseq, struct rseq __user if (!access_ok(rseq, rseq_len)) return -EFAULT; =20 - if (IS_ENABLED(CONFIG_RSEQ_SLICE_EXTENSION)) + if (IS_ENABLED(CONFIG_RSEQ_SLICE_EXTENSION)) { rseqfl |=3D RSEQ_CS_FLAG_SLICE_EXT_AVAILABLE; + if (rseq_slice_extension_enabled() && + (flags & RSEQ_FLAG_SLICE_EXT_DEFAULT_ON)) + rseqfl |=3D RSEQ_CS_FLAG_SLICE_EXT_ENABLED; + } =20 scoped_user_write_access(rseq, efault) { /* @@ -488,6 +492,10 @@ SYSCALL_DEFINE4(rseq, struct rseq __user current->rseq.len =3D rseq_len; current->rseq.sig =3D sig; =20 +#ifdef CONFIG_RSEQ_SLICE_EXTENSION + current->rseq.slice.state.enabled =3D !!(rseqfl & RSEQ_CS_FLAG_SLICE_EXT_= ENABLED); +#endif + /* * If rseq was previously inactive, and has just been * registered, ensure the cpu_id_start and cpu_id fields From nobody Sun Feb 8 02:55:52 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8557F4A5B05 for ; Wed, 21 Jan 2026 14:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005983; cv=none; b=ZA1ns1GhQWKooIKkhtScCv7hm9tsmCwYu7QU7Z82Q1xUh/HFF5GhoGrCuk0sy1jGphiOjxODb+xU67L3egw6meLde3hpgzmVIrMf/et8c1aLutooP3G+X7OIkQKcTU1gjcrxw5XGnFkaHF4yynFymnUt67MKz4g67p1SSGRYPZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005983; c=relaxed/simple; bh=r/XHxTP1SFkFube6S6fOcBRkOsLbQ/XJLZcfUO9aiFA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gQeUZqQ4OjGWBy/54YD2LsOGDfbT0QjuUGUjr4fOBCN3Q7CsYEbLsiee9tj3kCV5C2kI8zTzFqSiRp/f1XribkS/mK/3xJlR64RPAX1bxCmuBJA1KuHjqdQK1x2WM1Bhz45rUhhMwy9ZftL+krSsxXrqufFdG9LJAiDouDPm8k4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=pxWcp7KF; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="pxWcp7KF" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=aqy6q2PF4tmu1fKJosKubbHYefzcOUhLoPjupKeh2kQ=; b=pxWcp7KFGQlOVx4A9gazDajjXi fe399B6bWht4iNd8msFG6efDA4KDNPIqDlBYop3vKGMVuKLHB8p564yXHAV+YRRCj/f7OVpT0KJO0 AXgbmQBQz9ohuD/XK45CF8rb6EOhRIWxnZqIpuGqsWCOvA5pY9BcGZR0R7JC0GUiK0Hb2QrsIvkzP n+c+O3uhBJ/EKL/WKo3TV5N+QFZNOTxUb2gjzQWykWvu6Lb4eW15itB9cAcwXEg/1jBeXKXTDnqfF 7Yej8I06/TYhhPIEs7ewiasLSmHG8gAn9nKfct7IW1tKyqw8DyuJoSKOTyA5HN46gPxOIbmWA9sSP /lcKNt+Q==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1viZGF-0000000GCYI-0YDt; Wed, 21 Jan 2026 14:32:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 8D9383008E2; Wed, 21 Jan 2026 15:32:42 +0100 (CET) Message-ID: <20260121143207.923520192@infradead.org> User-Agent: quilt/0.68 Date: Wed, 21 Jan 2026 15:24:59 +0100 From: Peter Zijlstra To: tglx@linutronix.de, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, paulmck@kernel.org, boqun.feng@gmail.com, corbet@lwn.net, prakash.sangappa@oracle.com, vineethr@linux.ibm.com, kprateek.nayak@amd.com, rostedt@goodmis.org, bigeasy@linutronix.de, arnd@arndb.de, rdunlap@infradead.org, rongevarg@gmail.com, longman@redhat.com Subject: [PATCH 2/5] rseq: Move slice_ext_nsec to debugfs References: <20260121142457.242071831@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move changing the slice ext duration to debugfs, a sliglty less permanent interface. Signed-off-by: Peter Zijlstra (Intel) --- Documentation/admin-guide/sysctl/kernel.rst | 11 ---- Documentation/userspace-api/rseq.rst | 4 + kernel/rseq.c | 69 +++++++++++++++++++----= ----- 3 files changed, 51 insertions(+), 33 deletions(-) --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -1248,17 +1248,6 @@ reboot-cmd (SPARC only) ROM/Flash boot loader. Maybe to tell it what to do after rebooting. ??? =20 -rseq_slice_extension_nsec -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D - -A task can request to delay its scheduling if it is in a critical section -via the prctl(PR_RSEQ_SLICE_EXTENSION_SET) mechanism. This sets the maximum -allowed extension in nanoseconds before scheduling of the task is enforced. -Default value is 10000ns (10us). The possible range is 10000ns (10us) to -50000ns (50us). - -This value has a direct correlation to the worst case scheduling latency; -increment at your own risk. =20 sched_energy_aware =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- a/Documentation/userspace-api/rseq.rst +++ b/Documentation/userspace-api/rseq.rst @@ -79,7 +79,9 @@ slice extension by setting rseq::slice_c interrupted and the interrupt results in a reschedule request in the kernel, then the kernel can grant a time slice extension and return to userspace instead of scheduling out. The length of the extension is -determined by the ``rseq_slice_extension_nsec`` sysctl. +determined by debugfs:rseq/slice_ext_nsec. The default value is 10 usec; w= hich +is the minimum value. It can be incremented to 50 usecs, however doing so +can/will affect the minimum scheduling latency. =20 The kernel indicates the grant by clearing rseq::slice_ctrl::request and setting rseq::slice_ctrl::granted to 1. If there is a reschedule of the --- a/kernel/rseq.c +++ b/kernel/rseq.c @@ -222,12 +222,16 @@ static const struct file_operations debu .release =3D single_release, }; =20 +extern void rseq_slice_ext_init(struct dentry *root_dir); + static int __init rseq_debugfs_init(void) { struct dentry *root_dir =3D debugfs_create_dir("rseq", NULL); =20 debugfs_create_file("debug", 0644, root_dir, NULL, &debug_ops); rseq_stats_init(root_dir); + if (IS_ENABLED(CONFIG_RSEQ_SLICE_EXTENSIO)) + rseq_slice_ext_init(root_dir); return 0; } __initcall(rseq_debugfs_init); @@ -515,7 +519,9 @@ struct slice_timer { void *cookie; }; =20 -unsigned int rseq_slice_ext_nsecs __read_mostly =3D 10 * NSEC_PER_USEC; +static const unsigned int rseq_slice_ext_nsecs_min =3D 10 * NSEC_PER_USEC; +static const unsigned int rseq_slice_ext_nsecs_max =3D 50 * NSEC_PER_USEC; +unsigned int rseq_slice_ext_nsecs __read_mostly =3D rseq_slice_ext_nsecs_m= in; static DEFINE_PER_CPU(struct slice_timer, slice_timer); DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key); =20 @@ -761,30 +767,52 @@ SYSCALL_DEFINE0(rseq_slice_yield) return yielded; } =20 -#ifdef CONFIG_SYSCTL -static const unsigned int rseq_slice_ext_nsecs_min =3D 10 * NSEC_PER_USEC; -static const unsigned int rseq_slice_ext_nsecs_max =3D 50 * NSEC_PER_USEC; +#ifdef CONFIG_DEBUG_FS +static int rseq_slice_ext_show(struct seq_file *m, void *p) +{ + seq_printf(m, "%d\n", rseq_slice_ext_nsecs); + return 0; +} + +static ssize_t rseq_slice_ext_write(struct file *file, const char __user *= ubuf, + size_t count, loff_t *ppos) +{ + unsigned int nsecs; + + if (kstrtouint(ubuf, count, &nsecs)) + return -EINVAL; + + if (nsecs < rseq_slice_ext_nsecs_min) + return -ERANGE; + + if (nsecs > rseq_slice_ext_nsecs_max) + return -ERANGE; + + rseq_slice_ext_nsecs =3D nsecs; + + return count; +} =20 -static const struct ctl_table rseq_slice_ext_sysctl[] =3D { - { - .procname =3D "rseq_slice_extension_nsec", - .data =3D &rseq_slice_ext_nsecs, - .maxlen =3D sizeof(unsigned int), - .mode =3D 0644, - .proc_handler =3D proc_douintvec_minmax, - .extra1 =3D (unsigned int *)&rseq_slice_ext_nsecs_min, - .extra2 =3D (unsigned int *)&rseq_slice_ext_nsecs_max, - }, +static int rseq_slice_ext_open(struct inode *inode, struct file *file) +{ + return single_open(file, rseq_slice_ext_show, inode->i_private); +} + +static const struct file_operations slice_ext_ops =3D { + .open =3D rseq_slice_ext_open, + .read =3D seq_read, + .write =3D rseq_slice_ext_write, + .llseek =3D seq_lseek, + .release =3D single_release, }; =20 -static void rseq_slice_sysctl_init(void) +static void rseq_slice_ext_init(struct dentry *root_dir) { - if (rseq_slice_extension_enabled()) - register_sysctl_init("kernel", rseq_slice_ext_sysctl); + debugfs_create_file("slice_ext_nsec", 0644, root_dir, NULL, &slice_ext_op= s); } -#else /* CONFIG_SYSCTL */ -static inline void rseq_slice_sysctl_init(void) { } -#endif /* !CONFIG_SYSCTL */ +#else +static void rseq_slice_ext_init(struct dentry *root_dir) { } +#endif =20 static int __init rseq_slice_cmdline(char *str) { @@ -807,7 +835,6 @@ static int __init rseq_slice_init(void) hrtimer_setup(per_cpu_ptr(&slice_timer.timer, cpu), rseq_slice_expired, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED_HARD); } - rseq_slice_sysctl_init(); return 0; } device_initcall(rseq_slice_init); From nobody Sun Feb 8 02:55:52 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FA5E48C8B1 for ; Wed, 21 Jan 2026 14:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005983; cv=none; b=YBAv8sb7NxYEqKtr280sO1M1tFA6nIsoIVfLuD1Q0Oom5rXnSD+uS0hhDyu/GJ1lT03bwTB+isQhRzvFjKyiGJRSs4YtNeDe/JFyhNAUOR3oM7bjpgcHzkEdyHLPNshB7YPuGd9JL9oU8SQeNbk58JuC9vnt7S/S0eUIJl+RAJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005983; c=relaxed/simple; bh=yA8dZ2u9/jKtSuXR3OAGM7r31GKZe4lD2V/Wcdt8giA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=D0eIldaV3PlYBzpt8yWuY1XFmV9o2BQEY8LwO5FDth2tUpn84K9GessaV2f+QJvI08o0VJQtg5cmOZ083OCwbof7c8hDC2Fcyv3Y2Y1Zj2m4pJAD3jqW3rFBioLqeptzmHxL+bpNk1jcKvLkNE/PG0/404wxhRzDcC2mzQi6AVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=eBH/Yaro; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eBH/Yaro" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=uoo+7gYFjvaXF9Cy59t/HP50QqZQnJF1Os+WgOv7ObA=; b=eBH/YaroYt3L/2+Pr6Qzcz9+dz RG1o8VXxios1bIk1ZOPAYSoaYCJGqQvgd/GelMyaaUl/Um4yee8feTrv9q/YMfV7/zCSK731xXp6u 4GzZpxT3UbQtpeW7ovBk7xU2wC2RePNnnlH8iupIZR4I16Bcv34r/hNIkAcfcHMTxhBVNxbWBl96P vnZQEueoxMDGkQ68Z/E4sgn7KozSZz9GDW9xLWsqBoUrG2jNXWKrcC3qIDVfsQ1aLXCvy/kiRR8q7 5Q5nkVWUHbpYK85+Yq+AY9t5rYIgrAzMLdKbZlMNxQTDrbQ2VUQZpLiuZSsMNhmyUs7grtm1Q72Kx ZE/NmJPA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1viZGF-0000000GTKE-2iUx; Wed, 21 Jan 2026 14:32:43 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 92070300B8A; Wed, 21 Jan 2026 15:32:42 +0100 (CET) Message-ID: <20260121143208.073200729@infradead.org> User-Agent: quilt/0.68 Date: Wed, 21 Jan 2026 15:25:00 +0100 From: Peter Zijlstra To: tglx@linutronix.de, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, paulmck@kernel.org, boqun.feng@gmail.com, corbet@lwn.net, prakash.sangappa@oracle.com, vineethr@linux.ibm.com, kprateek.nayak@amd.com, rostedt@goodmis.org, bigeasy@linutronix.de, arnd@arndb.de, rdunlap@infradead.org, rongevarg@gmail.com, longman@redhat.com Subject: [PATCH 3/5] rseq: Lower default slice extension References: <20260121142457.242071831@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change the minimum slice extension to 5 usec. Since slice_test selftest reaches a staggering ~350 nsec extension: Task: slice_test Mean: 350.266 ns Latency (us) | Count ------------------------------ EXPIRED | 238 0 us | 143189 1 us | 167 2 us | 26 3 us | 11 4 us | 28 5 us | 31 6 us | 22 7 us | 23 8 us | 32 9 us | 16 10 us | 35 Lower the minimal (and default) value to 5 usecs -- which is still massive. Signed-off-by: Peter Zijlstra (Intel) --- Documentation/userspace-api/rseq.rst | 2 +- kernel/rseq.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/Documentation/userspace-api/rseq.rst +++ b/Documentation/userspace-api/rseq.rst @@ -79,7 +79,7 @@ slice extension by setting rseq::slice_c interrupted and the interrupt results in a reschedule request in the kernel, then the kernel can grant a time slice extension and return to userspace instead of scheduling out. The length of the extension is -determined by debugfs:rseq/slice_ext_nsec. The default value is 10 usec; w= hich +determined by debugfs:rseq/slice_ext_nsec. The default value is 5 usec; wh= ich is the minimum value. It can be incremented to 50 usecs, however doing so can/will affect the minimum scheduling latency. =20 --- a/kernel/rseq.c +++ b/kernel/rseq.c @@ -519,7 +519,7 @@ struct slice_timer { void *cookie; }; =20 -static const unsigned int rseq_slice_ext_nsecs_min =3D 10 * NSEC_PER_USEC; +static const unsigned int rseq_slice_ext_nsecs_min =3D 5 * NSEC_PER_USEC; static const unsigned int rseq_slice_ext_nsecs_max =3D 50 * NSEC_PER_USEC; unsigned int rseq_slice_ext_nsecs __read_mostly =3D rseq_slice_ext_nsecs_m= in; static DEFINE_PER_CPU(struct slice_timer, slice_timer); From nobody Sun Feb 8 02:55:52 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECC6648C8B0 for ; Wed, 21 Jan 2026 14:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005981; cv=none; b=Ht9PyqIQ6maV+OrX2dUWvdpCyctLnbAEh8tZECRm1/WlzVtwTwRhIwsILuq+hG4TCat59war+HcHhjn/m9D4lvjTuB2J/qK2aAO2H5R7Fdgdu29e9de5S3dd4I9lz32s2NwomMmM/ikhomcOnEZx+XXfpsME1Jy5c8r8xKsUsJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005981; c=relaxed/simple; bh=kP9qwF25rFwsyAe2CjEdFD7qKhadcPIVO6R6IVS5VWo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aXttill7QztweK9tO9iH2iiuqpoVcBXnnBc3DPHhnEjWq3p1Ulvkx1pktFgmUHBG0US4ZedlmVqK7zoiUBFzZn5mauzqi2d5jRwXluZEyw6Of2Ue77Rk/bw63AC+vxKgGZN4OXoOdD/roXA8E2HCqWXdDRWMU8l39TvUm+6ghJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lbmeDdfU; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lbmeDdfU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=n/GjM0sBpJmMGxTCTtDukJeLriXosPGRF+iVt8tH2n8=; b=lbmeDdfU1B7GwAp7fK9RYExvNJ +DtPz2G4x6Khk6eV/EzQ1q8hDyvf/RHowQ4hV5w8DdjhYIpPppQycAYBRqCrukaucH1o8Q23ASnHD z8hlYdhbXy1HiL/1eFn4tYdt8teMyRuFXLLyjm1kO9Hv9lBMn7c95chSS6L7A+yOJd7ovNMYWCjBf TH8I+LojaLRwMMNPJersVDyX3CTqqVO/bSn2cG6wQR+iG84QbzhVpROuE8JwtmBaThjRcFnVYM9UZ tN1W95+sXwVD/nyeK+Hmw0ZARtBuXT96Hz7+iqtUljAquB/GW25gAGZQo2BI4ehQiR5Ei0gXjgwnB 77fs1NYg==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1viZGF-0000000GTKF-2epY; Wed, 21 Jan 2026 14:32:43 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 9640C300BD1; Wed, 21 Jan 2026 15:32:42 +0100 (CET) Message-ID: <20260121143208.219595606@infradead.org> User-Agent: quilt/0.68 Date: Wed, 21 Jan 2026 15:25:01 +0100 From: Peter Zijlstra To: tglx@linutronix.de, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, paulmck@kernel.org, boqun.feng@gmail.com, corbet@lwn.net, prakash.sangappa@oracle.com, vineethr@linux.ibm.com, kprateek.nayak@amd.com, rostedt@goodmis.org, bigeasy@linutronix.de, arnd@arndb.de, rdunlap@infradead.org, rongevarg@gmail.com, longman@redhat.com Subject: [PATCH 4/5] hrtimer: Fix trace oddity References: <20260121142457.242071831@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It turns out that __run_hrtimer() will trace like: -0 [032] d.h2. 20705.474563: hrtimer_cancel: hrti= mer=3D0xff2db8f77f8226e8 -0 [032] d.h1. 20705.474563: hrtimer_expire_entry: hrti= mer=3D0xff2db8f77f8226e8 now=3D20699452001850 function=3Dtick_nohz_handler/= 0x0 Which is a bit nonsensical, the timer doesn't get canceled on expiration. The cause is the use of the incorrect debug helper. Fixes: c6a2a1770245 ("hrtimer: Add tracepoint for hrtimers") Reported-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) --- kernel/time/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1750,7 +1750,7 @@ static void __run_hrtimer(struct hrtimer =20 lockdep_assert_held(&cpu_base->lock); =20 - debug_deactivate(timer); + debug_hrtimer_deactivate(timer); base->running =3D timer; =20 /* From nobody Sun Feb 8 02:55:52 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 886004A5B06 for ; Wed, 21 Jan 2026 14:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005982; cv=none; b=qB6P6+kYZNYsH7joTaxSWDwAf6p66yW1VBf7UeGrDgpfPEo0K8p/7dtI0lcrmRNKHnSJr07HbkMPr5QJifCpPVz255H4ALSCd+hTylO27dutGSMnW15TNzpViKWpek8coLjUG6ZCvItgMU7FJV86Vk/fXA++LPjH6ogrTlCpupI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769005982; c=relaxed/simple; bh=Cb5yo0CuAeEcrMccWG611/FRTW3qNZQZiYqeH5VlYUQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=AvAQiefhVgmk5HKGtphisg5Wg7lQBIqmJuMxykVajhjWRKHAi16CzDhKzveSkSaFtzoZGUrBLu9qCyviFEwQmiGBqMM2YVMt/gBxkyLEfJQu+1gcsVBDIVLupj0jebnpkN9yYlWlawdHs5dccDDmUsWjTTJ9h8NrOveLsLrnpxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lxnv2wZF; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lxnv2wZF" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=pnShIv763SA9zus1zhVHbnt2xp+CDmq/nwaoc/oPvuc=; b=lxnv2wZF87GMDslKgfC0FGh+RQ 8Ab75jn0r/oZGhY3EvR/8/X/1Q3avN8/VcXEG/F/Zr3hFfYuQGW6JxoL61Rg2M4aw9vKRUhfWv425 Pfn+CcmNBQQdHEP2x18zemNDdW1KzR2q9OpJqfZPtUPeu8RKGfWSxv6FR+FEoS0BD1rjGz+cXlSx0 J9c1vNfC3LWGtJ0WmNvNBNmN2TtcHksj93ZZEbmhXHdkVbXO2MonagSU0m8MsXIVCpXufSZ6gIrqn J4o91t8+SGOc1brMisgT0DhBR+LFWpUnfXivRkM+OxWUkVUsX3fW1V7dJHmV1Gnn7SodoQ/GE7roL VthVTioA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1viZGG-0000000GCYL-17Qa; Wed, 21 Jan 2026 14:32:47 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 9AD00300CDE; Wed, 21 Jan 2026 15:32:42 +0100 (CET) Message-ID: <20260121143208.340549136@infradead.org> User-Agent: quilt/0.68 Date: Wed, 21 Jan 2026 15:25:02 +0100 From: Peter Zijlstra To: tglx@linutronix.de, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, paulmck@kernel.org, boqun.feng@gmail.com, corbet@lwn.net, prakash.sangappa@oracle.com, vineethr@linux.ibm.com, kprateek.nayak@amd.com, rostedt@goodmis.org, bigeasy@linutronix.de, arnd@arndb.de, rdunlap@infradead.org, rongevarg@gmail.com, longman@redhat.com Subject: [PATCH 5/5] selftests/rseq: Add rseq slice histogram script References: <20260121142457.242071831@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A script that processes trace-cmd data and generates a histogram of rseq slice_ext durations for the recorded workload. Signed-off-by: Peter Zijlstra (Intel) --- Documentation/userspace-api/rseq.rst | 3=20 tools/testing/selftests/rseq/rseq-slice-hist.py | 132 +++++++++++++++++++= +++++ 2 files changed, 135 insertions(+) --- a/Documentation/userspace-api/rseq.rst +++ b/Documentation/userspace-api/rseq.rst @@ -83,6 +83,9 @@ determined by debugfs:rseq/slice_ext_nse is the minimum value. It can be incremented to 50 usecs, however doing so can/will affect the minimum scheduling latency. =20 +Any proposed changes to this default will have to come with a selftest and +rseq-slice-hist.py output that shows the new value has merrit. + The kernel indicates the grant by clearing rseq::slice_ctrl::request and setting rseq::slice_ctrl::granted to 1. If there is a reschedule of the thread after granting the extension, the kernel clears the granted bit to --- /dev/null +++ b/tools/testing/selftests/rseq/rseq-slice-hist.py @@ -0,0 +1,132 @@ +#!/usr/bin/python3 + +# +# trace-cmd record -e hrtimer_start -e hrtimer_cancel -e hrtimer_expire_en= try -- $cmd +# + +from tracecmd import * + +def load_kallsyms(file_path=3D'/proc/kallsyms'): + """ + Parses /proc/kallsyms into a dictionary. + Returns: { address_int: symbol_name } + """ + kallsyms_map =3D {} + + try: + with open(file_path, 'r') as f: + for line in f: + # The format is: [address] [type] [name] [module] + parts =3D line.split() + if len(parts) < 3: + continue + + addr =3D int(parts[0], 16) + name =3D parts[2] + + kallsyms_map[addr] =3D name + + except PermissionError: + print(f"Error: Permission denied reading {file_path}. Try running = with sudo.") + except FileNotFoundError: + print(f"Error: {file_path} not found.") + + return kallsyms_map + +ksyms =3D load_kallsyms() + +# pending[timer_ptr] =3D {'ts': timestamp, 'comm': comm} +pending =3D {} + +# histograms[comm][bucket] =3D count +histograms =3D {} + +class OnlineHarmonicMean: + def __init__(self): + self.n =3D 0 # Count of elements + self.S =3D 0.0 # Cumulative sum of reciprocals + + def update(self, x): + if x =3D=3D 0: + raise ValueError("Harmonic mean is undefined for zero.") + + self.n +=3D 1 + self.S +=3D 1.0 / x + return self.n / self.S + + @property + def mean(self): + return self.n / self.S if self.n > 0 else 0 + +ohms =3D {} + +def handle_start(record): + func_name =3D ksyms[record.num_field("function")] + if "rseq_slice_expired" in func_name: + timer_ptr =3D record.num_field("hrtimer") + pending[timer_ptr] =3D { + 'ts': record.ts, + 'comm': record.comm + } + return None + +def handle_cancel(record): + timer_ptr =3D record.num_field("hrtimer") + + if timer_ptr in pending: + start_data =3D pending.pop(timer_ptr) + duration_ns =3D record.ts - start_data['ts'] + duration_us =3D duration_ns // 1000 + + comm =3D start_data['comm'] + + if comm not in ohms: + ohms[comm] =3D OnlineHarmonicMean() + + ohms[comm].update(duration_ns) + + if comm not in histograms: + histograms[comm] =3D {} + + histograms[comm][duration_us] =3D histograms[comm].get(duration_us= , 0) + 1 + return None + +def handle_expire(record): + timer_ptr =3D record.num_field("hrtimer") + + if timer_ptr in pending: + start_data =3D pending.pop(timer_ptr) + comm =3D start_data['comm'] + + if comm not in histograms: + histograms[comm] =3D {} + + # Record -1 bucket for expired (failed to cancel) + histograms[comm][-1] =3D histograms[comm].get(-1, 0) + 1 + return None + +if __name__ =3D=3D "__main__": + t =3D Trace("trace.dat") + for cpu in range(0, t.cpus): + ev =3D t.read_event(cpu) + while ev: + if "hrtimer_start" in ev.name: + handle_start(ev) + if "hrtimer_cancel" in ev.name: + handle_cancel(ev) + if "hrtimer_expire_entry" in ev.name: + handle_expire(ev) + + ev =3D t.read_event(cpu) + + print("\n" + "=3D"*40) + print("RSEQ SLICE HISTOGRAM (us)") + print("=3D"*40) + for comm, buckets in histograms.items(): + print(f"\nTask: {comm} Mean: {ohms[comm].mean:.3f} ns") + print(f" {'Latency (us)':<15} | {'Count'}") + print(f" {'-'*30}") + # Sort buckets numerically, putting -1 at the top + for bucket in sorted(buckets.keys()): + label =3D "EXPIRED" if bucket =3D=3D -1 else f"{bucket} us" + print(f" {label:<15} | {buckets[bucket]}")