[PATCH RFC v1 1/5] rcutorture: Abstract reader-segment dump into rcu_torture_dump_read_segs()
From: Joel Fernandes
Date: Tue Jun 16 2026 - 18:26:39 EST
From: "Paul E. McKenney" <paulmck@xxxxxxxxxx>
This commit abstracts the open-coded dumping of reader segments in the
rcu_torture_cleanup() function into a new rcu_torture_dump_read_segs()
function. This abstraction will allow reader segments to be dumped for
other purposes.
Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
---
kernel/rcu/rcutorture.c | 148 +++++++++++++++++++++-------------------
1 file changed, 76 insertions(+), 72 deletions(-)
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 5f2848b828dc..42f94c62c18a 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2378,6 +2378,80 @@ struct rcu_torture_one_read_state {
unsigned long long ts;
};
+static void rcu_torture_dump_read_segs(struct rt_read_seg *rrsp, int nsegs)
+{
+ bool firsttime;
+ int i;
+ int j;
+
+ firsttime = 1;
+ for (i = 0; i < nsegs; i++) {
+ if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_GP))
+ pr_alert("\t%lluus ", div64_u64(rrsp[i].rt_ts, 1000ULL));
+ else
+ pr_alert("\t");
+ pr_cont("%d: %#4x", i, rrsp[i].rt_readstate);
+ if (rrsp[i].rt_delay_jiffies != 0) {
+ pr_cont("%s%ldjiffies", firsttime ? "" : "+",
+ rrsp[i].rt_delay_jiffies);
+ firsttime = 0;
+ }
+ if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_CPU)) {
+ pr_cont(" CPU %2d", rrsp[i].rt_cpu);
+ if (rrsp[i].rt_cpu != rrsp[i].rt_end_cpu)
+ pr_cont("->%-2d", rrsp[i].rt_end_cpu);
+ else
+ pr_cont(" ...");
+ }
+ if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_GP) &&
+ cur_ops->gather_gp_seqs && cur_ops->format_gp_seqs) {
+ char buf1[20+1];
+ char buf2[20+1];
+ char sepchar = '-';
+
+ cur_ops->format_gp_seqs(rrsp[i].rt_gp_seq, buf1, ARRAY_SIZE(buf1));
+ cur_ops->format_gp_seqs(rrsp[i].rt_gp_seq_end, buf2, ARRAY_SIZE(buf2));
+ if (rrsp[i].rt_gp_seq == rrsp[i].rt_gp_seq_end) {
+ if (buf2[0]) {
+ for (j = 0; buf2[j]; j++)
+ buf2[j] = '.';
+ if (j)
+ buf2[j - 1] = ' ';
+ }
+ sepchar = ' ';
+ }
+ pr_cont(" %s%c%s", buf1, sepchar, buf2);
+ }
+ if (rrsp[i].rt_delay_ms != 0) {
+ pr_cont(" %s%ldms", firsttime ? "" : "+", rrsp[i].rt_delay_ms);
+ firsttime = 0;
+ }
+ if (rrsp[i].rt_delay_us != 0) {
+ pr_cont(" %s%ldus", firsttime ? "" : "+", rrsp[i].rt_delay_us);
+ firsttime = 0;
+ }
+ pr_cont("%s", rrsp[i].rt_preempted ? " preempted" : "");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_BH)
+ pr_cont(" BH");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_IRQ)
+ pr_cont(" IRQ");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_PREEMPT)
+ pr_cont(" PREEMPT");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_RBH)
+ pr_cont(" RBH");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_SCHED)
+ pr_cont(" SCHED");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_RCU_1)
+ pr_cont(" RCU_1");
+ if (rrsp[i].rt_readstate & RCUTORTURE_RDR_RCU_2)
+ pr_cont(" RCU_2");
+ pr_cont("\n");
+
+ }
+ if (rt_read_preempted)
+ pr_alert("\tReader was preempted.\n");
+}
+
static void init_rcu_torture_one_read_state(struct rcu_torture_one_read_state *rtorsp,
struct torture_random_state *trsp)
{
@@ -4071,11 +4145,9 @@ static void rcu_gpwrap_lag_cleanup(void)
static void
rcu_torture_cleanup(void)
{
- int firsttime;
int flags = 0;
unsigned long gp_seq = 0;
int i;
- int j;
if (torture_cleanup_begin()) {
if (cur_ops->cb_barrier != NULL) {
@@ -4160,76 +4232,8 @@ rcu_torture_cleanup(void)
pr_alert("Failure/close-call rcutorture reader segments:\n");
if (rt_read_nsegs == 0)
pr_alert("\t: No segments recorded!!!\n");
- firsttime = 1;
- for (i = 0; i < rt_read_nsegs; i++) {
- if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_GP))
- pr_alert("\t%lluus ", div64_u64(err_segs[i].rt_ts, 1000ULL));
- else
- pr_alert("\t");
- pr_cont("%d: %#4x", i, err_segs[i].rt_readstate);
- if (err_segs[i].rt_delay_jiffies != 0) {
- pr_cont("%s%ldjiffies", firsttime ? "" : "+",
- err_segs[i].rt_delay_jiffies);
- firsttime = 0;
- }
- if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_CPU)) {
- pr_cont(" CPU %2d", err_segs[i].rt_cpu);
- if (err_segs[i].rt_cpu != err_segs[i].rt_end_cpu)
- pr_cont("->%-2d", err_segs[i].rt_end_cpu);
- else
- pr_cont(" ...");
- }
- if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_GP) &&
- cur_ops->gather_gp_seqs && cur_ops->format_gp_seqs) {
- char buf1[20+1];
- char buf2[20+1];
- char sepchar = '-';
-
- cur_ops->format_gp_seqs(err_segs[i].rt_gp_seq,
- buf1, ARRAY_SIZE(buf1));
- cur_ops->format_gp_seqs(err_segs[i].rt_gp_seq_end,
- buf2, ARRAY_SIZE(buf2));
- if (err_segs[i].rt_gp_seq == err_segs[i].rt_gp_seq_end) {
- if (buf2[0]) {
- for (j = 0; buf2[j]; j++)
- buf2[j] = '.';
- if (j)
- buf2[j - 1] = ' ';
- }
- sepchar = ' ';
- }
- pr_cont(" %s%c%s", buf1, sepchar, buf2);
- }
- if (err_segs[i].rt_delay_ms != 0) {
- pr_cont(" %s%ldms", firsttime ? "" : "+",
- err_segs[i].rt_delay_ms);
- firsttime = 0;
- }
- if (err_segs[i].rt_delay_us != 0) {
- pr_cont(" %s%ldus", firsttime ? "" : "+",
- err_segs[i].rt_delay_us);
- firsttime = 0;
- }
- pr_cont("%s", err_segs[i].rt_preempted ? " preempted" : "");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_BH)
- pr_cont(" BH");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_IRQ)
- pr_cont(" IRQ");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_PREEMPT)
- pr_cont(" PREEMPT");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_RBH)
- pr_cont(" RBH");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_SCHED)
- pr_cont(" SCHED");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_RCU_1)
- pr_cont(" RCU_1");
- if (err_segs[i].rt_readstate & RCUTORTURE_RDR_RCU_2)
- pr_cont(" RCU_2");
- pr_cont("\n");
-
- }
- if (rt_read_preempted)
- pr_alert("\tReader was preempted.\n");
+ else
+ rcu_torture_dump_read_segs(err_segs, rt_read_nsegs);
}
if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
--
2.34.1