mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kunwu Chan <kunwu.chan@gmail.com>
To: paulmck@kernel.org, rcu@vger.kernel.org
Cc: dwmw2@infradead.org, jiangshanlai@gmail.com,
	josh@joshtriplett.org, work@onurozkan.dev, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, dave@stgolabs.net,
	jfern@kernel.org, frederic@kernel.org,
	neeraj.upadhyay@kernel.org, boqun@kernel.org, urezki@gmail.com,
	qiang.zhang@linux.dev, puranjay@kernel.org, shuah@kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Kunwu Chan <kunwu.chan@gmail.com>
Subject: [PATCH 12/17] rcutorture: Check NMI coverage
Date: Wed,  2 Dec 2026 00:18:10 +0800	[thread overview]
Message-ID: <20261201161815.1637481-13-kunwu.chan@gmail.com> (raw)
In-Reply-To: <20261201161815.1637481-1-kunwu.chan@gmail.com>

Periodic statistics use printk continuations and can split across
console lines. Emit a single NMI coverage summary after the perf
events and statistics thread stop and the callback barrier completes.

Require one valid summary followed by SUCCESS from the same flavor.
Return 0 if the requested coverage is present or 4 if it is absent.
Return 1 if the record is invalid or missing, or the run failed.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/rcutorture.c                       | 22 ++++++
 .../rcutorture/bin/kvm-recheck-nmi.sh         | 72 +++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 8905abe8725e..60c2f4cdccc6 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -3468,6 +3468,27 @@ rcu_torture_stats_print(void)
 	writer_gp_snap = writer_gp;
 }
 
+/* Print one complete record after the NMI sources stop and callbacks drain. */
+static void rcu_torture_nmi_coverage_print(void)
+{
+	unsigned long count, samples = 0;
+	unsigned int too_old = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(rcu_torture_nmi_pipe); i++) {
+		count = atomic_long_read(&rcu_torture_nmi_pipe[i]);
+		samples += count;
+		if (i > 1 && count)
+			too_old = 1;
+	}
+	pr_alert("%s%s NMI coverage: reads=%lu samples=%lu too-old=%u calls=%lu callbacks=%lu\n",
+		 torture_type, TORTURE_FLAG,
+		 (unsigned long)atomic_long_read(&n_rcu_torture_nmi_read),
+		 samples, too_old,
+		 (unsigned long)atomic_long_read(&n_rcu_torture_nmi_call),
+		 (unsigned long)atomic_long_read(&n_rcu_torture_nmi_cb));
+}
+
 /*
  * Periodically prints torture statistics, if periodic statistics printing
  * was specified via the stat_interval module parameter.
@@ -4730,6 +4751,7 @@ rcu_torture_cleanup(void)
 	rcu_torture_mem_dump_obj();
 
 	rcu_torture_stats_print();  /* -After- the stats thread is stopped! */
