From 17031c6df30913608de1f66ca952ed75dd1324be Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 13 Mar 2018 10:43:02 -0700 Subject: [PATCH] gettime: Rework the clock thread starting mechanism Replace two mutexes in struct clock_thread that are intended to make the clock threads start simultaneously by a fio_mutex. This patch avoids that drd reports the following: ==23831== Thread 2: ==23831== Mutex not locked by calling thread: mutex 0x6cb7bf8, recursion count 1, owner 1. ==23831== at 0x4C38EC3: pthread_mutex_unlock_intercept (drd_pthread_intercepts.c:978) ==23831== by 0x4C38EC3: pthread_mutex_unlock (drd_pthread_intercepts.c:991) ==23831== by 0x420974: clock_thread_fn (gettime.c:604) ==23831== by 0x4C34C44: vgDrd_thread_wrapper (drd_pthread_intercepts.c:444) ==23831== by 0x5E4159A: start_thread (in /lib64/libpthread-2.27.so) ==23831== by 0x6356A1E: clone (in /lib64/libc-2.27.so) ==23924== Mutex still locked at thread exit: mutex 0x6cb7bd0, recursion count 1, owner 2. ==23924== at 0x4C35BF2: pthread_join_intercept (drd_pthread_intercepts.c:711) ==23924== by 0x4C35BF2: pthread_join (drd_pthread_intercepts.c:718) ==23924== by 0x420D7F: fio_monotonic_clocktest (gettime.c:722) ==23924== by 0x420441: fio_clock_init (gettime.c:424) ==23924== by 0x437526: fio_time_init (time.c:141) ==23924== by 0x49BF41: main (fio.c:56) Signed-off-by: Bart Van Assche --- Makefile | 3 ++- gettime.c | 20 ++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 9ac9a390..eb3bddd6 100644 --- a/Makefile +++ b/Makefile @@ -231,7 +231,8 @@ T_AXMAP_OBJS += lib/lfsr.o lib/axmap.o T_AXMAP_PROGS = t/axmap T_LFSR_TEST_OBJS = t/lfsr-test.o -T_LFSR_TEST_OBJS += lib/lfsr.o gettime.o t/log.o t/debug.o t/arch.o +T_LFSR_TEST_OBJS += lib/lfsr.o gettime.o fio_sem.o pshared.o \ + t/log.o t/debug.o t/arch.o T_LFSR_TEST_PROGS = t/lfsr-test T_GEN_RAND_OBJS = t/gen-rand.o diff --git a/gettime.c b/gettime.c index c256a96c..57c66f7e 100644 --- a/gettime.c +++ b/gettime.c @@ -8,6 +8,7 @@ #include #include "fio.h" +#include "fio_sem.h" #include "smalloc.h" #include "hash.h" @@ -563,8 +564,7 @@ struct clock_thread { pthread_t thread; int cpu; int debug; - pthread_mutex_t lock; - pthread_mutex_t started; + struct fio_sem lock; unsigned long nr_entries; uint32_t *seq; struct clock_entry *entries; @@ -600,8 +600,7 @@ static void *clock_thread_fn(void *data) goto err; } - pthread_mutex_lock(&t->lock); - pthread_mutex_unlock(&t->started); + fio_sem_down(&t->lock); first = get_cpu_clock(); c = &t->entries[0]; @@ -702,9 +701,7 @@ int fio_monotonic_clocktest(int debug) t->seq = &seq; t->nr_entries = nr_entries; t->entries = &entries[i * nr_entries]; - pthread_mutex_init(&t->lock, NULL); - pthread_mutex_init(&t->started, NULL); - pthread_mutex_lock(&t->lock); + __fio_sem_init(&t->lock, FIO_SEM_LOCKED); if (pthread_create(&t->thread, NULL, clock_thread_fn, t)) { failed++; nr_cpus = i; @@ -715,13 +712,7 @@ int fio_monotonic_clocktest(int debug) for (i = 0; i < nr_cpus; i++) { struct clock_thread *t = &cthreads[i]; - pthread_mutex_lock(&t->started); - } - - for (i = 0; i < nr_cpus; i++) { - struct clock_thread *t = &cthreads[i]; - - pthread_mutex_unlock(&t->lock); + fio_sem_up(&t->lock); } for (i = 0; i < nr_cpus; i++) { @@ -731,6 +722,7 @@ int fio_monotonic_clocktest(int debug) pthread_join(t->thread, &ret); if (ret) failed++; + __fio_sem_remove(&t->lock); } free(cthreads); -- 2.25.1