tw_timer_expire_timers() return the number of expirations 25/5125/3
authorGabriel Ganne <gabriel.ganne@enea.com>
Mon, 13 Feb 2017 09:27:15 +0000 (10:27 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 16 Feb 2017 08:15:58 +0000 (08:15 +0000)
to be used for node statistics

Also fix tw_timer_stop() description

Change-Id: I84b529e330c4534fd55487e7e2b8b089ee68ca11
Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>
src/vppinfra/tw_timer_template.c
src/vppinfra/tw_timer_template.h

index 9aa5624..139d27c 100644 (file)
@@ -144,11 +144,8 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
 /**
  * @brief Stop a tw timer
  * @param tw_timer_wheel_t * tw timer wheel object pointer
- * @param u32 pool_index user pool index, passed for consistency checking only
- * @param u32 timer_id 4 bit timer ID, passed for consistency checking only
  * @param u32 handle timer cancellation returned by tw_timer_start
  */
-
 void TW (tw_timer_stop) (TWT (tw_timer_wheel) * tw, u32 handle)
 {
   TWT (tw_timer) * t;
@@ -238,30 +235,32 @@ void TW (tw_timer_wheel_free) (TWT (tw_timer_wheel) * tw)
  * @param tw_timer_wheel_t * tw timer wheel template instance pointer
  * @param f64 now the current time, e.g. from vlib_time_now(vm)
  */
-void TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now)
+u32 TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now)
 {
   u32 nticks, i;
   tw_timer_wheel_slot_t *ts;
   TWT (tw_timer) * t, *head;
   u32 fast_wheel_index;
   u32 next_index;
+  u32 nexpirations, total_nexpirations;
 #if TW_TIMER_WHEELS > 1
   u32 slow_wheel_index;
 #endif
 
   /* Shouldn't happen */
   if (PREDICT_FALSE (now < tw->next_run_time))
-    return;
+    return 0;
 
   /* Number of ticks which have occurred */
   nticks = tw->ticks_per_second * (now - tw->last_run_time);
   if (nticks == 0)
-    return;
+    return 0;
 
   /* Remember when we ran, compute next runtime */
   tw->next_run_time = (now + tw->timer_interval);
   tw->last_run_time = now;
 
+  total_nexpirations = 0;
   for (i = 0; i < nticks; i++)
     {
       fast_wheel_index = tw->current_index[TW_TIMER_RING_FAST];
@@ -325,11 +324,17 @@ void TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now)
        }
 
       /* If any timers expired, tell the user */
-      if (vec_len (tw->expired_timer_handles))
-       tw->expired_timer_callback (tw->expired_timer_handles);
+      nexpirations = vec_len (tw->expired_timer_handles);
+      if (nexpirations)
+       {
+         tw->expired_timer_callback (tw->expired_timer_handles);
+         total_nexpirations += nexpirations;
+       }
       tw->current_index[TW_TIMER_RING_FAST]++;
       tw->current_tick++;
     }
+
+  return total_nexpirations;
 }
 
 /*
index cf15ab8..2e41bca 100644 (file)
@@ -188,7 +188,7 @@ void TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw,
 
 void TW (tw_timer_wheel_free) (TWT (tw_timer_wheel) * tw);
 
-void TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now);
+u32 TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now);
 
 /*
  * fd.io coding-style-patch-verification: ON