qualcomm/qbox
Loading...
Searching...
No Matches
gs::RegionLRUCache< Key, Value > Class Template Reference

RegionLRUCache - A true LRU cache for region-based address lookups. More...

#include <addrmap_cache_examples.h>

Inheritance diagram for gs::RegionLRUCache< Key, Value >:
Collaboration diagram for gs::RegionLRUCache< Key, Value >:

Public Member Functions

bool get (const Key &key, Value &value) override
 Retrieve value from cache and update LRU order.
void put (const Key &key, const Value &value, uint64_t size) override
 Insert or update region in cache with LRU eviction.
void clear () override
 Clear all cached entries.
uint64_t get_hits () const override
uint64_t get_misses () const override
void reset_stats () override

Detailed Description

template<typename Key, typename Value>
class gs::RegionLRUCache< Key, Value >

RegionLRUCache - A true LRU cache for region-based address lookups.

This cache implements proper Least Recently Used (LRU) eviction policy using a std::list-based approach. When a region is accessed, it's moved to the back of the list (most recently used position). When eviction is needed, the front entry (least recently used) is removed.

Key features:

  • True LRU eviction based on access patterns (not insertion time)
  • List-based storage enabling O(1) splice for LRU
  • Moves accessed entries to back (most recently used)
  • Evicts from front (least recently used)
  • O(n) traversal and O(1) move via splice (acceptable for small cache sizes)
  • Instance-level storage (each router has its own cache)

Use this cache when workloads exhibit temporal locality in region access patterns.

Note: SystemC uses cooperative multitasking (single OS thread), so thread-local storage is not needed. Each router instance maintains its own cache.

Member Function Documentation

◆ clear()

template<typename Key, typename Value>
void gs::RegionLRUCache< Key, Value >::clear ( )
inlineoverridevirtual

Clear all cached entries.

Implements gs::AddrMapCacheBase< Key, Value >.

◆ get()

template<typename Key, typename Value>
bool gs::RegionLRUCache< Key, Value >::get ( const Key & key,
Value & value )
inlineoverridevirtual

Retrieve value from cache and update LRU order.

Searches through the vector from back to front (most recently used first) for better cache hit performance. If found, moves the entry to the back (most recently used) and returns true.

Parameters
keyAddress to look up
valueOutput parameter for the cached target info
Returns
true if found in cache, false otherwise

Implements gs::AddrMapCacheBase< Key, Value >.

◆ get_hits()

template<typename Key, typename Value>
uint64_t gs::RegionLRUCache< Key, Value >::get_hits ( ) const
inlineoverridevirtual

◆ get_misses()

template<typename Key, typename Value>
uint64_t gs::RegionLRUCache< Key, Value >::get_misses ( ) const
inlineoverridevirtual

◆ put()

template<typename Key, typename Value>
void gs::RegionLRUCache< Key, Value >::put ( const Key & key,
const Value & value,
uint64_t size )
inlineoverridevirtual

Insert or update region in cache with LRU eviction.

If a region with the same start address already exists, updates it and moves to back. If new and at capacity, evicts the least recently used entry (front of vector) before inserting at back.

Parameters
keyRegion start address
valueTarget info to cache
sizeRegion size

Implements gs::AddrMapCacheBase< Key, Value >.

◆ reset_stats()

template<typename Key, typename Value>
void gs::RegionLRUCache< Key, Value >::reset_stats ( )
inlineoverridevirtual

The documentation for this class was generated from the following file: