The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::memory::CachedMemory< MemoryWriteType > Class Template Reference

Memory that can be used as a cache for core models. More...

#include <CachedMemory.hpp>

Inheritance diagram for sparta::memory::CachedMemory< MemoryWriteType >:
Collaboration diagram for sparta::memory::CachedMemory< MemoryWriteType >:

Public Member Functions

 CachedMemory (const std::string &name, uint64_t write_id, uint32_t outstanding_writes_watermark, addr_t block_size, addr_t total_size, sparta::memory::BlockingMemoryIF *downstream_memory)
 Create a CachedMemory object.
 
uint64_t getWriteID () const
 Get the write ID for this cache.
 
const std::map< uint64_t, MemoryWriteType > & getOutstandingWrites () const
 Get all outstanding writes.
 
std::vector< MemoryWriteType > getOutstandingWritesForAddr (addr_t paddr) const
 Given address, find outstanding writes that are not merged/committed.
 
uint32_t getNumOutstandingWrites () const
 Return the number of uncomitted writes.
 
void commitWrite (const MemoryWriteType &write_to_commit)
 Commit the write that matches the given MemoryWriteType.
 
void mergeWrite (addr_t paddr, addr_t size, const uint8_t *buf)
 Merge an incoming write from system memory.
 
void dropWrite (const MemoryWriteType &write_to_drop)
 Drop the outstanding write that matches the given MemoryWriteType.
 
const MemoryWriteType & getLastOutstandingWrite () const
 Return the latest outstanding store access.
 
- Public Member Functions inherited from sparta::memory::BlockingMemoryIF
std::string stringize (bool pretty=false) const
 Render description of this BlockingMemoryIF as a string.
 
 BlockingMemoryIF (const std::string &desc, addr_t block_size, const DebugMemoryIF::AccessWindow &window, TranslationIF *transif=nullptr)
 Construct a blocking memory interface.
 
