-/** \brief Sanity-check the forward and reverse LRU lists
- */
-static inline void
-lru_validate (hss_main_t *hsm)
-{
-#if CLIB_DEBUG > 0
- f64 last_timestamp;
- u32 index;
- int i;
- hss_cache_entry_t *ep;
-
- last_timestamp = 1e70;
- for (i = 1, index = hsm->first_index; index != ~0;)
- {
- ep = pool_elt_at_index (hsm->cache_pool, index);
- index = ep->next_index;
- /* Timestamps should be smaller (older) as we walk the fwd list */
- if (ep->last_used > last_timestamp)
- {
- clib_warning ("%d[%d]: last used %.6f, last_timestamp %.6f",
- ep - hsm->cache_pool, i,
- ep->last_used, last_timestamp);
- }
- last_timestamp = ep->last_used;
- i++;
- }
-
- last_timestamp = 0.0;
- for (i = 1, index = hsm->last_index; index != ~0;)
- {
- ep = pool_elt_at_index (hsm->cache_pool, index);
- index = ep->prev_index;
- /* Timestamps should be larger (newer) as we walk the rev list */
- if (ep->last_used < last_timestamp)
- {
- clib_warning ("%d[%d]: last used %.6f, last_timestamp %.6f",
- ep - hsm->cache_pool, i,
- ep->last_used, last_timestamp);
- }
- last_timestamp = ep->last_used;
- i++;
- }
-#endif
-}
-
-/** \brief Remove a data cache entry from the LRU lists
- */
-static inline void
-lru_remove (hss_main_t *hsm, hss_cache_entry_t *ep)
-{
- hss_cache_entry_t *next_ep, *prev_ep;
- u32 ep_index;
-
- lru_validate (hsm);
-
- ep_index = ep - hsm->cache_pool;
-
- /* Deal with list heads */
- if (ep_index == hsm->first_index)
- hsm->first_index = ep->next_index;
- if (ep_index == hsm->last_index)
- hsm->last_index = ep->prev_index;
-
- /* Fix next->prev */
- if (ep->next_index != ~0)
- {
- next_ep = pool_elt_at_index (hsm->cache_pool, ep->next_index);
- next_ep->prev_index = ep->prev_index;
- }
- /* Fix prev->next */
- if (ep->prev_index != ~0)
- {
- prev_ep = pool_elt_at_index (hsm->cache_pool, ep->prev_index);
- prev_ep->next_index = ep->next_index;
- }
- lru_validate (hsm);
-}
-
-/** \brief Add an entry to the LRU lists, tag w/ supplied timestamp
- */
-static inline void
-lru_add (hss_main_t *hsm, hss_cache_entry_t *ep, f64 now)
-{
- hss_cache_entry_t *next_ep;
- u32 ep_index;
-
- lru_validate (hsm);
-
- ep_index = ep - hsm->cache_pool;
-
- /*
- * Re-add at the head of the forward LRU list,
- * tail of the reverse LRU list
- */
- if (hsm->first_index != ~0)
- {
- next_ep = pool_elt_at_index (hsm->cache_pool, hsm->first_index);
- next_ep->prev_index = ep_index;
- }
-
- ep->prev_index = ~0;
-
- /* ep now the new head of the LRU forward list */
- ep->next_index = hsm->first_index;
- hsm->first_index = ep_index;
-
- /* single session case: also the tail of the reverse LRU list */
- if (hsm->last_index == ~0)
- hsm->last_index = ep_index;
- ep->last_used = now;
-
- lru_validate (hsm);
-}
-
-/** \brief Remove and re-add a cache entry from/to the LRU lists
- */
-static inline void
-lru_update (hss_main_t *hsm, hss_cache_entry_t *ep, f64 now)
-{
- lru_remove (hsm, ep);
- lru_add (hsm, ep, now);
-}
-