count_stat_eventual: Remove unnecessary READ_ONCE() and smp_mb()
PATCH 1/1 count_stat_eventual: Remove unnecessary READ_ONCE() and smp_mb()
--- CodeSamples/count/count_stat_eventual.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
CodeSamples/count/count_stat_eventual.c +4 -4
@@ -40,16 +40,17 @@ void *eventual(void *arg) {int t;unsigned long sum; +int stopflag_l =0 ; -while (READ_ONCE (stopflag) <3 ) { +while (stopflag_l <3 ) { sum =0 ;for_each_thread (t) sum +=READ_ONCE (per_thread (counter, t));WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 ); -if (READ_ONCE (stopflag)) { +if ((stopflag_l =READ_ONCE (stopflag)) !=0 ) {smp_mb (); -WRITE_ONCE (stopflag,READ_ONCE (stopflag) +1 ); +WRITE_ONCE (stopflag, ++stopflag_l); } }return NULL ;
@@ -68,7 +69,6 @@ void count_init(void)void count_cleanup (void ) {WRITE_ONCE (stopflag,1 ); -smp_mb ();while (READ_ONCE (stopflag) <3 )poll (NULL ,0 ,1 );smp_mb ();
Signature · 1 line
2.7.4
Hi Paul and Akira,
This is the updated patch according to the discussion with Akira and following is the summary. Please take a look. Comments are welcome!
In function eventual( ), if the value of stopflag become larger than zero (the ''if'' branch is taken), then only the "eventual()" thread updates stopflag. So, the READ_ONCE() within the WRITE_ONCE() is not necessary. Remove it.
In function count_cleanup( ), there is no need to run smp_mb( ) in between statement writing to and statement reading from the same variable, stopflag. Remove smp_mb().
Thanks,
--Jason
Quoted 42 lines · Junchang Wang
Signed-off-by Junchang Wang <[email protected]>Signed-off-by Akira Yokosawa <[email protected]>--- CodeSamples/count/count_stat_eventual.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)CodeSamples/count/count_stat_eventual.c +4
-5@@ -40,16 +40,17 @@ void *eventual(void *arg) {int t;unsigned long sum; +int stopflag_l =0 ; -while (READ_ONCE (stopflag) <3 ) { +while (stopflag_l <3 ) { sum =0 ;for_each_thread (t) sum +=READ_ONCE (per_thread (counter, t));WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 ); -if (READ_ONCE (stopflag)) { +if ((stopflag_l =READ_ONCE (stopflag)) !=0 ) {smp_mb (); -WRITE_ONCE (stopflag,READ_ONCE (stopflag) +1 ); +WRITE_ONCE (stopflag, ++stopflag_l); } }return NULL ;@@ -68,7 +69,6 @@ void count_init(void)void count_cleanup (void ) {WRITE_ONCE (stopflag,1 ); -smp_mb ();while (READ_ONCE (stopflag) <3 )poll (NULL ,0 ,1 );smp_mb (); --2.7.4
Quoted 14 lines · Junchang Wang
Hi Paul and Akira,
This is the updated patch according to the discussion with Akira and following is the summary. Please take a look. Comments are welcome!
In function
eventual( ), if the value of stopflag become larger than zero (the ''if'' branch is taken), then only the "eventual()" thread updates stopflag. So, theREAD_ONCE()within theWRITE_ONCE()is not necessary. Remove it.
In functioncount_cleanup( ), there is no need to runsmp_mb( )in between statement writing to and statement reading from the same variable, stopflag. Removesmp_mb().
Quoted 6 lines
Thanks,
--JasonQuoted 2 lines · Junchang Wang
Signed-off-by Junchang Wang <[email protected]>Signed-off-by Akira Yokosawa <[email protected]>
Hi Jason,
Glad to know you agree with me here!
Can you resubmit a v2 of the patch to include the message above in the commit log? It would be easier for Paul to apply.
Also, since I didn't created the patch itself, I'd like you to use the following tag instead:
in front of your Signed-off-by.
Thanks, Akira
Quoted 41 lines
Quoted 40 lines
--- CodeSamples/count/count_stat_eventual.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)CodeSamples/count/count_stat_eventual.c +4
-5@@ -40,16 +40,17 @@ void *eventual(void *arg) {int t;unsigned long sum; +int stopflag_l =0 ; -while (READ_ONCE (stopflag) <3 ) { +while (stopflag_l <3 ) { sum =0 ;for_each_thread (t) sum +=READ_ONCE (per_thread (counter, t));WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 ); -if (READ_ONCE (stopflag)) { +if ((stopflag_l =READ_ONCE (stopflag)) !=0 ) {smp_mb (); -WRITE_ONCE (stopflag,READ_ONCE (stopflag) +1 ); +WRITE_ONCE (stopflag, ++stopflag_l); } }return NULL ;@@ -68,7 +69,6 @@ void count_init(void)void count_cleanup (void ) {WRITE_ONCE (stopflag,1 ); -smp_mb ();while (READ_ONCE (stopflag) <3 )poll (NULL ,0 ,1 );smp_mb (); --2.7.4
Hi Akira,
Thanks a lot for commenting on the patch. Just sent the patch version 2.
Cheers!
--Jason
Quoted 79 lines · Akira Yokosawa
Quoted 14 lines · Junchang Wang
Hi Paul and Akira,
This is the updated patch according to the discussion with Akira and following is the summary. Please take a look. Comments are welcome!
In function
eventual( ), if the value of stopflag become larger than zero (the ''if'' branch is taken), then only the "eventual()" thread updates stopflag. So, theREAD_ONCE()within theWRITE_ONCE()is not necessary. Remove it.
In functioncount_cleanup( ), there is no need to runsmp_mb( )in between statement writing to and statement reading from the same variable, stopflag. Removesmp_mb().Quoted 6 lines
Thanks,
--JasonQuoted 2 lines · Junchang Wang
Signed-off-by Junchang Wang <[email protected]>Signed-off-by Akira Yokosawa <[email protected]>Hi Jason,
Glad to know you agree with me here!
Can you resubmit a v2 of the patch to include the message above in the commit log? It would be easier for Paul to apply.
Also, since I didn't created the patch itself, I'd like you to use the following tag instead:Suggested-by Akira Yokosawa <[email protected]>in front of your Signed-off-by.
Thanks, Akira
Quoted 41 lines
Quoted 40 lines
--- CodeSamples/count/count_stat_eventual.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)CodeSamples/count/count_stat_eventual.c +4
-5@@ -40,16 +40,17 @@ void *eventual(void *arg) {int t;unsigned long sum; +int stopflag_l =0 ; -while (READ_ONCE (stopflag) <3 ) { +while (stopflag_l <3 ) { sum =0 ;for_each_thread (t) sum +=READ_ONCE (per_thread (counter, t));WRITE_ONCE (global_count, sum);poll (NULL ,0 ,1 ); -if (READ_ONCE (stopflag)) { +if ((stopflag_l =READ_ONCE (stopflag)) !=0 ) {smp_mb (); -WRITE_ONCE (stopflag,READ_ONCE (stopflag) +1 ); +WRITE_ONCE (stopflag, ++stopflag_l); } }return NULL ;@@ -68,7 +69,6 @@ void count_init(void)void count_cleanup (void ) {WRITE_ONCE (stopflag,1 ); -smp_mb ();while (READ_ONCE (stopflag) <3 )poll (NULL ,0 ,1 );smp_mb (); --2.7.4