From nobody Tue Feb 10 22:15:41 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]}")