[PATCH 2/4] rcu_nest: Use READ_ONCE() and WRITE_ONCE() for shared variable rcu_gp_ctr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Replace the plain accesses and the use of ACCESS_ONCE() with
READ_ONCE()/WRITE_ONCE(). And then update the tex file accordingly.

Remove the goto statement in rcu_read_lock() because it seems this goto
logic has been discarded. If we should keep this code snippet, could you
please let me know the goal of this code snippet? Then we should update
the tex file accordingly.

Signed-off-by: Junchang Wang <junchangwang@xxxxxxxxx>
---
 CodeSamples/defer/rcu_nest.c | 5 +++--
 CodeSamples/defer/rcu_nest.h | 8 +-------
 appendix/toyrcu/toyrcu.tex   | 8 ++++----
 3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/CodeSamples/defer/rcu_nest.c b/CodeSamples/defer/rcu_nest.c
index 64e4087..845be6f 100644
--- a/CodeSamples/defer/rcu_nest.c
+++ b/CodeSamples/defer/rcu_nest.c
@@ -35,7 +35,7 @@ void synchronize_rcu(void)
 
 	/* Advance to a new grace-period number, enforce ordering. */
 
-	rcu_gp_ctr += RCU_GP_CTR_BOTTOM_BIT;
+	WRITE_ONCE(rcu_gp_ctr, READ_ONCE(rcu_gp_ctr) + RCU_GP_CTR_BOTTOM_BIT);
 	smp_mb();
 
 	/*
@@ -45,7 +45,8 @@ void synchronize_rcu(void)
 
 	for_each_thread(t) {
 		while (rcu_gp_ongoing(t) &&
-		       ((per_thread(rcu_reader_gp, t) - rcu_gp_ctr) < 0)) {
+		       ((per_thread(rcu_reader_gp, t) -
+			 READ_ONCE(rcu_gp_ctr)) < 0)) {
 			/*@@@ poll(NULL, 0, 10); */
 			barrier();
 		}
diff --git a/CodeSamples/defer/rcu_nest.h b/CodeSamples/defer/rcu_nest.h
index bcc4cde..7bb99bc 100644
--- a/CodeSamples/defer/rcu_nest.h
+++ b/CodeSamples/defer/rcu_nest.h
@@ -49,18 +49,12 @@ static void rcu_read_lock(void)
 	 */
 
 	rrgp = &__get_thread_var(rcu_reader_gp);
-retry:
 	tmp = *rrgp;
 	if ((tmp & RCU_GP_CTR_NEST_MASK) == 0)
-		tmp = rcu_gp_ctr;
+		tmp = READ_ONCE(rcu_gp_ctr);
 	tmp++;
 	*rrgp = tmp;
 	smp_mb();
-	if (((tmp & RCU_GP_CTR_NEST_MASK) == 1) &&
-	    ((rcu_gp_ctr - tmp) > (RCU_GP_CTR_NEST_MASK << 8)) != 0) {
-		(*rrgp)--;
-		goto retry;
-	}
 }
 
 static void rcu_read_unlock(void)
diff --git a/appendix/toyrcu/toyrcu.tex b/appendix/toyrcu/toyrcu.tex
index d9a7055..39126d2 100644
--- a/appendix/toyrcu/toyrcu.tex
+++ b/appendix/toyrcu/toyrcu.tex
@@ -1420,7 +1420,7 @@ variables.
  6   rrgp = &__get_thread_var(rcu_reader_gp);
  7   tmp = *rrgp;
  8   if ((tmp & RCU_GP_CTR_NEST_MASK) == 0)
- 9     tmp = ACCESS_ONCE(rcu_gp_ctr);
+ 9     tmp = READ_ONCE(rcu_gp_ctr);
 10   tmp++;
 11   *rrgp = tmp;
 12   smp_mb();
@@ -1440,13 +1440,13 @@ variables.
 26 
 27   smp_mb();
 28   spin_lock(&rcu_gp_lock);
-29   ACCESS_ONCE(rcu_gp_ctr) +=
-30     RCU_GP_CTR_BOTTOM_BIT;
+29   WRITE_ONCE(rcu_gp_ctr, READ_ONCE(rcu_gp_ctr) +
+30                           RCU_GP_CTR_BOTTOM_BIT);
 31   smp_mb();
 32   for_each_thread(t) {
 33     while (rcu_gp_ongoing(t) &&
 34            ((per_thread(rcu_reader_gp, t) -
-35              rcu_gp_ctr) < 0)) {
+35              READ_ONCE(rcu_gp_ctr)) < 0)) {
 36       poll(NULL, 0, 10);
 37     }
 38   }
-- 
2.7.4




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux