{
/* Poison free elements so we never use them by mistake. */
if (CLIB_DEBUG > 0)
- memset (ev, ~0, vec_len (ev) * sizeof (ev[0]));
+ clib_memset (ev, ~0, vec_len (ev) * sizeof (ev[0]));
_vec_len (ev) = 0;
vec_add1 (w->free_elt_vectors, ev);
}
e = insert_helper (w, level_index, rtime);
e->user_data = user_data;
e->cpu_time_relative_to_base = dt;
+ if (insert_cpu_time < w->cached_min_cpu_time_on_wheel)
+ w->cached_min_cpu_time_on_wheel = insert_cpu_time;
}
else
{
{
timing_wheel_overflow_elt_t *oe;
/* *INDENT-OFF* */
- pool_foreach (oe, w->overflow_pool, ({
+ pool_foreach (oe, w->overflow_pool) {
if (oe->user_data == user_data)
pool_put (w->overflow_pool, oe);
- }));
+ }
/* *INDENT-ON* */
}
min_t = w->cpu_time_base + min_dt;
/* *INDENT-OFF* */
- pool_foreach (oe, w->overflow_pool,
- ({ min_t = clib_min (min_t, oe->cpu_time); }));
+ pool_foreach (oe, w->overflow_pool)
+ { min_t = clib_min (min_t, oe->cpu_time); }
/* *INDENT-ON* */
done:
vec_foreach (e, l->elts[wi])
{
/* This should always be true since otherwise we would have already expired
- this element. */
+ this element. Note that in the second half of this function we need
+ to take care not to place the expired elements ourselves. */
ASSERT (e->cpu_time_relative_to_base >= delta);
e->cpu_time_relative_to_base -= delta;
}
{
timing_wheel_overflow_elt_t *oe;
/* *INDENT-OFF* */
- pool_foreach (oe, w->overflow_pool, ({
+ pool_foreach (oe, w->overflow_pool) {
/* It fits now into 32 bits. */
if (0 == ((oe->cpu_time - w->cpu_time_base) >> BITS (e->cpu_time_relative_to_base)))
{
u64 ti = oe->cpu_time >> w->log2_clocks_per_bin;
- if (ti < w->current_time_index)
+ if (ti <= w->current_time_index)
{
/* This can happen when timing wheel is not advanced for a long time
(for example when at a gdb breakpoint for a while). */
+ /* Note: the ti == w->current_time_index means it is also an expired timer */
if (! elt_is_deleted (w, oe->user_data))
vec_add1 (expired_user_data, oe->user_data);
}
timing_wheel_insert_helper (w, oe->cpu_time, oe->user_data);
pool_put (w->overflow_pool, oe);
}
- }));
+ }
/* *INDENT-ON* */
}
return expired_user_data;
expire_bin (w, advance_level_index, wi, advance_cpu_time,
expired_user_data);
+ /* When we jump out, we have already just expired the bin,
+ corresponding to advance_wheel_index */
if (wi == advance_wheel_index)
break;
}
/* Don't advance until necessary. */
+ /* However, if the timing_wheel_advance() hasn't been called for some time,
+ the while() loop will ensure multiple calls to advance_cpu_time_base()
+ in a row until the w->cpu_time_base is fresh enough. */
while (PREDICT_FALSE
(advance_time_index >= w->time_index_next_cpu_time_base_update))
expired_user_data = advance_cpu_time_base (w, expired_user_data);
{
timing_wheel_t *w = va_arg (*va, timing_wheel_t *);
int verbose = va_arg (*va, int);
- uword indent = format_get_indent (s);
+ u32 indent = format_get_indent (s);
s = format (s, "level 0: %.4e - %.4e secs, 2^%d - 2^%d clocks",
(f64) (1 << w->log2_clocks_per_bin) / w->cpu_clocks_per_second,