summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Huang <mmpgouride@gmail.com>2023-05-30 14:51:27 +0000
committerPaul E. McKenney <paulmck@kernel.org>2023-06-02 13:42:52 -0700
commit83c6f2379c11435e9d0972e0018ae98456ac0f20 (patch)
tree79cf9098eb57dae5791339d4ab9102b91e46faf3
parent94f01e467566ebfaee77868cc02b747e8950ad0b (diff)
downloadperfbook-83c6f2379c11435e9d0972e0018ae98456ac0f20.tar.gz
CodeSample/count: Update the places where READ_ONCE is used
There is no concurrent updates to 'total' by other threads, plain access is enough. But there might be threads updating 'counter', READ_ONCE is required. Signed-off-by: Alan Huang <mmpgouride@gmail.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
-rw-r--r--CodeSamples/count/count_end_rcu.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/CodeSamples/count/count_end_rcu.c b/CodeSamples/count/count_end_rcu.c
index 8fc70611..71bd5269 100644
--- a/CodeSamples/count/count_end_rcu.c
+++ b/CodeSamples/count/count_end_rcu.c
@@ -48,10 +48,10 @@ unsigned long read_count(void) //\lnlbl{read:b}
rcu_read_lock(); //\lnlbl{read:rrl}
cap = rcu_dereference(countarrayp); //\lnlbl{read:deref}
- sum = READ_ONCE(cap->total); //\lnlbl{read:init}
+ sum = cap->total; //\lnlbl{read:init}
for_each_thread(t) { //\lnlbl{read:add:b}
ctrp = READ_ONCE(cap->counterp[t]);
- if (ctrp != NULL) sum += *ctrp; //\lnlbl{read:add:e}
+ if (ctrp != NULL) sum += READ_ONCE(*ctrp); //\lnlbl{read:add:e}
}
rcu_read_unlock(); //\lnlbl{read:rru}
return sum; //\lnlbl{read:ret}