1 #ifndef JEMALLOC_INTERNAL_MUTEX_PROF_H 2 #define JEMALLOC_INTERNAL_MUTEX_PROF_H 3 4 #include "jemalloc/internal/atomic.h" 5 #include "jemalloc/internal/nstime.h" 6 #include "jemalloc/internal/tsd_types.h" 7 8 #define MUTEX_PROF_GLOBAL_MUTEXES \ 9 OP(background_thread) \ 10 OP(ctl) \ 11 OP(prof) 12 13 typedef enum { 14 #define OP(mtx) global_prof_mutex_##mtx, 15 MUTEX_PROF_GLOBAL_MUTEXES 16 #undef OP 17 mutex_prof_num_global_mutexes 18 } mutex_prof_global_ind_t; 19 20 #define MUTEX_PROF_ARENA_MUTEXES \ 21 OP(large) \ 22 OP(extent_avail) \ 23 OP(extents_dirty) \ 24 OP(extents_muzzy) \ 25 OP(extents_retained) \ 26 OP(decay_dirty) \ 27 OP(decay_muzzy) \ 28 OP(base) \ 29 OP(tcache_list) 30 31 typedef enum { 32 #define OP(mtx) arena_prof_mutex_##mtx, 33 MUTEX_PROF_ARENA_MUTEXES 34 #undef OP 35 mutex_prof_num_arena_mutexes 36 } mutex_prof_arena_ind_t; 37 38 #define MUTEX_PROF_COUNTERS \ 39 OP(num_ops, uint64_t) \ 40 OP(num_wait, uint64_t) \ 41 OP(num_spin_acq, uint64_t) \ 42 OP(num_owner_switch, uint64_t) \ 43 OP(total_wait_time, uint64_t) \ 44 OP(max_wait_time, uint64_t) \ 45 OP(max_num_thds, uint32_t) 46 47 typedef enum { 48 #define OP(counter, type) mutex_counter_##counter, 49 MUTEX_PROF_COUNTERS 50 #undef OP 51 mutex_prof_num_counters 52 } mutex_prof_counter_ind_t; 53 54 typedef struct { 55 /* 56 * Counters touched on the slow path, i.e. when there is lock 57 * contention. We update them once we have the lock. 58 */ 59 /* Total time (in nano seconds) spent waiting on this mutex. */ 60 nstime_t tot_wait_time; 61 /* Max time (in nano seconds) spent on a single lock operation. */ 62 nstime_t max_wait_time; 63 /* # of times have to wait for this mutex (after spinning). */ 64 uint64_t n_wait_times; 65 /* # of times acquired the mutex through local spinning. */ 66 uint64_t n_spin_acquired; 67 /* Max # of threads waiting for the mutex at the same time. */ 68 uint32_t max_n_thds; 69 /* Current # of threads waiting on the lock. Atomic synced. */ 70 atomic_u32_t n_waiting_thds; 71 72 /* 73 * Data touched on the fast path. These are modified right after we 74 * grab the lock, so it's placed closest to the end (i.e. right before 75 * the lock) so that we have a higher chance of them being on the same 76 * cacheline. 77 */ 78 /* # of times the mutex holder is different than the previous one. */ 79 uint64_t n_owner_switches; 80 /* Previous mutex holder, to facilitate n_owner_switches. */ 81 tsdn_t *prev_owner; 82 /* # of lock() operations in total. */ 83 uint64_t n_lock_ops; 84 } mutex_prof_data_t; 85 86 #endif /* JEMALLOC_INTERNAL_MUTEX_PROF_H */ 87