+	rcu_torture_nmi_coverage_print();
 
 	if (err_segs_recorded) {
 		pr_alert("Failure/close-call rcutorture reader segments:\n");
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh
new file mode 100755
index 000000000000..8a0e2fbc0660
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Usage: kvm-recheck-nmi.sh resdir [readers|calls|both]
+# Exit codes are 0 for coverage, 1 for failure, and 4 for untested.
+#
+# Author: Kunwu Chan <kunwu.chan@gmail.com>
+
+resdir="${1-}"
+mode="${2-both}"
+case "$mode" in
+readers|calls|both) ;;
+*) echo "Usage: $0 resdir [readers|calls|both]" >&2; exit 1 ;;
+esac
+if test -z "$resdir" || test ! -f "$resdir/console.log" ||
+   test ! -r "$resdir/console.log"
+then
+	echo "FAIL: unreadable console.log in $resdir" >&2
+	exit 1
+fi
+
+LC_ALL=C awk -v mode="$mode" '
+function fail(message) { print "FAIL: " message; exit 1 }
+function skip(message) { print "SKIP: " message; exit 4 }
+{
+	sub(/\r$/, "")
+	sub(/^\[[[:space:]]*[0-9]+\.[0-9]+\][[:space:]]*/, "")
+	sub(/^\[[[:space:]]*[CT][0-9]+\][[:space:]]*/, "")
+}
+/printk messages dropped/ { dropped = 1 }
+/^[^[:space:]]+-torture:[[:space:]]+NMI coverage:([[:space:]]|$)/ {
+	if (++summaries != 1 || results || NF != 8 ||
+	    $4 !~ /^reads=(0|[1-9][0-9]*)$/ ||
+	    $5 !~ /^samples=(0|[1-9][0-9]*)$/ ||
+	    $6 !~ /^too-old=[01]$/ ||
+	    $7 !~ /^calls=(0|[1-9][0-9]*)$/ ||
+	    $8 !~ /^callbacks=(0|[1-9][0-9]*)$/) {
+		malformed = 1
+		next
+	}
+	flavor = $1
+	reads = substr($4, 7)
+	samples = substr($5, 9)
+	too_old = ($6 == "too-old=1")
+	calls = substr($7, 7)
+	callbacks = substr($8, 11)
+}
+/^[^[:space:]]+-torture:(---)?[[:space:]]+End of test:/ {
+	result_flavor = $1
+	sub(/---$/, "", result_flavor)
+	if (++results != 1 || result_flavor != flavor || $5 !~ /^SUCCESS:?$/)
+		bad_result = 1
+}
+END {
+	if (dropped) fail("console reports dropped printk messages")
+	if (!summaries) fail("missing final NMI coverage summary")
+	if (malformed) fail("invalid, duplicate or misplaced NMI coverage summary")
+	if (bad_result || !results) fail("missing matching successful test completion")
+	if (too_old) fail("NMI reader observed a too-old object")
+	# Compare decimal strings exactly, including counts beyond awk precision.
+	if (length(samples) > length(reads) ||
+	    (length(samples) == length(reads) && "n" samples > "n" reads))
+		fail("NMI object samples exceed reader count")
+	if (mode != "readers" && "n" calls != "n" callbacks)
+		fail("NMI callback count differs after cleanup")
+	if (mode != "calls" && samples == "0")
+		skip("no protected object sampled from NMI")
+	if (mode != "readers" && calls == "0")
+		skip("no callback submitted from NMI")
+	printf "PASS: NMI reads=%s object-samples=%s calls=%s callbacks=%s\n", \
+		reads, samples, calls, callbacks
+}' < "$resdir/console.log"
-- 
2.43.0


  parent reply	other threads:[~2026-12-01 16:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
2026-12-01 16:17 ` [PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper Kunwu Chan
2026-12-01 16:18 ` [PATCH 02/17] srcu: Let GP completion take a size-state snapshot Kunwu Chan
2026-12-01 16:18 ` [PATCH 03/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
2026-12-01 16:18 ` [PATCH 04/17] srcu: Check only the boot CPU callback queue in SMALL domains Kunwu Chan
2026-12-01 16:18 ` [PATCH 05/17] rcutorture: Add selftests for console writer progress Kunwu Chan
2026-12-01 16:18 ` [PATCH 06/17] rcutorture: Compare console version counters exactly Kunwu Chan
2026-12-01 16:18 ` [PATCH 07/17] rcutorture: Recognize completed writer waits in console logs Kunwu Chan
2026-12-01 16:18 ` [PATCH 08/17] rcutorture: Emit the version with the statistics prefix Kunwu Chan
2026-12-01 16:18 ` [PATCH 09/17] rcutorture: Report completed synchronous writer waits Kunwu Chan
2026-12-01 16:18 ` [PATCH 10/17] rcutorture: Use writer wait counts in kernel stall diagnostics Kunwu Chan
2026-12-01 16:18 ` [PATCH 11/17] rcutorture: Add consecutive expedited waits per writer iteration Kunwu Chan
2026-12-01 16:18 ` Kunwu Chan [this message]
2026-12-01 16:18 ` [PATCH 13/17] rcutorture: Test NMI coverage result classification Kunwu Chan
2026-12-01 16:18 ` [PATCH 14/17] rcutorture: Test NMI summary field validation Kunwu Chan
2026-12-01 16:18 ` [PATCH 15/17] rcutorture: Test NMI console-log boundaries Kunwu Chan
2026-12-01 16:18 ` [PATCH 16/17] rcutorture: Document how to check SRCU NMI coverage Kunwu Chan
2026-12-01 16:18 ` [PATCH 17/17] rcutorture: Document directed SRCU NMI tests Kunwu Chan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201161815.1637481-13-kunwu.chan@gmail.com \
    --to=kunwu.chan@gmail.com \
    --cc=boqun@kernel.org \
    --cc=dave@stgolabs.net \
    --cc=dwmw2@infradead.org \
    --cc=frederic@kernel.org \
    --cc=jfern@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=puranjay@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=urezki@gmail.com \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®