virtual bool tryRead (addr_t addr, addr_t size, uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
 Attempt to read memory of size size at address addr.
 
void read (addr_t addr, addr_t size, uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
 Attempts to read memory.
 
virtual bool tryWrite (addr_t addr, addr_t size, const uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
 Attempt to write memory of size size at address addr.
 
void write (addr_t addr, addr_t size, const uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
 Attempts to write memory.
 
virtual DMIBlockingMemoryIFgetDMI (addr_t addr, addr_t size)
 Get a DMI blocking interface to access the given address/size.
 
virtual void invalidateAllDMI ()
 Invalidate all DMI's.
 
- Public Member Functions inherited from sparta::memory::DebugMemoryIF
 DebugMemoryIF ()=delete
 Default constuctor.
 
 DebugMemoryIF (const std::string &desc, addr_t block_size, const AccessWindow &window, TranslationIF *transif=nullptr)
 Construct a DebugMemoryInterface.
 
virtual ~DebugMemoryIF ()
 Virutal destructor.
 
virtual const TranslationIFgetTranslationIF ()
 Gets the translation interface associated with this Debug memory interface (if any).
 
const std::string & getDescription ()
 Returns the description specified at construction.
 
addr_t getBlockSize () const
 Returns the block size of memory represented by this interface. Read and write accesses must not span block boundaries (where addr % block_size == 0).
 
addr_t getRange () const
 Gets the total span of this interface's valid address range.
 
addr_t getLowEnd () const
 Gets the lowest address accessible.
 
addr_t getHighEnd () const
 Gets the highest address accessible + 1.
 
addr_t getAccessibleSize () const
 Gets the total accessible size of this interface's valid addresses within the total size (getRange) excluding holes between access windows.
 
const std::vector< AccessWindow > & getWindows () const
 Gets the vector of windows representing this interface.
 
bool isAddressInWindows (addr_t addr) const noexcept
 Determines if the given address is in an access window defined for this interface.
 
void verifyInAccessWindows (addr_t addr, addr_t size) const
 Verifies that the range [addr, addr+size) is within the access windows for this interface.
 
bool isInAccessWindows (addr_t addr, addr_t size) const
 Determines if the range [addr, addr+size) is within the access windows for this interface.
 
void verifyNoBlockSpan (addr_t addr, addr_t size) const
 Verifies that the given address does not span block boundaries defined for this interface.
 
bool doesAccessSpan (addr_t addr, addr_t size) const noexcept
 Determines if the given address spans block boundaries defined for this interface. Accesses which span blocks are illegal for read/write accesses, but allowed for peak/poke debug accesses.
 
bool tryPeek (addr_t addr, addr_t size, uint8_t *buf) const
 Attempts to 'peek' memory without having any side effects, size-limitations, alignment constraints except that all bytes peeked are inside an access window for this interface.
 
void peek (addr_t addr, addr_t size, uint8_t *buf) const
 Wrapper on tryPeek which throws a MemoryAccessError if the peek is not legal.
 
bool tryPoke (addr_t addr, addr_t size, const uint8_t *buf)
 Attempts to 'poke' memory without having any side effects other than changing the bytes within the range [ addr , addr + size ). Poke has no size-limitations or alignment constraints except that all bytes peeked are inside an access window for this interface.
 
void poke (addr_t addr, addr_t size, const uint8_t *buf)
 Wrapper on tryPoke which throws a MemoryAccessError if the poke is not legal.
 

Additional Inherited Members

- Protected Member Functions inherited from sparta::memory::BlockingMemoryIF
- Protected Attributes inherited from sparta::memory::DebugMemoryIF
const addr_t block_size_
 Size of a block accessed through this interface.
 
addr_t block_mask_
 Mask applied to an address to get only bits representing the block ID.
 
addr_t block_idx_lsb_
 rshift applied to an address to get the block ID
 
const std::vector< AccessWindowacc_windows_
 Vector of access windows representing this memory.
 
TranslationIFtrans_
 Translation interface created for this interface. Externally owned.
 
const std::string *const desc_ptr_
 Description pointer.
 
addr_t total_range_
 Range of addresses from highest accessible to lowest.
 
addr_t low_end_
 Lowest accessible address.
 
addr_t high_end_
 Highest accessible address + 1.
 
addr_t accessible_size_
 Number of bytes accessible through this interface.
 

Detailed Description

template<class MemoryWriteType = StoreData>
class sparta::memory::CachedMemory< MemoryWriteType >

Memory that can be used as a cache for core models.

Template Parameters
MemoryWriteTypeType supplied by the modeler to track the outstanding writes

CachedMemory is used by a functional/performance model to "cache" outstanding writes and provide those values back to the core when asked. It is implemented as full memory model, with its memory always representing the latest stored value that is not committed.

When the write is committed by a functional model (like in a cosimulation environment), the data is pushed downstream.

If the memory is not to be pushed out (flushing for example), the modeler can "drop" that memory update and CachedMemory will restore the previous value.

Use case: data-driven performance modeling where there are speculative stores (storing to a local store commit buffer) and there are dependent loads on that data. If the store is no longer speculative, the store is officially committed. If it's flushed, old data can be restored and downstream memory (main memory/IO devices, etc) will never see the data.

System memory is responsible for updating other CachedMemory instances in the case of multicore.

Since this class acts like a cache off of a core (example), a few rules apply:

  1. Reads will always be from this block of memory and must be aligned. If the read is not in this cache, downstream memory will be peeked, but the result will not be cached.
  2. Writes will always cache. If the data were not in the cache initially, downsteam memory will be peeked and loaded before merging the write data.
  3. Peeking will always be a read on the cache memory. If the block is not in the cache, peeking will be forwarded to downstream memory
  4. Poking will always write to the cache as well as downsteam memory. If the data is not in the cache, it will be loaded into the cache before being written

Definition at line 164 of file CachedMemory.hpp.

Constructor & Destructor Documentation

◆ CachedMemory()

template<class MemoryWriteType >
sparta::memory::CachedMemory< MemoryWriteType >::CachedMemory ( const std::string & name,
uint64_t write_id,
uint32_t outstanding_writes_watermark,
addr_t block_size,
addr_t total_size,
sparta::memory::BlockingMemoryIF * downstream_memory )

Create a CachedMemory object.

Parameters
nameCachedMemory name
write_idThe ID this CachedMemory to uniquify memory writes
outstanding_writes_watermarkWatermark for assertion if uncomitted writes get too large
block_sizeBlock size of the cache. (See sparta::MemoryObject::MemoryObject)
total_sizeTotal size of the cache block (See sparta::MemoryObject::MemoryObject)
downstream_memoryThe coherency point past this CachedMemory

Definition at line 280 of file CachedMemory.hpp.

Member Function Documentation

◆ commitWrite()

template<class MemoryWriteType >
void sparta::memory::CachedMemory< MemoryWriteType >::commitWrite ( const MemoryWriteType & write_to_commit)

Commit the write that matches the given MemoryWriteType.

Parameters
write_to_commitThe MemoryAccessWrite to commit

There must be an exact match in the cache for that address/size combination for the outstanding write to be removed

Definition at line 394 of file CachedMemory.hpp.

◆ dropWrite()

template<class MemoryWriteType >
void sparta::memory::CachedMemory< MemoryWriteType >::dropWrite ( const MemoryWriteType & write_to_drop)

Drop the outstanding write that matches the given MemoryWriteType.

Parameters
write_to_dropThe MemoryAccessWrite to drop
Exceptions
SpartaExceptionif no commit with the given exists

Definition at line 421 of file CachedMemory.hpp.

◆ getLastOutstandingWrite()

template<class MemoryWriteType = StoreData>
const MemoryWriteType & sparta::memory::CachedMemory< MemoryWriteType >::getLastOutstandingWrite ( ) const
inline

Return the latest outstanding store access.

Returns
The latest/newest write access created

Definition at line 249 of file CachedMemory.hpp.

◆ getNumOutstandingWrites()

template<class MemoryWriteType = StoreData>
uint32_t sparta::memory::CachedMemory< MemoryWriteType >::getNumOutstandingWrites ( ) const
inline

Return the number of uncomitted writes.

Definition at line 214 of file CachedMemory.hpp.

◆ getOutstandingWrites()

template<class MemoryWriteType = StoreData>
const std::map< uint64_t, MemoryWriteType > & sparta::memory::CachedMemory< MemoryWriteType >::getOutstandingWrites ( ) const
inline

Get all outstanding writes.

Returns
vector of outstanding memory access writes based on the user type

Definition at line 194 of file CachedMemory.hpp.

◆ getOutstandingWritesForAddr()

template<class MemoryWriteType >
std::vector< MemoryWriteType > sparta::memory::CachedMemory< MemoryWriteType >::getOutstandingWritesForAddr ( addr_t paddr) const

Given address, find outstanding writes that are not merged/committed.

Parameters
paddrPhysical address to search for
Returns
vector of outstanding memory writes that match

This function will return all MemAccessWrites that it finds that partially (at least/most 1 byte) or completely contains the given paddr.

The first element of the vector is the oldest outstanding write

Definition at line 381 of file CachedMemory.hpp.

◆ getWriteID()

template<class MemoryWriteType = StoreData>
uint64_t sparta::memory::CachedMemory< MemoryWriteType >::getWriteID ( ) const
inline

Get the write ID for this cache.

Returns
The write ID given at construction

Definition at line 188 of file CachedMemory.hpp.

◆ mergeWrite()

template<class MemoryWriteType >
void sparta::memory::CachedMemory< MemoryWriteType >::mergeWrite ( addr_t paddr,
addr_t size,
const uint8_t * buf )

Merge an incoming write from system memory.

Parameters
paddrWrite's address
sizeWrite's size (in bytes)
bufData to store

This function will merge the given data into this cache only writing those bytes that do not collide wtih stores that have not been committed.

Definition at line 461 of file CachedMemory.hpp.


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