}
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;
}
}
-#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;
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;
/* 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;
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;
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);