From abd467493110efbcf92f0e85a699f9cda47daff7 Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Thu, 16 Apr 2020 13:33:56 -0700 Subject: [PATCH] Extract out per event postponed wait time fetching --- include/jemalloc/internal/prof_externs.h | 2 ++ include/jemalloc/internal/stats.h | 1 + include/jemalloc/internal/tcache_externs.h | 2 ++ src/prof.c | 5 +++++ src/stats.c | 5 +++++ src/tcache.c | 10 ++++++++++ src/thread_event.c | 17 ++++++++++++----- 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/jemalloc/internal/prof_externs.h b/include/jemalloc/internal/prof_externs.h index 2284ae65..d500f560 100644 --- a/include/jemalloc/internal/prof_externs.h +++ b/include/jemalloc/internal/prof_externs.h @@ -98,8 +98,10 @@ void prof_prefork0(tsdn_t *tsdn); void prof_prefork1(tsdn_t *tsdn); void prof_postfork_parent(tsdn_t *tsdn); void prof_postfork_child(tsdn_t *tsdn); + /* Only accessed by thread event. */ uint64_t prof_sample_new_event_wait(tsd_t *tsd); +uint64_t prof_sample_postponed_event_wait(tsd_t *tsd); bool prof_idump_accum(tsdn_t *tsdn, uint64_t accumbytes); bool prof_log_start(tsdn_t *tsdn, const char *filename); diff --git a/include/jemalloc/internal/stats.h b/include/jemalloc/internal/stats.h index 42c321e5..4989fe1a 100644 --- a/include/jemalloc/internal/stats.h +++ b/include/jemalloc/internal/stats.h @@ -39,6 +39,7 @@ extern char opt_stats_interval_opts[stats_print_tot_num_options+1]; /* Only accessed by thread event. */ uint64_t stats_interval_new_event_wait(tsd_t *tsd); +uint64_t stats_interval_postponed_event_wait(tsd_t *tsd); bool stats_interval_accum(tsd_t *tsd, uint64_t bytes); /* Implements je_malloc_stats_print. */ diff --git a/include/jemalloc/internal/tcache_externs.h b/include/jemalloc/internal/tcache_externs.h index 7fd730d6..3be65286 100644 --- a/include/jemalloc/internal/tcache_externs.h +++ b/include/jemalloc/internal/tcache_externs.h @@ -55,7 +55,9 @@ void tcache_assert_initialized(tcache_t *tcache); /* Only accessed by thread event. */ uint64_t tcache_gc_new_event_wait(tsd_t *tsd); +uint64_t tcache_gc_postponed_event_wait(tsd_t *tsd); uint64_t tcache_gc_dalloc_new_event_wait(tsd_t *tsd); +uint64_t tcache_gc_dalloc_postponed_event_wait(tsd_t *tsd); void tcache_event_hard(tsd_t *tsd, tcache_slow_t *tcache_slow, tcache_t *tcache); diff --git a/src/prof.c b/src/prof.c index 94055855..ad83cfe5 100644 --- a/src/prof.c +++ b/src/prof.c @@ -561,6 +561,11 @@ prof_sample_new_event_wait(tsd_t *tsd) { #endif } +uint64_t +prof_sample_postponed_event_wait(tsd_t *tsd) { + return TE_MIN_START_WAIT; +} + int prof_getpid(void) { #ifdef _WIN32 diff --git a/src/stats.c b/src/stats.c index 9d13f596..16d4e88e 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1503,6 +1503,11 @@ stats_interval_new_event_wait(tsd_t *tsd) { return stats_interval_accum_batch; } +uint64_t +stats_interval_postponed_event_wait(tsd_t *tsd) { + return TE_MIN_START_WAIT; +} + bool stats_boot(void) { uint64_t stats_interval; diff --git a/src/tcache.c b/src/tcache.c index cba2ea72..16c87cb0 100644 --- a/src/tcache.c +++ b/src/tcache.c @@ -45,11 +45,21 @@ tcache_gc_new_event_wait(tsd_t *tsd) { return TCACHE_GC_INCR_BYTES; } +uint64_t +tcache_gc_postponed_event_wait(tsd_t *tsd) { + return TE_MIN_START_WAIT; +} + uint64_t tcache_gc_dalloc_new_event_wait(tsd_t *tsd) { return TCACHE_GC_INCR_BYTES; } +uint64_t +tcache_gc_dalloc_postponed_event_wait(tsd_t *tsd) { + return TE_MIN_START_WAIT; +} + void tcache_event_hard(tsd_t *tsd, tcache_slow_t *tcache_slow, tcache_t *tcache) { szind_t binind = tcache_slow->next_gc_bin; diff --git a/src/thread_event.c b/src/thread_event.c index 0d71f32d..9de8376d 100644 --- a/src/thread_event.c +++ b/src/thread_event.c @@ -5,12 +5,19 @@ #include "jemalloc/internal/thread_event.h" /* - * Signatures for functions computing new event wait time. The functions - * should be defined by the modules owning each event. The signatures here are - * used to verify that the definitions are in the right shape. + * Signatures for functions computing new / postponed event wait time. New + * event wait time is the time till the next event if an event is currently + * being triggered; postponed event wait time is the time till the next event + * if an event should be triggered but needs to be postponed, e.g. when the TSD + * is not nominal or during reentrancy. + * + * These event wait time computation functions should be defined by the modules + * owning each event. The signatures here are used to verify that the + * definitions follow the right format. */ #define E(event, condition_unused, is_alloc_event_unused) \ -uint64_t event##_new_event_wait(tsd_t *tsd); +uint64_t event##_new_event_wait(tsd_t *tsd); \ +uint64_t event##_postponed_event_wait(tsd_t *tsd); ITERATE_OVER_ALL_EVENTS #undef E @@ -256,7 +263,7 @@ te_event_trigger(tsd_t *tsd, te_ctx_t *ctx) { if (event_wait > accumbytes) { \ event_wait -= accumbytes; \ } else if (!allow_event_trigger) { \ - event_wait = TE_MIN_START_WAIT; \ + event_wait = event##_postponed_event_wait(tsd); \ } else { \ is_##event##_triggered = true; \ event_wait = event##_new_event_wait(tsd); \