aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2020-03-08 08:27:19 -0400
committerJohn Lo <loj@cisco.com>2020-03-09 20:55:37 +0000
commit3d9f134e77864024d67f27e85d85e2ad12a13dc6 (patch)
tree384623f01c7afcc2183345b555cc691eef3708cf
parent8e7fdddd34ef3c5f93f4ccba9660fa3d63994522 (diff)
vppinfra: fix corner cases in tw_timer_expire
Type: fix Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I4b3ff6e9c8e1d76037b168aeab36dcb5b4482260
-rw-r--r--src/vppinfra/tw_timer_template.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/vppinfra/tw_timer_template.c b/src/vppinfra/tw_timer_template.c
index af2b75a0f57..6b005fd2ff3 100644
--- a/src/vppinfra/tw_timer_template.c
+++ b/src/vppinfra/tw_timer_template.c
@@ -513,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;
@@ -525,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;