From: Mathieu Desnoyers Date: Fri, 12 Jun 2009 17:31:02 +0000 (-0400) Subject: Add -c option for read-side C.S. length to tests X-Git-Tag: v0.1~165 X-Git-Url: https://git.lttng.org/?a=commitdiff_plain;h=8b632babd61dd1708c4cf95f1f417469f8f6a528;hp=b4fde1d45c43e18b0589a983509bea738c54cbce;p=urcu.git Add -c option for read-side C.S. length to tests Signed-off-by: Mathieu Desnoyers --- diff --git a/test_mutex.c b/test_mutex.c index 57f5842..29c840b 100644 --- a/test_mutex.c +++ b/test_mutex.c @@ -71,6 +71,9 @@ static volatile struct test_array test_array = { 8 }; static unsigned long duration; +/* read-side C.S. duration, in us */ +static unsigned long rduration; + /* * returns 0 if test should end. */ @@ -130,6 +133,8 @@ void *thr_reader(void *data) for (;;) { pthread_mutex_lock(&lock); assert(test_array.a == 8); + if (unlikely(rduration)) + usleep(rduration); pthread_mutex_unlock(&lock); nr_reads++; if (unlikely(!test_duration_read())) @@ -180,6 +185,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(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } @@ -244,6 +250,13 @@ int main(int argc, char **argv) use_affinity = 1; printf("Adding CPU %d affinity\n", a); break; + case 'c': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + rduration = atoi(argv[++i]); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); diff --git a/test_perthreadlock.c b/test_perthreadlock.c index 4f46d23..a2abb8d 100644 --- a/test_perthreadlock.c +++ b/test_perthreadlock.c @@ -75,6 +75,9 @@ static volatile struct test_array test_array = { 8 }; static unsigned long duration; +/* read-side C.S. duration, in us */ +static unsigned long rduration; + /* * returns 0 if test should end. */ @@ -134,6 +137,8 @@ void *thr_reader(void *data) for (;;) { pthread_mutex_lock(&per_thread_lock[tidx].lock); assert(test_array.a == 8); + if (unlikely(rduration)) + usleep(rduration); pthread_mutex_unlock(&per_thread_lock[tidx].lock); nr_reads++; if (unlikely(!test_duration_read())) @@ -189,6 +194,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(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } @@ -253,6 +259,13 @@ int main(int argc, char **argv) use_affinity = 1; printf("Adding CPU %d affinity\n", a); break; + case 'c': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + rduration = atoi(argv[++i]); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); diff --git a/test_qsbr.c b/test_qsbr.c index f56234b..7ff1aca 100644 --- a/test_qsbr.c +++ b/test_qsbr.c @@ -65,6 +65,9 @@ static struct test_array *test_rcu_pointer; static unsigned long duration; +/* read-side C.S. duration, in us */ +static unsigned long rduration; + /* * returns 0 if test should end. */ @@ -164,6 +167,8 @@ void *thr_reader(void *_count) debug_yield_read(); if (local_ptr) assert(local_ptr->a == 8); + if (unlikely(rduration)) + usleep(rduration); _rcu_read_unlock(); nr_reads++; /* QS each 1024 reads */ @@ -228,6 +233,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(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } @@ -291,6 +297,13 @@ int main(int argc, char **argv) use_affinity = 1; printf("Adding CPU %d affinity\n", a); break; + case 'c': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + rduration = atoi(argv[++i]); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); diff --git a/test_rwlock.c b/test_rwlock.c index 0fdaad6..4ec427b 100644 --- a/test_rwlock.c +++ b/test_rwlock.c @@ -71,6 +71,9 @@ static volatile struct test_array test_array = { 8 }; static unsigned long duration; +/* read-side C.S. duration, in us */ +static unsigned long rduration; + /* * returns 0 if test should end. */ @@ -127,6 +130,8 @@ void *thr_reader(void *_count) for (;;) { pthread_rwlock_rdlock(&lock); assert(test_array.a == 8); + if (unlikely(rduration)) + usleep(rduration); pthread_rwlock_unlock(&lock); nr_reads++; if (unlikely(!test_duration_read())) @@ -177,6 +182,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(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } @@ -241,6 +247,13 @@ int main(int argc, char **argv) use_affinity = 1; printf("Adding CPU %d affinity\n", a); break; + case 'c': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + rduration = atoi(argv[++i]); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); diff --git a/test_urcu.c b/test_urcu.c index 016fa3f..85f4a36 100644 --- a/test_urcu.c +++ b/test_urcu.c @@ -69,6 +69,9 @@ static struct test_array *test_rcu_pointer; static unsigned long duration; +/* read-side C.S. duration, in us */ +static unsigned long rduration; + /* * returns 0 if test should end. */ @@ -168,6 +171,8 @@ void *thr_reader(void *_count) debug_yield_read(); if (local_ptr) assert(local_ptr->a == 8); + if (unlikely(rduration)) + usleep(rduration); rcu_read_unlock(); nr_reads++; if (unlikely(!test_duration_read())) @@ -229,6 +234,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(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } @@ -292,6 +298,13 @@ int main(int argc, char **argv) use_affinity = 1; printf("Adding CPU %d affinity\n", a); break; + case 'c': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + rduration = atoi(argv[++i]); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv);