X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Fbenchmark%2Ftest_perthreadlock.c;h=ac21444191d55092c43474d7a405e9c3a4d072c1;hp=d76b45655ab13f1a94eb07d6519b870a8f80bda0;hb=bd23a6c64e8ccff9a666441958e34793748ebd3a;hpb=f597a8b945f69aea4a3dc3b5ad2e8a2a5237ca8f diff --git a/tests/benchmark/test_perthreadlock.c b/tests/benchmark/test_perthreadlock.c index d76b456..ac21444 100644 --- a/tests/benchmark/test_perthreadlock.c +++ b/tests/benchmark/test_perthreadlock.c @@ -20,8 +20,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE -#include "config.h" #include #include #include @@ -35,7 +33,6 @@ #include #include -#include "cpuset.h" #include "thread-id.h" /* hardcoded number of CPUs */ @@ -116,11 +113,7 @@ static void set_affinity(void) } CPU_ZERO(&mask); CPU_SET(cpu, &mask); -#if SCHED_SETAFFINITY_ARGS == 2 - sched_setaffinity(0, &mask); -#else sched_setaffinity(0, sizeof(mask), &mask); -#endif #endif /* HAVE_SCHED_SETAFFINITY */ } @@ -172,6 +165,7 @@ static void urcu_mutex_unlock(pthread_mutex_t *lock) } } +static void *thr_reader(void *data) { unsigned long tidx = (unsigned long)data; @@ -206,6 +200,7 @@ void *thr_reader(void *data) } +static void *thr_writer(void *data) { unsigned long wtidx = (unsigned long)data; @@ -222,7 +217,7 @@ void *thr_writer(void *data) cmm_smp_mb(); for (;;) { - for (tidx = 0; tidx < nr_readers; tidx++) { + for (tidx = 0; tidx < (long)nr_readers; tidx++) { urcu_mutex_lock(&per_thread_lock[tidx].lock); } test_array.a = 0; @@ -245,6 +240,7 @@ void *thr_writer(void *data) return ((void*)2); } +static void show_usage(int argc, char **argv) { printf("Usage : %s nr_readers nr_writers duration (s) \n", @@ -265,6 +261,7 @@ int main(int argc, char **argv) void *tret; unsigned long long tot_reads = 0, tot_writes = 0; int i, a; + unsigned int i_thr; if (argc < 4) { show_usage(argc, argv); @@ -283,7 +280,7 @@ int main(int argc, char **argv) show_usage(argc, argv); return -1; } - + err = sscanf(argv[3], "%lu", &duration); if (err != 1) { show_usage(argc, argv); @@ -343,21 +340,21 @@ int main(int argc, char **argv) tot_nr_reads = calloc(nr_readers, sizeof(*tot_nr_reads)); tot_nr_writes = calloc(nr_writers, sizeof(*tot_nr_writes)); per_thread_lock = calloc(nr_readers, sizeof(*per_thread_lock)); - for (i = 0; i < nr_readers; i++) { - pthread_mutex_init(&per_thread_lock[i].lock, NULL); + for (i_thr = 0; i_thr < nr_readers; i_thr++) { + pthread_mutex_init(&per_thread_lock[i_thr].lock, NULL); } next_aff = 0; - for (i = 0; i < nr_readers; i++) { - err = pthread_create(&tid_reader[i], NULL, thr_reader, - (void *)(long)i); + for (i_thr = 0; i_thr < nr_readers; i_thr++) { + err = pthread_create(&tid_reader[i_thr], NULL, thr_reader, + (void *)(long)i_thr); if (err != 0) exit(1); } - for (i = 0; i < nr_writers; i++) { - err = pthread_create(&tid_writer[i], NULL, thr_writer, - (void *)(long)i); + for (i_thr = 0; i_thr < nr_writers; i_thr++) { + err = pthread_create(&tid_writer[i_thr], NULL, thr_writer, + (void *)(long)i_thr); if (err != 0) exit(1); } @@ -370,17 +367,17 @@ int main(int argc, char **argv) test_stop = 1; - for (i = 0; i < nr_readers; i++) { - err = pthread_join(tid_reader[i], &tret); + for (i_thr = 0; i_thr < nr_readers; i_thr++) { + err = pthread_join(tid_reader[i_thr], &tret); if (err != 0) exit(1); - tot_reads += tot_nr_reads[i]; + tot_reads += tot_nr_reads[i_thr]; } - for (i = 0; i < nr_writers; i++) { - err = pthread_join(tid_writer[i], &tret); + for (i_thr = 0; i_thr < nr_writers; i_thr++) { + err = pthread_join(tid_writer[i_thr], &tret); if (err != 0) exit(1); - tot_writes += tot_nr_writes[i]; + tot_writes += tot_nr_writes[i_thr]; } printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads,