Home | History | Annotate | Line # | Download | only in internal
      1  1.1  christos #ifndef JEMALLOC_INTERNAL_COUNTER_H
      2  1.1  christos #define JEMALLOC_INTERNAL_COUNTER_H
      3  1.1  christos 
      4  1.1  christos #include "jemalloc/internal/mutex.h"
      5  1.1  christos 
      6  1.1  christos typedef struct counter_accum_s {
      7  1.1  christos 	LOCKEDINT_MTX_DECLARE(mtx)
      8  1.1  christos 	locked_u64_t accumbytes;
      9  1.1  christos 	uint64_t interval;
     10  1.1  christos } counter_accum_t;
     11  1.1  christos 
     12  1.1  christos JEMALLOC_ALWAYS_INLINE bool
     13  1.1  christos counter_accum(tsdn_t *tsdn, counter_accum_t *counter, uint64_t bytes) {
     14  1.1  christos 	uint64_t interval = counter->interval;
     15  1.1  christos 	assert(interval > 0);
     16  1.1  christos 	LOCKEDINT_MTX_LOCK(tsdn, counter->mtx);
     17  1.1  christos 	/*
     18  1.1  christos 	 * If the event moves fast enough (and/or if the event handling is slow
     19  1.1  christos 	 * enough), extreme overflow can cause counter trigger coalescing.
     20  1.1  christos 	 * This is an intentional mechanism that avoids rate-limiting
     21  1.1  christos 	 * allocation.
     22  1.1  christos 	 */
     23  1.1  christos 	bool overflow = locked_inc_mod_u64(tsdn, LOCKEDINT_MTX(counter->mtx),
     24  1.1  christos 	    &counter->accumbytes, bytes, interval);
     25  1.1  christos 	LOCKEDINT_MTX_UNLOCK(tsdn, counter->mtx);
     26  1.1  christos 	return overflow;
     27  1.1  christos }
     28  1.1  christos 
     29  1.1  christos bool counter_accum_init(counter_accum_t *counter, uint64_t interval);
     30  1.1  christos void counter_prefork(tsdn_t *tsdn, counter_accum_t *counter);
     31  1.1  christos void counter_postfork_parent(tsdn_t *tsdn, counter_accum_t *counter);
     32  1.1  christos void counter_postfork_child(tsdn_t *tsdn, counter_accum_t *counter);
     33  1.1  christos 
     34  1.1  christos #endif /* JEMALLOC_INTERNAL_COUNTER_H */
     35