Additionally to Dave's answer, you also have to be very careful with the expected precision of the timers.
When you're inserting a timer with a interval on N into a timer with a period of P, you timeout is not guaranteed to be N * P, it is more something like (N-1)*P < timeout < N*P. The reason for that is that the wheel works on a an internal tick and that tick does no necessarily equal NOW. You might be near the end of current tick when inserting and that will lead to a shorter that expected timeout. For timers where the timeout is magnitudes larger then the interval, that does not matter. But when you have to compare the expected time of the timeout to NOW you might get into trouble. Especially since NOW is a float, calculating NOW+(N*period) will not result in the same value as adding period N times to NOW (NOW+period+period+period....+period) in a loop. Rounding differences lead to a shift that can break a simple earlier/later comparison on those results. Regards Andreas Am Mi., 12. Juni 2019 um 13:22 Uhr schrieb Dave Barach via Lists.Fd.Io <dbarach=cisco....@lists.fd.io>: > > You didn't mention calling tw_timer_expire_timers_xxx(tw, now), which is the > only force of physics which will actually cause a timer to expire. > > See also .../src/vppinfra/test_tw_timer.c, src/vlib/main.c or > src/vnet/tcp/tcp.c for usage examples. The timer wheel code has been tested > to N=60 million concurrent timers. It's not trivially broken. > > D > > ________________________________ > From: vpp-dev@lists.fd.io <vpp-dev@lists.fd.io> on behalf of hari_akkin via > Lists.Fd.Io <hari_akkin=yahoo....@lists.fd.io> > Sent: Wednesday, June 12, 2019 7:00 AM > To: vpp-dev@lists.fd.io > Cc: vpp-dev@lists.fd.io > Subject: [vpp-dev] timer wheel usage queries > > Hello > I am trying to use timer_wheel framework to start a timer. I followed the > examples given in fdio, but the expiry_callback function never being called > back. > I am not sure if timer failed to expire or my usage has problems. I used the > below functions: > > Timer wheel Init: > { > tw_timer_wheel_1t_1w_2048sl_t* tw = &example_main->timer_wheels; > tw_timer_wheel_init_1t_1w_2048sl (tw, example_timer_expired_callback, > 1.0 /* timer period 1s */ , 1024); > tw->last_run_time = vlib_time_now (vm); > } > > Timer Start: > handle = tw_timer_start_1t_1w_2048sl(&example->timer_wheels,1,0,5); > > The expiry functiion example_timer_expired_callback never been called. > > Is there any issue in the way I am using or is there any knwon issue in TW > framework? > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > > View/Reply Online (#13262): https://lists.fd.io/g/vpp-dev/message/13262 > Mute This Topic: https://lists.fd.io/mt/32039603/675601 > Group Owner: vpp-dev+ow...@lists.fd.io > Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub > [andreas.schu...@travelping.com] > -=-=-=-=-=-=-=-=-=-=-=- -- -- Dipl.-Inform. Andreas Schultz ----------------------- enabling your networks ---------------------- Travelping GmbH Phone: +49-391-81 90 99 0 Roentgenstr. 13 Fax: +49-391-81 90 99 299 39108 Magdeburg Email: i...@travelping.com GERMANY Web: http://www.travelping.com Company Registration: Amtsgericht Stendal Reg No.: HRB 10578 Geschaeftsfuehrer: Holger Winkelmann VAT ID No.: DE236673780 ---------------------------------------------------------------------
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#13266): https://lists.fd.io/g/vpp-dev/message/13266 Mute This Topic: https://lists.fd.io/mt/32039603/21656 Group Owner: vpp-dev+ow...@lists.fd.io Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-