X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Fbenchmark%2Ftest_urcu_assign.c;h=dcb5d1e74fa7904a0bcafd06de05e1df48354a5b;hp=6c4adc35f4f04ee25d702a46705cc5a897414b88;hb=2388c075d46055bd33ee824c399d72c219b98d90;hpb=f5ab766ee2c8300cb00ca5878b1cb464f960a66d diff --git a/tests/benchmark/test_urcu_assign.c b/tests/benchmark/test_urcu_assign.c index 6c4adc3..dcb5d1e 100644 --- a/tests/benchmark/test_urcu_assign.c +++ b/tests/benchmark/test_urcu_assign.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,16 +33,14 @@ #include #include -#include "cpuset.h" #include "thread-id.h" +#include "../common/debug-yield.h" /* hardcoded number of CPUs */ #define NR_CPUS 16384 #ifndef DYNAMIC_LINK_TEST #define _LGPL_SOURCE -#else -#define rcu_debug_yield_read() #endif #include @@ -88,7 +84,7 @@ pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; static void set_affinity(void) { -#if HAVE_SCHED_SETAFFINITY +#ifdef HAVE_SCHED_SETAFFINITY cpu_set_t mask; int cpu, ret; #endif /* HAVE_SCHED_SETAFFINITY */ @@ -96,7 +92,7 @@ static void set_affinity(void) if (!use_affinity) return; -#if HAVE_SCHED_SETAFFINITY +#ifdef HAVE_SCHED_SETAFFINITY ret = pthread_mutex_lock(&affinity_mutex); if (ret) { perror("Error in pthread mutex lock"); @@ -111,11 +107,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 */ } @@ -140,6 +132,7 @@ static unsigned int nr_writers; pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; +static void rcu_copy_mutex_lock(void) { int ret; @@ -150,6 +143,7 @@ void rcu_copy_mutex_lock(void) } } +static void rcu_copy_mutex_unlock(void) { int ret; @@ -168,8 +162,8 @@ void rcu_copy_mutex_unlock(void) * both alloc and free, which insures we never run over our tail. */ #define ARRAY_SIZE (1048576 * nr_writers) -#define ARRAY_POISON 0xDEADBEEF -static int array_index; +#define ARRAY_POISON (int) 0xDEADBEEF +static unsigned int array_index; static struct test_array *test_array; static struct test_array *test_array_alloc(void) @@ -194,6 +188,7 @@ static void test_array_free(struct test_array *ptr) ptr->a = ARRAY_POISON; } +static void *thr_reader(void *_count) { unsigned long long *count = _count; @@ -234,6 +229,7 @@ void *thr_reader(void *_count) } +static void *thr_writer(void *_count) { unsigned long long *count = _count; @@ -275,14 +271,13 @@ void *thr_writer(void *_count) return ((void*)2); } -void show_usage(int argc, char **argv) +static +void show_usage(char **argv) { printf("Usage : %s nr_readers nr_writers duration (s) \n", argv[0]); printf("OPTIONS:\n"); -#ifdef DEBUG_YIELD printf(" [-r] [-w] (yield reader and/or writer)\n"); -#endif printf(" [-d delay] (writer period (us))\n"); printf(" [-c duration] (reader C.S. duration (in loops))\n"); printf(" [-e duration] (writer C.S. duration (in loops))\n"); @@ -299,27 +294,28 @@ int main(int argc, char **argv) unsigned long long *count_reader, *count_writer; unsigned long long tot_reads = 0, tot_writes = 0; int i, a; + unsigned int i_thr; if (argc < 4) { - show_usage(argc, argv); + show_usage(argv); return -1; } err = sscanf(argv[1], "%u", &nr_readers); if (err != 1) { - show_usage(argc, argv); + show_usage(argv); return -1; } err = sscanf(argv[2], "%u", &nr_writers); if (err != 1) { - show_usage(argc, argv); + show_usage(argv); return -1; } - + err = sscanf(argv[3], "%lu", &duration); if (err != 1) { - show_usage(argc, argv); + show_usage(argv); return -1; } @@ -327,17 +323,15 @@ int main(int argc, char **argv) if (argv[i][0] != '-') continue; switch (argv[i][1]) { -#ifdef DEBUG_YIELD case 'r': - rcu_yield_active |= RCU_YIELD_READ; + rcu_debug_yield_enable(RCU_YIELD_READ); break; case 'w': - rcu_yield_active |= RCU_YIELD_WRITE; + rcu_debug_yield_enable(RCU_YIELD_WRITE); break; -#endif case 'a': if (argc < i + 2) { - show_usage(argc, argv); + show_usage(argv); return -1; } a = atoi(argv[++i]); @@ -347,21 +341,21 @@ int main(int argc, char **argv) break; case 'c': if (argc < i + 2) { - show_usage(argc, argv); + show_usage(argv); return -1; } rduration = atol(argv[++i]); break; case 'd': if (argc < i + 2) { - show_usage(argc, argv); + show_usage(argv); return -1; } wdelay = atol(argv[++i]); break; case 'e': if (argc < i + 2) { - show_usage(argc, argv); + show_usage(argv); return -1; } wduration = atol(argv[++i]); @@ -387,15 +381,15 @@ int main(int argc, char **argv) next_aff = 0; - for (i = 0; i < nr_readers; i++) { - err = pthread_create(&tid_reader[i], NULL, thr_reader, - &count_reader[i]); + for (i_thr = 0; i_thr < nr_readers; i_thr++) { + err = pthread_create(&tid_reader[i_thr], NULL, thr_reader, + &count_reader[i_thr]); if (err != 0) exit(1); } - for (i = 0; i < nr_writers; i++) { - err = pthread_create(&tid_writer[i], NULL, thr_writer, - &count_writer[i]); + for (i_thr = 0; i_thr < nr_writers; i_thr++) { + err = pthread_create(&tid_writer[i_thr], NULL, thr_writer, + &count_writer[i_thr]); if (err != 0) exit(1); } @@ -408,19 +402,19 @@ 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 += count_reader[i]; + tot_reads += count_reader[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 += count_writer[i]; + tot_writes += count_writer[i_thr]; } - + printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, tot_writes); printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu wdur %6lu " @@ -429,11 +423,13 @@ int main(int argc, char **argv) argv[0], duration, nr_readers, rduration, wduration, nr_writers, wdelay, tot_reads, tot_writes, tot_reads + tot_writes); + test_array_free(test_rcu_pointer); free(test_array); free(tid_reader); free(tid_writer); free(count_reader); free(count_writer); + return 0; }