diff options
author | Qi Wang <interwq@gwu.edu> | 2017-03-18 00:42:10 (GMT) |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2017-03-23 07:03:28 (GMT) |
commit | f6698ec1e6752e40be9adf43ebf42ab832255afc (patch) | |
tree | 98bbb48d6edc8fe7ff5a5b5920b1286163340bac /src/mutex.c | |
parent | 74f78cafdaa0adc885f9670066d3ecf13aee1ba5 (diff) | |
download | jemalloc-f6698ec1e6752e40be9adf43ebf42ab832255afc.zip jemalloc-f6698ec1e6752e40be9adf43ebf42ab832255afc.tar.gz jemalloc-f6698ec1e6752e40be9adf43ebf42ab832255afc.tar.bz2 |
Switch to nstime_t for the time related fields in mutex profiling.
Diffstat (limited to 'src/mutex.c')
-rw-r--r-- | src/mutex.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/mutex.c b/src/mutex.c index 06ccd42..fa2770a 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -68,6 +68,7 @@ JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, void malloc_mutex_lock_slow(malloc_mutex_t *mutex) { mutex_prof_data_t *data = &mutex->prof_data; + UNUSED nstime_t before = NSTIME_ZERO_INITIALIZER; if (ncpus == 1) { goto label_spin_done; @@ -87,12 +88,11 @@ malloc_mutex_lock_slow(malloc_mutex_t *mutex) { malloc_mutex_lock_final(mutex); return; } - nstime_t now, before; label_spin_done: - nstime_init(&now, 0); - nstime_update(&now); - nstime_copy(&before, &now); - + nstime_update(&before); + /* Copy before to after to avoid clock skews. */ + nstime_t after; + nstime_copy(&after, &before); uint32_t n_thds = atomic_add_u32(&data->n_waiting_thds, 1); /* One last try as above two calls may take quite some cycles. */ if (!malloc_mutex_trylock(mutex)) { @@ -103,16 +103,18 @@ label_spin_done: /* True slow path. */ malloc_mutex_lock_final(mutex); + /* Update more slow-path only counters. */ atomic_sub_u32(&data->n_waiting_thds, 1); - nstime_update(&now); + nstime_update(&after); + + nstime_t delta; + nstime_copy(&delta, &after); + nstime_subtract(&delta, &before); - /* Update more slow-path only counters. */ - nstime_subtract(&now, &before); - uint64_t wait_time = nstime_ns(&now); data->n_wait_times++; - data->tot_wait_time += wait_time; - if (wait_time > data->max_wait_time) { - data->max_wait_time = wait_time; + nstime_add(&data->tot_wait_time, &delta); + if (nstime_compare(&data->max_wait_time, &delta) < 0) { + nstime_copy(&data->max_wait_time, &delta); } if (n_thds > data->max_n_thds) { data->max_n_thds = n_thds; |