From 217c62a53e5621bb8790a242a57dc7e9f8eef3a8 Mon Sep 17 00:00:00 2001 From: Andreas Schultz Date: Tue, 25 Jun 2019 15:29:06 +0200 Subject: vppinfra: fix tw_timer_first_expires_in_ticks for multiple wheels When only the fast in wheel is in use, the next expiring has to be within the fast_slot_bitmap. With mutliple wheels, the next expiring timer could be in the slow wheel. The timers on the slow wheel are only moved into the fast wheel when the fast wheel index reaches TW_SLOTS_PER_RING. When calculating the next expiring timer we therefor need to consider the timers on the slow wheel as well. When there are no more before reaching TW_SLOTS_PER_RING, instead of scanning the slow wheel, return the number of ticks until TW_SLOTS_PER_RING is reached. Type: fix Change-Id: I847031f8efc015c888d082f0b0c1bd500aa65704 Signed-off-by: Andreas Schultz Signed-off-by: Dave Barach --- src/vppinfra/tw_timer_template.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/vppinfra/tw_timer_template.c b/src/vppinfra/tw_timer_template.c index 11a38890f9c..9ad74624521 100644 --- a/src/vppinfra/tw_timer_template.c +++ b/src/vppinfra/tw_timer_template.c @@ -827,6 +827,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 +850,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); -- cgit 1.2.3-korg