From d0f47b9bf9bb6b38dfe379b3aa19af09ff47a667 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 1 Jul 2019 21:55:03 +0200 Subject: add barrier to larson benchmark The barrier prevents worker thread from doing work before the main thread starts the timing. This behaviour was mentioned in the paper: Mostly Lock-Free Malloc by Dave Dice, Alex Garthwaite --- src/benchmarks/larson/larson.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/benchmarks/larson/larson.cc b/src/benchmarks/larson/larson.cc index be8038f..3da7a12 100644 --- a/src/benchmarks/larson/larson.cc +++ b/src/benchmarks/larson/larson.cc @@ -172,6 +172,8 @@ typedef struct thr_data { int cThreads ; unsigned long cBytesAlloced ; + pthread_barrier_t *barrier; + volatile int finished ; struct lran2_st rgen ; @@ -436,6 +438,9 @@ void runthreads(long sleep_cnt, int min_threads, int max_threads, int chperthrea nperthread = chperthread ; stopflag = FALSE ; + + pthread_barrier_t barrier; + pthread_barrier_init(&barrier, NULL, num_threads + 1); for(i=0; i< num_threads; i++){ de_area[i].threadno = i+1 ; @@ -450,6 +455,7 @@ void runthreads(long sleep_cnt, int min_threads, int max_threads, int chperthrea de_area[i].cAllocs = 0 ; de_area[i].cFrees = 0 ; de_area[i].cThreads = 0 ; + de_area[i].barrier = &barrier ; de_area[i].finished = FALSE ; lran2_init(&de_area[i].rgen, de_area[i].seed) ; @@ -461,6 +467,8 @@ void runthreads(long sleep_cnt, int min_threads, int max_threads, int chperthrea } + pthread_barrier_wait(&barrier); + QueryPerformanceCounter( &start_cnt) ; // printf ("Sleeping for %ld seconds.\n", sleep_cnt); @@ -553,6 +561,8 @@ static void * exercise_heap( void *pinput) pdea->cThreads++ ; range = pdea->max_size - pdea->min_size ; + pthread_barrier_wait(pdea->barrier); + /* allocate NumBlocks chunks of random size */ for( cblks=0; cblksNumBlocks; cblks++){ victim = lran2(&pdea->rgen)%pdea->asize ; -- cgit v1.2.3