From cce8c1981eac4633ebb0a8e6bfd3e20beb1144ba Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 11 Aug 2022 19:13:28 -0400 Subject: [PATCH] fix: lock tracking --- runtime/include/generic_thread.h | 7 ++++--- runtime/include/lock.h | 23 ++++++++++++----------- runtime/src/generic_thread.c | 7 ++++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/runtime/include/generic_thread.h b/runtime/include/generic_thread.h index 5069d9f..61f4e6a 100644 --- a/runtime/include/generic_thread.h +++ b/runtime/include/generic_thread.h @@ -3,9 +3,10 @@ #include #include -extern thread_local uint64_t generic_thread_lock_duration; -extern thread_local uint64_t generic_thread_lock_longest; -extern thread_local uint64_t generic_thread_start_timestamp; +extern thread_local uint64_t generic_thread_lock_duration; +extern thread_local uint64_t generic_thread_lock_longest; +extern thread_local const char *generic_thread_lock_longest_fn; +extern thread_local uint64_t generic_thread_start_timestamp; void generic_thread_dump_lock_overhead(void); void generic_thread_initialize(void); diff --git a/runtime/include/lock.h b/runtime/include/lock.h index 81a7681..9a7c676 100644 --- a/runtime/include/lock.h +++ b/runtime/include/lock.h @@ -29,23 +29,24 @@ typedef ck_spinlock_mcs_t lock_t; * @param unique_variable_name - a unique prefix to hygienically namespace an associated lock/unlock pair */ -#define LOCK_LOCK_WITH_BOOKKEEPING(lock, unique_variable_name) \ - struct ck_spinlock_mcs _hygiene_##unique_variable_name##_node; \ - uint64_t _hygiene_##unique_variable_name##_pre = __getcycles(); \ - ck_spinlock_mcs_lock((lock), &(_hygiene_##unique_variable_name##_node)); \ - uint64_t _hygiene_##unique_variable_name##_duration = (__getcycles() - _hygiene_##unique_variable_name##_pre); \ - if (_hygiene_##unique_variable_name##_duration > generic_thread_lock_longest) { \ - generic_thread_lock_longest = _hygiene_##unique_variable_name##_duration; \ - } \ - generic_thread_lock_duration += _hygiene_##unique_variable_name##_duration; +#define LOCK_LOCK_WITH_BOOKKEEPING(lock, unique_variable_name) \ + struct ck_spinlock_mcs _hygiene_##unique_variable_name##_node; \ + uint64_t _hygiene_##unique_variable_name##_pre = __getcycles(); \ + ck_spinlock_mcs_lock((lock), &(_hygiene_##unique_variable_name##_node)); /** * Unlocks a lock * @param lock - the address of the lock * @param unique_variable_name - a unique prefix to hygienically namespace an associated lock/unlock pair */ -#define LOCK_UNLOCK_WITH_BOOKKEEPING(lock, unique_variable_name) \ - ck_spinlock_mcs_unlock(lock, &(_hygiene_##unique_variable_name##_node)); +#define LOCK_UNLOCK_WITH_BOOKKEEPING(lock, unique_variable_name) \ + ck_spinlock_mcs_unlock(lock, &(_hygiene_##unique_variable_name##_node)); \ + uint64_t _hygiene_##unique_variable_name##_duration = (__getcycles() - _hygiene_##unique_variable_name##_pre); \ + if (_hygiene_##unique_variable_name##_duration > generic_thread_lock_longest) { \ + generic_thread_lock_longest = _hygiene_##unique_variable_name##_duration; \ + generic_thread_lock_longest_fn = __func__; \ + } \ + generic_thread_lock_duration += _hygiene_##unique_variable_name##_duration; /** * Locks a lock, keeping track of overhead diff --git a/runtime/src/generic_thread.c b/runtime/src/generic_thread.c index eb9c453..e774784 100644 --- a/runtime/src/generic_thread.c +++ b/runtime/src/generic_thread.c @@ -9,9 +9,10 @@ extern uint32_t runtime_quantum_us; /* Implemented by listener and workers */ -thread_local uint64_t generic_thread_lock_duration = 0; -thread_local uint64_t generic_thread_lock_longest = 0; -thread_local uint64_t generic_thread_start_timestamp = 0; +thread_local uint64_t generic_thread_lock_duration = 0; +thread_local uint64_t generic_thread_lock_longest = 0; +thread_local uint64_t generic_thread_start_timestamp = 0; +thread_local const char *generic_thread_lock_longest_fn = NULL; void generic_thread_initialize()