aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/tw_timer_template.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-06-22 15:29:38 -0700
committerDave Barach <openvpp@barachs.net>2018-06-25 20:43:44 +0000
commitadb5bd5344cd7b422c0c08e6434ad8642b897502 (patch)
tree93f2ed26f808ff73882436ea4702eb0eedc2f765 /src/vppinfra/tw_timer_template.c
parentc474feea962bcde3b5eece0ff2be8d3fd8019093 (diff)
tw: add light weight timer update function
Because it avoids pool putting/getting the timer, this function is somewhat faster than stopping and restarting a timer. Change-Id: Id99ed9d356b0b1f7e12facfe8da193e1cd30b3ec Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vppinfra/tw_timer_template.c')
-rw-r--r--src/vppinfra/tw_timer_template.c79
1 files changed, 50 insertions, 29 deletions
diff --git a/src/vppinfra/tw_timer_template.c b/src/vppinfra/tw_timer_template.c
index a6d26d7991d..da40e2c0b3e 100644
--- a/src/vppinfra/tw_timer_template.c
+++ b/src/vppinfra/tw_timer_template.c
@@ -142,9 +142,8 @@ timer_addhead (TWT (tw_timer) * pool, u32 head_index, u32 new_index)
}
static inline void
-timer_remove (TWT (tw_timer) * pool, u32 index)
+timer_remove (TWT (tw_timer) * pool, TWT (tw_timer) * elt)
{
- TWT (tw_timer) * elt = pool_elt_at_index (pool, index);
TWT (tw_timer) * next_elt, *prev_elt;
ASSERT (elt->user_handle != ~0);
@@ -158,17 +157,8 @@ timer_remove (TWT (tw_timer) * pool, u32 index)
elt->prev = elt->next = ~0;
}
-/**
- * @brief Start a Tw Timer
- * @param tw_timer_wheel_t * tw timer wheel object pointer
- * @param u32 pool_index user pool index, presumably for a tw session
- * @param u32 timer_id app-specific timer ID. 4 bits.
- * @param u64 interval timer interval in ticks
- * @returns handle needed to cancel the timer
- */
-u32
-TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
- u64 interval)
+static void
+timer_add (TWT (tw_timer_wheel) * tw, TWT (tw_timer) * t, u64 interval)
{
#if TW_TIMER_WHEELS > 1
u16 slow_ring_offset;
@@ -182,14 +172,6 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
#endif
u16 fast_ring_offset;
tw_timer_wheel_slot_t *ts;
- TWT (tw_timer) * t;
-
- ASSERT (interval);
-
- pool_get (tw->timers, t);
- memset (t, 0xff, sizeof (*t));
-
- t->user_handle = TW (make_internal_timer_handle) (pool_index, timer_id);
/* Factor interval into 1..3 wheel offsets */
#if TW_TIMER_WHEELS > 2
@@ -209,9 +191,9 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
ts = &tw->overflow;
timer_addhead (tw->timers, ts->head_index, t - tw->timers);
#if TW_START_STOP_TRACE_SIZE > 0
- TW (tw_timer_trace) (tw, timer_id, pool_index, t - tw->timers);
+ TW (tw_timer_trace) (tw, timer_id, user_id, t - tw->timers);
#endif
- return t - tw->timers;
+ return;
}
#endif
@@ -262,9 +244,9 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
timer_addhead (tw->timers, ts->head_index, t - tw->timers);
#if TW_START_STOP_TRACE_SIZE > 0
- TW (tw_timer_trace) (tw, timer_id, pool_index, t - tw->timers);
+ TW (tw_timer_trace) (tw, timer_id, user_id, t - tw->timers);
#endif
- return t - tw->timers;
+ return;
}
#endif
@@ -280,9 +262,9 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
timer_addhead (tw->timers, ts->head_index, t - tw->timers);
#if TW_START_STOP_TRACE_SIZE > 0
- TW (tw_timer_trace) (tw, timer_id, pool_index, t - tw->timers);
+ TW (tw_timer_trace) (tw, timer_id, user_id, t - tw->timers);
#endif
- return t - tw->timers;
+ return;
}
#else
fast_ring_offset %= TW_SLOTS_PER_RING;
@@ -298,8 +280,32 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 pool_index, u32 timer_id,
fast_ring_offset, 1);
#endif
#if TW_START_STOP_TRACE_SIZE > 0
- TW (tw_timer_trace) (tw, timer_id, pool_index, t - tw->timers);
+ TW (tw_timer_trace) (tw, timer_id, user_id, t - tw->timers);
#endif
+}
+
+/**
+ * @brief Start a Tw Timer
+ * @param tw_timer_wheel_t * tw timer wheel object pointer
+ * @param u32 user_id user defined timer id, presumably for a tw session
+ * @param u32 timer_id app-specific timer ID. 4 bits.
+ * @param u64 interval timer interval in ticks
+ * @returns handle needed to cancel the timer
+ */
+u32
+TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 user_id, u32 timer_id,
+ u64 interval)
+{
+ TWT (tw_timer) * t;
+
+ ASSERT (interval);
+
+ pool_get (tw->timers, t);
+ memset (t, 0xff, sizeof (*t));
+
+ t->user_handle = TW (make_internal_timer_handle) (user_id, timer_id);
+
+ timer_add (tw, t, interval);
return t - tw->timers;
}
@@ -365,12 +371,27 @@ void TW (tw_timer_stop) (TWT (tw_timer_wheel) * tw, u32 handle)
/* in case of idiotic handle (e.g. passing a listhead index) */
ASSERT (t->user_handle != ~0);
- timer_remove (tw->timers, handle);
+ timer_remove (tw->timers, t);
pool_put_index (tw->timers, handle);
}
/**
+ * @brief Update a tw timer
+ * @param tw_timer_wheel_t * tw timer wheel object pointer
+ * @param u32 handle timer returned by tw_timer_start
+ * @param u32 interval timer interval in ticks
+ */
+void TW (tw_timer_update) (TWT (tw_timer_wheel) * tw, u32 handle,
+ u64 interval)
+{
+ TWT (tw_timer) * t;
+ t = pool_elt_at_index (tw->timers, handle);
+ timer_remove (tw->timers, t);
+ timer_add (tw, t, interval);
+}
+
+/**
* @brief Initialize a tw timer wheel template instance
* @param tw_timer_wheel_t * tw timer wheel object pointer
* @param void * expired_timer_callback. Passed a u32 * vector of