The Sparta Modeling Framework
|
Memory that can be used as a cache for core models. More...
#include <CachedMemory.hpp>
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. | |
![]() | |
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 DMIBlockingMemoryIF * | getDMI (addr_t addr, addr_t size) |
Get a DMI blocking interface to access the given address/size. | |
virtual void | invalidateAllDMI () |
Invalidate all DMI's. | |
![]() | |
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 TranslationIF * | getTranslationIF () |
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 | |
![]() | |
![]() | |
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< AccessWindow > | acc_windows_ |
Vector of access windows representing this memory. | |
TranslationIF * | trans_ |
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. | |
Memory that can be used as a cache for core models.
MemoryWriteType | Type 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:
Definition at line 164 of file CachedMemory.hpp.
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.
name | CachedMemory name |
write_id | The ID this CachedMemory to uniquify memory writes |
outstanding_writes_watermark | Watermark for assertion if uncomitted writes get too large |
block_size | Block size of the cache. (See sparta::MemoryObject::MemoryObject) |
total_size | Total size of the cache block (See sparta::MemoryObject::MemoryObject) |
downstream_memory | The coherency point past this CachedMemory |
Definition at line 280 of file CachedMemory.hpp.
void sparta::memory::CachedMemory< MemoryWriteType >::commitWrite | ( | const MemoryWriteType & | write_to_commit | ) |
Commit the write that matches the given MemoryWriteType.
write_to_commit | The 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.
void sparta::memory::CachedMemory< MemoryWriteType >::dropWrite | ( | const MemoryWriteType & | write_to_drop | ) |
Drop the outstanding write that matches the given MemoryWriteType.
write_to_drop | The MemoryAccessWrite to drop |
SpartaException | if no commit with the given exists |
Definition at line 421 of file CachedMemory.hpp.
|
inline |
Return the latest outstanding store access.
Definition at line 249 of file CachedMemory.hpp.
|
inline |
Return the number of uncomitted writes.
Definition at line 214 of file CachedMemory.hpp.
|
inline |
Get all outstanding writes.
Definition at line 194 of file CachedMemory.hpp.
std::vector< MemoryWriteType > sparta::memory::CachedMemory< MemoryWriteType >::getOutstandingWritesForAddr | ( | addr_t | paddr | ) | const |
Given address, find outstanding writes that are not merged/committed.
paddr | Physical address to search for |
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.
|
inline |
Get the write ID for this cache.
Definition at line 188 of file CachedMemory.hpp.
void sparta::memory::CachedMemory< MemoryWriteType >::mergeWrite | ( | addr_t | paddr, |
addr_t | size, | ||
const uint8_t * | buf ) |
Merge an incoming write from system memory.
paddr | Write's address |
size | Write's size (in bytes) |
buf | Data 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.