Blame memkind-1.10.0/jemalloc/include/jemalloc/internal/prof_structs.h

Packit Service 724aca
#ifndef JEMALLOC_INTERNAL_PROF_STRUCTS_H
Packit Service 724aca
#define JEMALLOC_INTERNAL_PROF_STRUCTS_H
Packit Service 724aca
Packit Service 724aca
#include "jemalloc/internal/ckh.h"
Packit Service 724aca
#include "jemalloc/internal/mutex.h"
Packit Service 724aca
#include "jemalloc/internal/prng.h"
Packit Service 724aca
#include "jemalloc/internal/rb.h"
Packit Service 724aca
Packit Service 724aca
struct prof_bt_s {
Packit Service 724aca
	/* Backtrace, stored as len program counters. */
Packit Service 724aca
	void		**vec;
Packit Service 724aca
	unsigned	len;
Packit Service 724aca
};
Packit Service 724aca
Packit Service 724aca
#ifdef JEMALLOC_PROF_LIBGCC
Packit Service 724aca
/* Data structure passed to libgcc _Unwind_Backtrace() callback functions. */
Packit Service 724aca
typedef struct {
Packit Service 724aca
	prof_bt_t	*bt;
Packit Service 724aca
	unsigned	max;
Packit Service 724aca
} prof_unwind_data_t;
Packit Service 724aca
#endif
Packit Service 724aca
Packit Service 724aca
struct prof_accum_s {
Packit Service 724aca
#ifndef JEMALLOC_ATOMIC_U64
Packit Service 724aca
	malloc_mutex_t	mtx;
Packit Service 724aca
	uint64_t	accumbytes;
Packit Service 724aca
#else
Packit Service 724aca
	atomic_u64_t	accumbytes;
Packit Service 724aca
#endif
Packit Service 724aca
};
Packit Service 724aca
Packit Service 724aca
struct prof_cnt_s {
Packit Service 724aca
	/* Profiling counters. */
Packit Service 724aca
	uint64_t	curobjs;
Packit Service 724aca
	uint64_t	curbytes;
Packit Service 724aca
	uint64_t	accumobjs;
Packit Service 724aca
	uint64_t	accumbytes;
Packit Service 724aca
};
Packit Service 724aca
Packit Service 724aca
typedef enum {
Packit Service 724aca
	prof_tctx_state_initializing,
Packit Service 724aca
	prof_tctx_state_nominal,
Packit Service 724aca
	prof_tctx_state_dumping,
Packit Service 724aca
	prof_tctx_state_purgatory /* Dumper must finish destroying. */
Packit Service 724aca
} prof_tctx_state_t;
Packit Service 724aca
Packit Service 724aca
struct prof_tctx_s {
Packit Service 724aca
	/* Thread data for thread that performed the allocation. */
Packit Service 724aca
	prof_tdata_t		*tdata;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Copy of tdata->thr_{uid,discrim}, necessary because tdata may be
Packit Service 724aca
	 * defunct during teardown.
Packit Service 724aca
	 */
Packit Service 724aca
	uint64_t		thr_uid;
Packit Service 724aca
	uint64_t		thr_discrim;
Packit Service 724aca
Packit Service 724aca
	/* Profiling counters, protected by tdata->lock. */
Packit Service 724aca
	prof_cnt_t		cnts;
Packit Service 724aca
Packit Service 724aca
	/* Associated global context. */
Packit Service 724aca
	prof_gctx_t		*gctx;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * UID that distinguishes multiple tctx's created by the same thread,
Packit Service 724aca
	 * but coexisting in gctx->tctxs.  There are two ways that such
Packit Service 724aca
	 * coexistence can occur:
Packit Service 724aca
	 * - A dumper thread can cause a tctx to be retained in the purgatory
Packit Service 724aca
	 *   state.
Packit Service 724aca
	 * - Although a single "producer" thread must create all tctx's which
Packit Service 724aca
	 *   share the same thr_uid, multiple "consumers" can each concurrently
Packit Service 724aca
	 *   execute portions of prof_tctx_destroy().  prof_tctx_destroy() only
Packit Service 724aca
	 *   gets called once each time cnts.cur{objs,bytes} drop to 0, but this
Packit Service 724aca
	 *   threshold can be hit again before the first consumer finishes
Packit Service 724aca
	 *   executing prof_tctx_destroy().
Packit Service 724aca
	 */
Packit Service 724aca
	uint64_t		tctx_uid;
Packit Service 724aca
Packit Service 724aca
	/* Linkage into gctx's tctxs. */
Packit Service 724aca
	rb_node(prof_tctx_t)	tctx_link;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * True during prof_alloc_prep()..prof_malloc_sample_object(), prevents
Packit Service 724aca
	 * sample vs destroy race.
Packit Service 724aca
	 */
Packit Service 724aca
	bool			prepared;
Packit Service 724aca
Packit Service 724aca
	/* Current dump-related state, protected by gctx->lock. */
Packit Service 724aca
	prof_tctx_state_t	state;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Copy of cnts snapshotted during early dump phase, protected by
Packit Service 724aca
	 * dump_mtx.
Packit Service 724aca
	 */
Packit Service 724aca
	prof_cnt_t		dump_cnts;
Packit Service 724aca
};
Packit Service 724aca
typedef rb_tree(prof_tctx_t) prof_tctx_tree_t;
Packit Service 724aca
Packit Service 724aca
struct prof_gctx_s {
Packit Service 724aca
	/* Protects nlimbo, cnt_summed, and tctxs. */
Packit Service 724aca
	malloc_mutex_t		*lock;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Number of threads that currently cause this gctx to be in a state of
Packit Service 724aca
	 * limbo due to one of:
Packit Service 724aca
	 *   - Initializing this gctx.
Packit Service 724aca
	 *   - Initializing per thread counters associated with this gctx.
Packit Service 724aca
	 *   - Preparing to destroy this gctx.
Packit Service 724aca
	 *   - Dumping a heap profile that includes this gctx.
Packit Service 724aca
	 * nlimbo must be 1 (single destroyer) in order to safely destroy the
Packit Service 724aca
	 * gctx.
Packit Service 724aca
	 */
Packit Service 724aca
	unsigned		nlimbo;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Tree of profile counters, one for each thread that has allocated in
Packit Service 724aca
	 * this context.
Packit Service 724aca
	 */
Packit Service 724aca
	prof_tctx_tree_t	tctxs;
Packit Service 724aca
Packit Service 724aca
	/* Linkage for tree of contexts to be dumped. */
Packit Service 724aca
	rb_node(prof_gctx_t)	dump_link;
Packit Service 724aca
Packit Service 724aca
	/* Temporary storage for summation during dump. */
Packit Service 724aca
	prof_cnt_t		cnt_summed;
Packit Service 724aca
Packit Service 724aca
	/* Associated backtrace. */
Packit Service 724aca
	prof_bt_t		bt;
Packit Service 724aca
Packit Service 724aca
	/* Backtrace vector, variable size, referred to by bt. */
Packit Service 724aca
	void			*vec[1];
Packit Service 724aca
};
Packit Service 724aca
typedef rb_tree(prof_gctx_t) prof_gctx_tree_t;
Packit Service 724aca
Packit Service 724aca
struct prof_tdata_s {
Packit Service 724aca
	malloc_mutex_t		*lock;
Packit Service 724aca
Packit Service 724aca
	/* Monotonically increasing unique thread identifier. */
Packit Service 724aca
	uint64_t		thr_uid;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Monotonically increasing discriminator among tdata structures
Packit Service 724aca
	 * associated with the same thr_uid.
Packit Service 724aca
	 */
Packit Service 724aca
	uint64_t		thr_discrim;
Packit Service 724aca
Packit Service 724aca
	/* Included in heap profile dumps if non-NULL. */
Packit Service 724aca
	char			*thread_name;
Packit Service 724aca
Packit Service 724aca
	bool			attached;
Packit Service 724aca
	bool			expired;
Packit Service 724aca
Packit Service 724aca
	rb_node(prof_tdata_t)	tdata_link;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Counter used to initialize prof_tctx_t's tctx_uid.  No locking is
Packit Service 724aca
	 * necessary when incrementing this field, because only one thread ever
Packit Service 724aca
	 * does so.
Packit Service 724aca
	 */
Packit Service 724aca
	uint64_t		tctx_uid_next;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Hash of (prof_bt_t *)-->(prof_tctx_t *).  Each thread tracks
Packit Service 724aca
	 * backtraces for which it has non-zero allocation/deallocation counters
Packit Service 724aca
	 * associated with thread-specific prof_tctx_t objects.  Other threads
Packit Service 724aca
	 * may write to prof_tctx_t contents when freeing associated objects.
Packit Service 724aca
	 */
Packit Service 724aca
	ckh_t			bt2tctx;
Packit Service 724aca
Packit Service 724aca
	/* Sampling state. */
Packit Service 724aca
	uint64_t		prng_state;
Packit Service 724aca
Packit Service 724aca
	/* State used to avoid dumping while operating on prof internals. */
Packit Service 724aca
	bool			enq;
Packit Service 724aca
	bool			enq_idump;
Packit Service 724aca
	bool			enq_gdump;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Set to true during an early dump phase for tdata's which are
Packit Service 724aca
	 * currently being dumped.  New threads' tdata's have this initialized
Packit Service 724aca
	 * to false so that they aren't accidentally included in later dump
Packit Service 724aca
	 * phases.
Packit Service 724aca
	 */
Packit Service 724aca
	bool			dumping;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * True if profiling is active for this tdata's thread
Packit Service 724aca
	 * (thread.prof.active mallctl).
Packit Service 724aca
	 */
Packit Service 724aca
	bool			active;
Packit Service 724aca
Packit Service 724aca
	/* Temporary storage for summation during dump. */
Packit Service 724aca
	prof_cnt_t		cnt_summed;
Packit Service 724aca
Packit Service 724aca
	/* Backtrace vector, used for calls to prof_backtrace(). */
Packit Service 724aca
	void			*vec[PROF_BT_MAX];
Packit Service 724aca
};
Packit Service 724aca
typedef rb_tree(prof_tdata_t) prof_tdata_tree_t;
Packit Service 724aca
Packit Service 724aca
#endif /* JEMALLOC_INTERNAL_PROF_STRUCTS_H */