CodeSamples/count: change full memory barrier to partial one
PATCH 1/1 CodeSamples/count: change full memory barrier to partial one
The original memory barriers in count_stat_eventual.c ensure writing to global_count happens before writing to stopflag and reading from stopflag happens before later reading from global_count.
Thus, smp_load_acquire and smp_store_release will suffice.
--- CodeSamples/count/count_stat_eventual.c | 6 ++---- count/count.tex | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-)
CodeSamples/count/count_stat_eventual.c +2 -4
@@ -51,8 +51,7 @@ void *eventual(void *arg) //\lnlbl{eventual:b}WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 );if (READ_ONCE (stopflag)) { -smp_mb (); -WRITE_ONCE (stopflag, stopflag +1 ); +smp_store_release (&stopflag, stopflag +1 ); } }return NULL ;
@@ -73,9 +72,8 @@ void count_init(void) //\lnlbl{init:b}void count_cleanup (void )//\lnlbl{cleanup:b} {WRITE_ONCE (stopflag,1 ); -while (READ_ONCE (stopflag) <3 ) +while (smp_load_acquire (&stopflag) <3 )poll (NULL ,0 ,1 ); -smp_mb (); }//\lnlbl{cleanup:e} //\end{snippet}
count/count.tex +3 -3
@@ -1013,9 +1013,9 @@ between passes. The \co{count_cleanup()} function on \clnrefrange{cleanup:b}{cleanup:e} coordinates termination. -The calls to \co{smp_mb()} here and in \co{eventual()} ensure -that all updates to \co{global_count} are visible to code following -the call to \co{count_cleanup()}. +The call to \co{smp_load_acquire()} here and the call to \co{smp_store_release()} +in \co{eventual()} ensure that all updates to \co{global_count} are visible +to code following the call to \co{count_cleanup()}. This approach gives extremely fast counter read-out while still supporting linear counter-update scalability.
Signature · 1 line
2.34.1
Quoted 44 lines · Alan Huang
The original memory barriers in
count_stat_eventual.censure writing toglobal_counthappens before writing to stopflag and reading from stopflag happens before later reading fromglobal_count.Thus,
smp_load_acquireandsmp_store_releasewill suffice.Signed-off-by Alan Huang <[email protected]>--- CodeSamples/count/count_stat_eventual.c | 6 ++---- count/count.tex | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-)CodeSamples/count/count_stat_eventual.c +2
-4@@ -51,8 +51,7 @@ void *eventual(void *arg) //\lnlbl{eventual:b}WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 );if (READ_ONCE (stopflag)) { -smp_mb (); -WRITE_ONCE (stopflag, stopflag +1 ); +smp_store_release (&stopflag, stopflag +1 ); } }return NULL ;@@ -73,9 +72,8 @@ void count_init(void) //\lnlbl{init:b}void count_cleanup (void )//\lnlbl{cleanup:b} {WRITE_ONCE (stopflag,1 ); -while (READ_ONCE (stopflag) <3 ) +while (smp_load_acquire (&stopflag) <3 )poll (NULL ,0 ,1 ); -smp_mb (); }//\lnlbl{cleanup:e} //\end{snippet} count/count.tex +0
-0@@ -1013,9 +1013,9 @@ between passes. The \co{count_cleanup()} function on
count/count.tex between passes. · line 1021
Quoted 10 lines
count/count.tex +3
-3\clnrefrange{cleanup:b}{cleanup:e} coordinates termination. -The calls to \co{smp_mb()} here and in \co{eventual()} ensure -that all updates to \co{global_count} are visible to code following -the call to \co{count_cleanup()}. +The call to \co{smp_load_acquire()} here and the call to \co{smp_store_release()} +in \co{eventual()} ensure that all updates to \co{global_count} are visible +to code following the call to \co{count_cleanup()}. This approach gives extremely fast counter read-out while still supporting linear counter-update scalability.
Looks good to me! Thanks.
Paul E. McKenney
AppliedQuoted 53 lines · Akira Yokosawa
Quoted 52 lines · Alan Huang
The original memory barriers in
count_stat_eventual.censure writing toglobal_counthappens before writing to stopflag and reading from stopflag happens before later reading fromglobal_count.Thus,
smp_load_acquireandsmp_store_releasewill suffice.Signed-off-by Alan Huang <[email protected]>--- CodeSamples/count/count_stat_eventual.c | 6 ++---- count/count.tex | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-)CodeSamples/count/count_stat_eventual.c +2
-4@@ -51,8 +51,7 @@ void *eventual(void *arg) //\lnlbl{eventual:b}WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 );if (READ_ONCE (stopflag)) { -smp_mb (); -WRITE_ONCE (stopflag, stopflag +1 ); +smp_store_release (&stopflag, stopflag +1 ); } }return NULL ;@@ -73,9 +72,8 @@ void count_init(void) //\lnlbl{init:b}void count_cleanup (void )//\lnlbl{cleanup:b} {WRITE_ONCE (stopflag,1 ); -while (READ_ONCE (stopflag) <3 ) +while (smp_load_acquire (&stopflag) <3 )poll (NULL ,0 ,1 ); -smp_mb (); }//\lnlbl{cleanup:e} //\end{snippet} count/count.tex +3
-3@@ -1013,9 +1013,9 @@ between passes. The \co{count_cleanup()} function on \clnrefrange{cleanup:b}{cleanup:e} coordinates termination. -The calls to \co{smp_mb()} here and in \co{eventual()} ensure -that all updates to \co{global_count} are visible to code following -the call to \co{count_cleanup()}. +The call to \co{smp_load_acquire()} here and the call to \co{smp_store_release()} +in \co{eventual()} ensure that all updates to \co{global_count} are visible +to code following the call to \co{count_cleanup()}.
Quoted 6 lines
count/count.tex between passes. · line 1021
Quoted 2 lines
count/count.tex +0
-0This approach gives extremely fast counter read-out while still supporting linear counter-update scalability.Looks good to me! Thanks.
Reviewed-by Akira Yokosawa <[email protected]>
Queued and pushed with the inevitable wordsmithing, thank you both!
Thanx, Paul