X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Ftw_timer_template.c;h=6b005fd2ff3281f69e9d169bcd55903e6ef2e56d;hb=3d9f134e77864024d67f27e85d85e2ad12a13dc6;hp=9c9bb977d5e48ec37d59e40f5d43ad53eaea45cb;hpb=40f92469c6c1b7145ad752475350f71d752d8033;p=vpp.git diff --git a/src/vppinfra/tw_timer_template.c b/src/vppinfra/tw_timer_template.c index 9c9bb977d5e..6b005fd2ff3 100644 --- a/src/vppinfra/tw_timer_template.c +++ b/src/vppinfra/tw_timer_template.c @@ -301,7 +301,7 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 user_id, u32 timer_id, ASSERT (interval); pool_get (tw->timers, t); - memset (t, 0xff, sizeof (*t)); + clib_memset (t, 0xff, sizeof (*t)); t->user_handle = TW (make_internal_timer_handle) (user_id, timer_id); @@ -411,7 +411,7 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw, int ring, slot; tw_timer_wheel_slot_t *ts; TWT (tw_timer) * t; - memset (tw, 0, sizeof (*tw)); + clib_memset (tw, 0, sizeof (*tw)); tw->expired_timer_callback = expired_timer_callback; tw->max_expirations = max_expirations; if (timer_interval_in_seconds == 0.0) @@ -421,7 +421,6 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw, } tw->timer_interval = timer_interval_in_seconds; tw->ticks_per_second = 1.0 / timer_interval_in_seconds; - tw->first_expires_tick = ~0ULL; vec_validate (tw->expired_timer_handles, 0); _vec_len (tw->expired_timer_handles) = 0; @@ -432,7 +431,7 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw, { ts = &tw->w[ring][slot]; pool_get (tw->timers, t); - memset (t, 0xff, sizeof (*t)); + clib_memset (t, 0xff, sizeof (*t)); t->next = t->prev = t - tw->timers; ts->head_index = t - tw->timers; } @@ -441,7 +440,7 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw, #if TW_OVERFLOW_VECTOR > 0 ts = &tw->overflow; pool_get (tw->timers, t); - memset (t, 0xff, sizeof (*t)); + clib_memset (t, 0xff, sizeof (*t)); t->next = t->prev = t - tw->timers; ts->head_index = t - tw->timers; #endif @@ -476,7 +475,7 @@ void TW (tw_timer_wheel_free) (TWT (tw_timer_wheel) * tw) } } -#if TW_OVERFLOW_VECVOR > 0 +#if TW_OVERFLOW_VECTOR > 0 ts = &tw->overflow; head = pool_elt_at_index (tw->timers, ts->head_index); next_index = head->next; @@ -490,7 +489,7 @@ void TW (tw_timer_wheel_free) (TWT (tw_timer_wheel) * tw) pool_put (tw->timers, head); #endif - memset (tw, 0, sizeof (*tw)); + clib_memset (tw, 0, sizeof (*tw)); } /** @@ -514,7 +513,7 @@ static inline u32 slow_wheel_index __attribute__ ((unused)); u32 glacier_wheel_index __attribute__ ((unused)); - /* Shouldn't happen */ + /* Called too soon to process new timer expirations? */ if (PREDICT_FALSE (now < tw->next_run_time)) return callback_vector_arg; @@ -526,6 +525,27 @@ static inline /* Remember when we ran, compute next runtime */ tw->next_run_time = (now + tw->timer_interval); + /* First call, or time jumped backwards? */ + if (PREDICT_FALSE + ((tw->last_run_time == 0.0) || (now <= tw->last_run_time))) + { + tw->last_run_time = now; + return callback_vector_arg; + } + + /* + * Refuse to do anything if we're about to process way too many slots. + * Should never come anywhere close to happening, with the possible exception + * of cases involving a large forward jump in the timebase. + */ + if (nticks > (1 << (TW_RING_SHIFT + 1))) + { + clib_warning ("Excessive nticks %u at %.6f last run %.6f", + nticks, now, tw->last_run_time); + tw->last_run_time = now; + return callback_vector_arg; + } + if (callback_vector_arg == 0) { _vec_len (tw->expired_timer_handles) = 0; @@ -827,6 +847,18 @@ u32 TW (tw_timer_first_expires_in_ticks) (TWT (tw_timer_wheel) * tw) u32 first_expiring_index, fast_ring_index; i32 delta; +#if TW_TIMER_WHEELS > 1 + fast_ring_index = tw->current_index[TW_TIMER_RING_FAST]; + if (fast_ring_index == TW_SLOTS_PER_RING) + return 1; + + first_expiring_index = clib_bitmap_next_set (tw->fast_slot_bitmap, + fast_ring_index); + if (first_expiring_index == ~0) + first_expiring_index = TW_SLOTS_PER_RING; + +#else + if (clib_bitmap_is_zero (tw->fast_slot_bitmap)) return TW_SLOTS_PER_RING; @@ -838,6 +870,7 @@ u32 TW (tw_timer_first_expires_in_ticks) (TWT (tw_timer_wheel) * tw) fast_ring_index); if (first_expiring_index == ~0 && fast_ring_index != 0) first_expiring_index = clib_bitmap_first_set (tw->fast_slot_bitmap); +#endif ASSERT (first_expiring_index != ~0);