CodeSample/count: Use plain access instead of WRITE_ONCE
PATCH 1/2 CodeSample/count: Use plain access instead of WRITE_ONCE
The cap here has not been published, plain access is enough.
--- CodeSamples/count/count_end_rcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
CodeSamples/count/count_end_rcu.c +1 -1
@@ -89,7 +89,7 @@ void count_unregister_thread(int nthreadsexpected) //\lnlbl{unreg:b} }//\lnlbl{unreg:alloc:e} spin_lock (&final_mutex);//\lnlbl{unreg:acq} *cap = *countarrayp;//\lnlbl{unreg:copy} -WRITE_ONCE (cap->total, cap->total + counter);//\lnlbl{unreg:add} + cap->total += counter;//\lnlbl{unreg:add} cap->counterp[idx] =NULL ;//\lnlbl{unreg:null} capold = countarrayp;//\lnlbl{unreg:retain} rcu_assign_pointer (countarrayp, cap);//\lnlbl{unreg:assign}
Signature · 1 line
2.34.1
PATCH 2/2 together: Remove wrong content
In count_unregister_thread, both adding the counter to total and NULLs the exiting thread's counterp[] array element happen before publishing the newly allocated cap. Therefore, count_unregister_thread() can not result in the outgoing thread's work to be double counted.
--- together/applyrcu.tex | 9 --------- 1 file changed, 9 deletions(-)
together/applyrcu.tex +0 -9
@@ -151,15 +151,6 @@ is invoked by each newly created thread. So, interestingly enough, when adding a new thread, this implementation gets the effect of allocating a new structure, but without actually having to do the allocation. - - \begin{fcvref}[ln:count:count_end_rcu:whole:unreg] - On the other hand, \co{count_unregister_thread()} can result - in the outgoing thread's work being double counted. - This can happen when \co{read_count()} is invoked between - \clnref{add,null}. - There are efficient ways of avoiding this double-counting, but - these are left as an exercise for the reader. - \end{fcvref} }\QuickQuizEnd \begin{fcvref}[ln:count:count_end_rcu:whole:unreg]
Signature · 1 line
2.34.1
Quoted 3 lines · Alan Huang
The cap here has not been published, plain access is enough.
Signed-off-by Alan Huang <[email protected]>
Good catch, thank you!
Does line 27 of that same listing need a READ_ONCE(*ctrp)?
Thanx, Paul
Quoted 20 lines
--- CodeSamples/count/count_end_rcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)CodeSamples/count/count_end_rcu.c +1
-1@@ -89,7 +89,7 @@ void count_unregister_thread(int nthreadsexpected) //\lnlbl{unreg:b} }//\lnlbl{unreg:alloc:e} spin_lock (&final_mutex);//\lnlbl{unreg:acq} *cap = *countarrayp;//\lnlbl{unreg:copy} -WRITE_ONCE (cap->total, cap->total + counter);//\lnlbl{unreg:add} + cap->total += counter;//\lnlbl{unreg:add} cap->counterp[idx] =NULL ;//\lnlbl{unreg:null} capold = countarrayp;//\lnlbl{unreg:retain} rcu_assign_pointer (countarrayp, cap);//\lnlbl{unreg:assign} Signature · 1 line
2.34.1
Quoted 11 lines
2023年5月30日 08:30,Paul E. McKenney <[email protected]> 写道:
Quoted 3 lines · Alan Huang
The cap here has not been published, plain access is enough.
Signed-off-by Alan Huang <[email protected]>Good catch, thank you!
Does line 27 of that same listing need a
READ_ONCE(*ctrp)?
It does need! I have sent another patch.
Thanks,
Alan
Quoted 23 lines
Thanx, Paul
Quoted 20 lines
---
CodeSamples/count/count_end_rcu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)CodeSamples/count/count_end_rcu.c +1
-1@@ -89,7 +89,7 @@ void count_unregister_thread(int nthreadsexpected) //\lnlbl{unreg:b} }//\lnlbl{unreg:alloc:e} spin_lock (&final_mutex);//\lnlbl{unreg:acq} *cap = *countarrayp;//\lnlbl{unreg:copy} -WRITE_ONCE (cap->total, cap->total + counter);//\lnlbl{unreg:add} + cap->total += counter;//\lnlbl{unreg:add} cap->counterp[idx] =NULL ;//\lnlbl{unreg:null} capold = countarrayp;//\lnlbl{unreg:retain} rcu_assign_pointer (countarrayp, cap);//\lnlbl{unreg:assign} Signature · 1 line
2.34.1