Blame jemalloc/include/jemalloc/internal/mutex_prof.h

Packit 345191
#ifndef JEMALLOC_INTERNAL_MUTEX_PROF_H
Packit 345191
#define JEMALLOC_INTERNAL_MUTEX_PROF_H
Packit 345191
Packit 345191
#include "jemalloc/internal/atomic.h"
Packit 345191
#include "jemalloc/internal/nstime.h"
Packit 345191
#include "jemalloc/internal/tsd_types.h"
Packit 345191
Packit 345191
#define MUTEX_PROF_GLOBAL_MUTEXES					\
Packit 345191
    OP(background_thread)						\
Packit 345191
    OP(ctl)								\
Packit 345191
    OP(prof)
Packit 345191
Packit 345191
typedef enum {
Packit 345191
#define OP(mtx) global_prof_mutex_##mtx,
Packit 345191
	MUTEX_PROF_GLOBAL_MUTEXES
Packit 345191
#undef OP
Packit 345191
	mutex_prof_num_global_mutexes
Packit 345191
} mutex_prof_global_ind_t;
Packit 345191
Packit 345191
#define MUTEX_PROF_ARENA_MUTEXES					\
Packit 345191
    OP(large)								\
Packit 345191
    OP(extent_avail)							\
Packit 345191
    OP(extents_dirty)							\
Packit 345191
    OP(extents_muzzy)							\
Packit 345191
    OP(extents_retained)						\
Packit 345191
    OP(decay_dirty)							\
Packit 345191
    OP(decay_muzzy)							\
Packit 345191
    OP(base)								\
Packit 345191
    OP(tcache_list)
Packit 345191
Packit 345191
typedef enum {
Packit 345191
#define OP(mtx) arena_prof_mutex_##mtx,
Packit 345191
	MUTEX_PROF_ARENA_MUTEXES
Packit 345191
#undef OP
Packit 345191
	mutex_prof_num_arena_mutexes
Packit 345191
} mutex_prof_arena_ind_t;
Packit 345191
Packit 345191
/*
Packit 345191
 * The forth parameter is a boolean value that is true for derived rate counters
Packit 345191
 * and false for real ones.
Packit 345191
 */
Packit 345191
#define MUTEX_PROF_UINT64_COUNTERS					\
Packit 345191
    OP(num_ops, uint64_t, "n_lock_ops", false, num_ops)					\
Packit 345191
    OP(num_ops_ps, uint64_t, "(#/sec)", true, num_ops)				\
Packit 345191
    OP(num_wait, uint64_t, "n_waiting", false, num_wait)				\
Packit 345191
    OP(num_wait_ps, uint64_t, "(#/sec)", true, num_wait)				\
Packit 345191
    OP(num_spin_acq, uint64_t, "n_spin_acq", false, num_spin_acq)			\
Packit 345191
    OP(num_spin_acq_ps, uint64_t, "(#/sec)", true, num_spin_acq)			\
Packit 345191
    OP(num_owner_switch, uint64_t, "n_owner_switch", false, num_owner_switch)		\
Packit 345191
    OP(num_owner_switch_ps, uint64_t, "(#/sec)", true, num_owner_switch)	\
Packit 345191
    OP(total_wait_time, uint64_t, "total_wait_ns", false, total_wait_time)		\
Packit 345191
    OP(total_wait_time_ps, uint64_t, "(#/sec)", true, total_wait_time)		\
Packit 345191
    OP(max_wait_time, uint64_t, "max_wait_ns", false, max_wait_time)
Packit 345191
Packit 345191
#define MUTEX_PROF_UINT32_COUNTERS					\
Packit 345191
    OP(max_num_thds, uint32_t, "max_n_thds", false, max_num_thds)
Packit 345191
Packit 345191
#define MUTEX_PROF_COUNTERS						\
Packit 345191
		MUTEX_PROF_UINT64_COUNTERS				\
Packit 345191
		MUTEX_PROF_UINT32_COUNTERS
Packit 345191
Packit 345191
#define OP(counter, type, human, derived, base_counter) mutex_counter_##counter,
Packit 345191
Packit 345191
#define COUNTER_ENUM(counter_list, t)					\
Packit 345191
		typedef enum {						\
Packit 345191
			counter_list					\
Packit 345191
			mutex_prof_num_##t##_counters			\
Packit 345191
		} mutex_prof_##t##_counter_ind_t;
Packit 345191
Packit 345191
COUNTER_ENUM(MUTEX_PROF_UINT64_COUNTERS, uint64_t)
Packit 345191
COUNTER_ENUM(MUTEX_PROF_UINT32_COUNTERS, uint32_t)
Packit 345191
Packit 345191
#undef COUNTER_ENUM
Packit 345191
#undef OP
Packit 345191
Packit 345191
typedef struct {
Packit 345191
	/*
Packit 345191
	 * Counters touched on the slow path, i.e. when there is lock
Packit 345191
	 * contention.  We update them once we have the lock.
Packit 345191
	 */
Packit 345191
	/* Total time (in nano seconds) spent waiting on this mutex. */
Packit 345191
	nstime_t		tot_wait_time;
Packit 345191
	/* Max time (in nano seconds) spent on a single lock operation. */
Packit 345191
	nstime_t		max_wait_time;
Packit 345191
	/* # of times have to wait for this mutex (after spinning). */
Packit 345191
	uint64_t		n_wait_times;
Packit 345191
	/* # of times acquired the mutex through local spinning. */
Packit 345191
	uint64_t		n_spin_acquired;
Packit 345191
	/* Max # of threads waiting for the mutex at the same time. */
Packit 345191
	uint32_t		max_n_thds;
Packit 345191
	/* Current # of threads waiting on the lock.  Atomic synced. */
Packit 345191
	atomic_u32_t		n_waiting_thds;
Packit 345191
Packit 345191
	/*
Packit 345191
	 * Data touched on the fast path.  These are modified right after we
Packit 345191
	 * grab the lock, so it's placed closest to the end (i.e. right before
Packit 345191
	 * the lock) so that we have a higher chance of them being on the same
Packit 345191
	 * cacheline.
Packit 345191
	 */
Packit 345191
	/* # of times the mutex holder is different than the previous one. */
Packit 345191
	uint64_t		n_owner_switches;
Packit 345191
	/* Previous mutex holder, to facilitate n_owner_switches. */
Packit 345191
	tsdn_t			*prev_owner;
Packit 345191
	/* # of lock() operations in total. */
Packit 345191
	uint64_t		n_lock_ops;
Packit 345191
} mutex_prof_data_t;
Packit 345191
Packit 345191
#endif /* JEMALLOC_INTERNAL_MUTEX_PROF_H */