>From 6516d48db858f549cf663d61b55188d515746915 Mon Sep 17 00:00:00 2001 From: Akira Yokosawa <akiyks@xxxxxxxxx> Date: Fri, 15 Dec 2017 23:17:59 +0900 Subject: [PATCH 1/4] count: Get rid of ACCESS_ONCE() in code snippet Also update code under CodeSamples/count/. Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx> --- CodeSamples/count/count_lim_sig.c | 26 +++++++++++++------------- CodeSamples/count/counttorture.h | 8 ++++---- CodeSamples/count/limtorture.h | 18 +++++++++--------- count/count.tex | 28 ++++++++++++++-------------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/CodeSamples/count/count_lim_sig.c b/CodeSamples/count/count_lim_sig.c index dbe4496..104d116 100644 --- a/CodeSamples/count/count_lim_sig.c +++ b/CodeSamples/count/count_lim_sig.c @@ -50,12 +50,12 @@ static void globalize_count(void) static void flush_local_count_sig(int unused) { - if (ACCESS_ONCE(theft) != THEFT_REQ) + if (READ_ONCE(theft) != THEFT_REQ) return; smp_mb(); - ACCESS_ONCE(theft) = THEFT_ACK; + WRITE_ONCE(theft, THEFT_ACK); if (!counting) { - ACCESS_ONCE(theft) = THEFT_READY; + WRITE_ONCE(theft, THEFT_READY); } smp_mb(); } @@ -68,25 +68,25 @@ static void flush_local_count(void) for_each_tid(t, tid) if (theftp[t] != NULL) { if (*countermaxp[t] == 0) { - ACCESS_ONCE(*theftp[t]) = THEFT_READY; + WRITE_ONCE(*theftp[t], THEFT_READY); continue; } - ACCESS_ONCE(*theftp[t]) = THEFT_REQ; + WRITE_ONCE(*theftp[t], THEFT_REQ); pthread_kill(tid, SIGUSR1); } for_each_tid(t, tid) { if (theftp[t] == NULL) continue; - while (ACCESS_ONCE(*theftp[t]) != THEFT_READY) { + while (READ_ONCE(*theftp[t]) != THEFT_READY) { poll(NULL, 0, 1); - if (ACCESS_ONCE(*theftp[t]) == THEFT_REQ) + if (READ_ONCE(*theftp[t]) == THEFT_REQ) pthread_kill(tid, SIGUSR1); } globalcount += *counterp[t]; *counterp[t] = 0; globalreserve -= *countermaxp[t]; *countermaxp[t] = 0; - ACCESS_ONCE(*theftp[t]) = THEFT_IDLE; + WRITE_ONCE(*theftp[t], THEFT_IDLE); } } @@ -109,16 +109,16 @@ int add_count(unsigned long delta) counting = 1; barrier(); - if (countermax - counter >= delta && ACCESS_ONCE(theft) <= THEFT_REQ) { + if (countermax - counter >= delta && READ_ONCE(theft) <= THEFT_REQ) { counter += delta; fastpath = 1; } barrier(); counting = 0; barrier(); - if (ACCESS_ONCE(theft) == THEFT_ACK) { + if (READ_ONCE(theft) == THEFT_ACK) { smp_mb(); - ACCESS_ONCE(theft) = THEFT_READY; + WRITE_ONCE(theft, THEFT_READY); } if (fastpath) return 1; @@ -150,9 +150,9 @@ int sub_count(unsigned long delta) barrier(); counting = 0; barrier(); - if (ACCESS_ONCE(theft) == THEFT_ACK) { + if (READ_ONCE(theft) == THEFT_ACK) { smp_mb(); - ACCESS_ONCE(theft) = THEFT_READY; + WRITE_ONCE(theft, THEFT_READY); } if (fastpath) return 1; diff --git a/CodeSamples/count/counttorture.h b/CodeSamples/count/counttorture.h index 1565a70..3bfd213 100644 --- a/CodeSamples/count/counttorture.h +++ b/CodeSamples/count/counttorture.h @@ -81,9 +81,9 @@ void *count_read_perf_test(void *arg) run_on(me); count_register_thread(&k); atomic_inc(&nthreadsrunning); - while (ACCESS_ONCE(goflag) == GOFLAG_INIT) + while (READ_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); - while (ACCESS_ONCE(goflag) == GOFLAG_RUN) { + while (READ_ONCE(goflag) == GOFLAG_RUN) { for (i = COUNT_READ_RUN; i > 0; i--) { j += read_count(); barrier(); @@ -105,9 +105,9 @@ void *count_update_perf_test(void *arg) count_register_thread(&k); atomic_inc(&nthreadsrunning); - while (ACCESS_ONCE(goflag) == GOFLAG_INIT) + while (READ_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); - while (ACCESS_ONCE(goflag) == GOFLAG_RUN) { + while (READ_ONCE(goflag) == GOFLAG_RUN) { for (i = COUNT_UPDATE_RUN; i > 0; i--) { inc_count(); barrier(); diff --git a/CodeSamples/count/limtorture.h b/CodeSamples/count/limtorture.h index 20862a9..4866e28 100644 --- a/CodeSamples/count/limtorture.h +++ b/CodeSamples/count/limtorture.h @@ -89,7 +89,7 @@ void *count_updown_limit(void *arg) run_on(me); count_register_thread(); atomic_inc(&nthreadsrunning); - while (ACCESS_ONCE(goflag) != GOFLAG_RUN_UP) + while (READ_ONCE(goflag) != GOFLAG_RUN_UP) poll(NULL, 0, 1); while (add_count(1)) { n_updates_local++; @@ -97,7 +97,7 @@ void *count_updown_limit(void *arg) __get_thread_var(n_updates_pt) += n_updates_local; smp_mb(); atomic_inc(&n_threads_run_up); - while (ACCESS_ONCE(goflag) != GOFLAG_RUN_DOWN) + while (READ_ONCE(goflag) != GOFLAG_RUN_DOWN) poll(NULL, 0, 1); n_updates_local = 0LL; while (sub_count(1)) { @@ -106,7 +106,7 @@ void *count_updown_limit(void *arg) __get_thread_var(n_updates_pt) += n_updates_local; smp_mb(); atomic_inc(&n_threads_run_down); - while (ACCESS_ONCE(goflag) != GOFLAG_STOP) + while (READ_ONCE(goflag) != GOFLAG_STOP) poll(NULL, 0, 1); count_unregister_thread(nthreadsexpected); return NULL; @@ -120,7 +120,7 @@ void *count_updown_hog(void *arg) run_on(me); count_register_thread(); atomic_inc(&nthreadsrunning); - while (ACCESS_ONCE(goflag) == GOFLAG_INIT) + while (READ_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); delta = num_online_threads() * 20; if (!add_count(delta)) { @@ -130,7 +130,7 @@ void *count_updown_hog(void *arg) __get_thread_var(n_updates_pt) += delta; smp_mb(); atomic_inc(&n_threads_hog); - while (ACCESS_ONCE(goflag) != GOFLAG_STOP) + while (READ_ONCE(goflag) != GOFLAG_STOP) poll(NULL, 0, 1); count_unregister_thread(nthreadsexpected); return NULL; @@ -209,9 +209,9 @@ void *count_read_perf_test(void *arg) run_on(me); count_register_thread(); atomic_inc(&nthreadsrunning); - while (ACCESS_ONCE(goflag) == GOFLAG_INIT) + while (READ_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); - while (ACCESS_ONCE(goflag) == GOFLAG_RUN) { + while (READ_ONCE(goflag) == GOFLAG_RUN) { for (i = COUNT_READ_RUN; i > 0; i--) { j += read_count(); barrier(); @@ -232,9 +232,9 @@ void *count_update_perf_test(void *arg) count_register_thread(); atomic_inc(&nthreadsrunning); - while (ACCESS_ONCE(goflag) == GOFLAG_INIT) + while (READ_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); - while (ACCESS_ONCE(goflag) == GOFLAG_RUN) { + while (READ_ONCE(goflag) == GOFLAG_RUN) { for (i = COUNT_UPDATE_RUN; i > 0; i--) { add_count(1); sub_count(1); diff --git a/count/count.tex b/count/count.tex index 900c384..277627d 100644 --- a/count/count.tex +++ b/count/count.tex @@ -2719,12 +2719,12 @@ and \co{theft} variables, respectively. 8 9 static void flush_local_count_sig(int unused) 10 { - 11 if (ACCESS_ONCE(theft) != THEFT_REQ) + 11 if (READ_ONCE(theft) != THEFT_REQ) 12 return; 13 smp_mb(); - 14 ACCESS_ONCE(theft) = THEFT_ACK; + 14 WRITE_ONCE(theft, THEFT_ACK); 15 if (!counting) { - 16 ACCESS_ONCE(theft) = THEFT_READY; + 16 WRITE_ONCE(theft, THEFT_READY); 17 } 18 smp_mb(); 19 } @@ -2737,25 +2737,25 @@ and \co{theft} variables, respectively. 26 for_each_tid(t, tid) 27 if (theftp[t] != NULL) { 28 if (*countermaxp[t] == 0) { - 29 ACCESS_ONCE(*theftp[t]) = THEFT_READY; + 29 WRITE_ONCE(*theftp[t], THEFT_READY); 30 continue; 31 } - 32 ACCESS_ONCE(*theftp[t]) = THEFT_REQ; + 32 WRITE_ONCE(*theftp[t], THEFT_REQ); 33 pthread_kill(tid, SIGUSR1); 34 } 35 for_each_tid(t, tid) { 36 if (theftp[t] == NULL) 37 continue; - 38 while (ACCESS_ONCE(*theftp[t]) != THEFT_READY) { + 38 while (READ_ONCE(*theftp[t]) != THEFT_READY) { 39 poll(NULL, 0, 1); - 40 if (ACCESS_ONCE(*theftp[t]) == THEFT_REQ) + 40 if (READ_ONCE(*theftp[t]) == THEFT_REQ) 41 pthread_kill(tid, SIGUSR1); 42 } 43 globalcount += *counterp[t]; 44 *counterp[t] = 0; 45 globalreserve -= *countermaxp[t]; 46 *countermaxp[t] = 0; - 47 ACCESS_ONCE(*theftp[t]) = THEFT_IDLE; + 47 WRITE_ONCE(*theftp[t], THEFT_IDLE); 48 } 49 } 50 @@ -2907,16 +2907,16 @@ earlier examples. 5 counting = 1; 6 barrier(); 7 if (countermax - counter >= delta && - 8 ACCESS_ONCE(theft) <= THEFT_REQ) { + 8 READ_ONCE(theft) <= THEFT_REQ) { 9 counter += delta; 10 fastpath = 1; 11 } 12 barrier(); 13 counting = 0; 14 barrier(); - 15 if (ACCESS_ONCE(theft) == THEFT_ACK) { + 15 if (READ_ONCE(theft) == THEFT_ACK) { 16 smp_mb(); - 17 ACCESS_ONCE(theft) = THEFT_READY; + 17 WRITE_ONCE(theft, THEFT_READY); 18 } 19 if (fastpath) 20 return 1; @@ -2954,16 +2954,16 @@ earlier examples. 42 counting = 1; 43 barrier(); 44 if (counter >= delta && - 45 ACCESS_ONCE(theft) <= THEFT_REQ) { + 45 READ_ONCE(theft) <= THEFT_REQ) { 46 counter -= delta; 47 fastpath = 1; 48 } 49 barrier(); 50 counting = 0; 51 barrier(); - 52 if (ACCESS_ONCE(theft) == THEFT_ACK) { + 52 if (READ_ONCE(theft) == THEFT_ACK) { 53 smp_mb(); - 54 ACCESS_ONCE(theft) = THEFT_READY; + 54 WRITE_ONCE(theft, THEFT_READY); 55 } 56 if (fastpath) 57 return 1; -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe perfbook" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html