From: Mathieu Desnoyers Date: Fri, 12 Jun 2009 17:51:20 +0000 (-0400) Subject: Delay reader in loops, not us X-Git-Tag: v0.1~164 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=daddf5b0bf1ec7aeaa56c278cf4c1dd1094c174a;p=userspace-rcu.git Delay reader in loops, not us Signed-off-by: Mathieu Desnoyers --- diff --git a/test_mutex.c b/test_mutex.c index 29c840b..6fd1746 100644 --- a/test_mutex.c +++ b/test_mutex.c @@ -71,9 +71,15 @@ static volatile struct test_array test_array = { 8 }; static unsigned long duration; -/* read-side C.S. duration, in us */ +/* read-side C.S. duration, in loops */ static unsigned long rduration; +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + /* * returns 0 if test should end. */ @@ -134,7 +140,7 @@ void *thr_reader(void *data) pthread_mutex_lock(&lock); assert(test_array.a == 8); if (unlikely(rduration)) - usleep(rduration); + loop_sleep(rduration); pthread_mutex_unlock(&lock); nr_reads++; if (unlikely(!test_duration_read())) @@ -185,7 +191,7 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); - printf(" [-c duration] (reader C.S. duration (us))"); + printf(" [-c duration] (reader C.S. duration (in loops))"); printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } diff --git a/test_perthreadlock.c b/test_perthreadlock.c index a2abb8d..0fc45d9 100644 --- a/test_perthreadlock.c +++ b/test_perthreadlock.c @@ -75,9 +75,15 @@ static volatile struct test_array test_array = { 8 }; static unsigned long duration; -/* read-side C.S. duration, in us */ +/* read-side C.S. duration, in loops */ static unsigned long rduration; +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + /* * returns 0 if test should end. */ @@ -138,7 +144,7 @@ void *thr_reader(void *data) pthread_mutex_lock(&per_thread_lock[tidx].lock); assert(test_array.a == 8); if (unlikely(rduration)) - usleep(rduration); + loop_sleep(rduration); pthread_mutex_unlock(&per_thread_lock[tidx].lock); nr_reads++; if (unlikely(!test_duration_read())) @@ -194,7 +200,7 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); - printf(" [-c duration] (reader C.S. duration (us))"); + printf(" [-c duration] (reader C.S. duration (in loops))"); printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } diff --git a/test_qsbr.c b/test_qsbr.c index 7ff1aca..488c904 100644 --- a/test_qsbr.c +++ b/test_qsbr.c @@ -65,9 +65,15 @@ static struct test_array *test_rcu_pointer; static unsigned long duration; -/* read-side C.S. duration, in us */ +/* read-side C.S. duration, in loops */ static unsigned long rduration; +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + /* * returns 0 if test should end. */ @@ -168,7 +174,7 @@ void *thr_reader(void *_count) if (local_ptr) assert(local_ptr->a == 8); if (unlikely(rduration)) - usleep(rduration); + loop_sleep(rduration); _rcu_read_unlock(); nr_reads++; /* QS each 1024 reads */ @@ -233,7 +239,7 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); - printf(" [-c duration] (reader C.S. duration (us))"); + printf(" [-c duration] (reader C.S. duration (in loops))"); printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } diff --git a/test_rwlock.c b/test_rwlock.c index 4ec427b..a6f31e3 100644 --- a/test_rwlock.c +++ b/test_rwlock.c @@ -71,9 +71,15 @@ static volatile struct test_array test_array = { 8 }; static unsigned long duration; -/* read-side C.S. duration, in us */ +/* read-side C.S. duration, in loops */ static unsigned long rduration; +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + /* * returns 0 if test should end. */ @@ -131,7 +137,7 @@ void *thr_reader(void *_count) pthread_rwlock_rdlock(&lock); assert(test_array.a == 8); if (unlikely(rduration)) - usleep(rduration); + loop_sleep(rduration); pthread_rwlock_unlock(&lock); nr_reads++; if (unlikely(!test_duration_read())) @@ -182,7 +188,7 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); - printf(" [-c duration] (reader C.S. duration (us))"); + printf(" [-c duration] (reader C.S. duration (in loops))"); printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } diff --git a/test_urcu.c b/test_urcu.c index 85f4a36..fe46928 100644 --- a/test_urcu.c +++ b/test_urcu.c @@ -69,9 +69,15 @@ static struct test_array *test_rcu_pointer; static unsigned long duration; -/* read-side C.S. duration, in us */ +/* read-side C.S. duration, in loops */ static unsigned long rduration; +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + /* * returns 0 if test should end. */ @@ -172,7 +178,7 @@ void *thr_reader(void *_count) if (local_ptr) assert(local_ptr->a == 8); if (unlikely(rduration)) - usleep(rduration); + loop_sleep(rduration); rcu_read_unlock(); nr_reads++; if (unlikely(!test_duration_read())) @@ -234,7 +240,7 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); - printf(" [-c duration] (reader C.S. duration (us))"); + printf(" [-c duration] (reader C.S. duration (in loops))"); printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); }