This commit splits a new hazptr_torture_reader_tail() function out
of hazptr_torture_reader().  This will allow hazptr_torture_reader()
to pass hazard pointers off to other tasks and to various types of
handlers, and those hazard pointers can in turn be passed to this new
hazptr_torture_reader_tail() function to complete processing.

Signed-off-by: Paul E. McKenney <[email protected]>
---
 kernel/rcu/hazptrtorture.c | 42 +++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/kernel/rcu/hazptrtorture.c b/kernel/rcu/hazptrtorture.c
index adaf250ecfd585..3d559cfb85816d 100644
--- a/kernel/rcu/hazptrtorture.c
+++ b/kernel/rcu/hazptrtorture.c
@@ -351,6 +351,31 @@ hazptr_torture_writer(void *arg)
        return 0;
 }
 
+/*
+ * Do the delay, the accounting, and the release.  This in intended to
+ * be invoked from hazptr_torture_reader, but also for hazard pointers
+ * sent off to interrupt handlers and the like.
+ */
+static void hazptr_torture_reader_tail(struct hazptr_ctx *hcp, struct 
hazptr_torture *htp,
+                                      struct torture_random_state *trsp)
+{
+       int pipe_count;
+
+       cur_ops->read_delay(trsp);
+       preempt_disable();
+       pipe_count = READ_ONCE(htp->htort_pipe_count);
+       if (pipe_count > HAZPTR_TORTURE_PIPE_LEN) {
+               // Should not happen in a correct hazptr implementation,
+               // happens quite often for TBD torture_type=busted.
+               pipe_count = HAZPTR_TORTURE_PIPE_LEN;
+       }
+       if (pipe_count > 1)
+               rcu_ftrace_dump(DUMP_ALL);
+       __this_cpu_inc(hazptr_torture_count[pipe_count]);
+       preempt_enable();
+       cur_ops->readunlock(hcp, htp);
+}
+
 /*
  * Hazard-pointer torture reader kthread.  Repeatedly dereferences
  * hazptr_torture_current, incrementing the corresponding element of the
@@ -365,7 +390,6 @@ static int hazptr_torture_reader(void *arg)
        unsigned long lastsleep = jiffies;
        long myid = (long)arg;
        int mynumonline = myid % nr_cpu_ids;
-       int pipe_count;
        DEFINE_TORTURE_RANDOM(rand);
 
        VERBOSE_TOROUT_STRING("hazptr_torture_reader task started");
@@ -373,6 +397,8 @@ static int hazptr_torture_reader(void *arg)
        do {
                htp = cur_ops->readlock(&hcp);
                if (!htp) {
+                       // Still starting up or allocation failure,
+                       // so get out of the way.
                        schedule_timeout_interruptible(HZ / 10);
                        continue;
                }
@@ -380,19 +406,7 @@ static int hazptr_torture_reader(void *arg)
                        torture_hrtimeout_us(500, 1000, &rand);
                        lastsleep = jiffies + 10;
                }
-               cur_ops->read_delay(&rand);
-               preempt_disable();
-               pipe_count = READ_ONCE(htp->htort_pipe_count);
-               if (pipe_count > HAZPTR_TORTURE_PIPE_LEN) {
-                       // Should not happen in a correct RCU implementation,
-                       // happens quite often for torture_type=busted.
-                       pipe_count = HAZPTR_TORTURE_PIPE_LEN;
-               }
-               if (pipe_count > 1)
-                       rcu_ftrace_dump(DUMP_ALL);
-               __this_cpu_inc(hazptr_torture_count[pipe_count]);
-               preempt_enable();
-               cur_ops->readunlock(hcp, htp);
+               hazptr_torture_reader_tail(hcp, htp, &rand);
                while (!torture_must_stop() &&
                       (torture_num_online_cpus() < mynumonline || 
!rcu_inkernel_boot_has_ended()))
                        schedule_timeout_interruptible(HZ / 5);
-- 
2.40.1


Reply via email to