Documentation
¶
Index ¶
- type Cache
- type CacheLine
- type EvictCallback
- type FullyAssociativeCache
- func (c *FullyAssociativeCache) CanForward(addr uint64) bool
- func (c *FullyAssociativeCache) GetCapacity() int
- func (c *FullyAssociativeCache) GetData(addr uint64) []byte
- func (c *FullyAssociativeCache) GetSize() int
- func (c *FullyAssociativeCache) GetState(addr uint64) State
- func (c *FullyAssociativeCache) HandleSnoop(snoopOpcode int, addr uint64) (*SnoopResponse, error)
- func (c *FullyAssociativeCache) Invalidate(addr uint64)
- func (c *FullyAssociativeCache) IsPresent(addr uint64) bool
- func (c *FullyAssociativeCache) SetData(addr uint64, data []byte)
- func (c *FullyAssociativeCache) SetEvictCallback(callback EvictCallback)
- func (c *FullyAssociativeCache) SetState(addr uint64, state State)
- type SnoopResponse
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// GetState returns the current state of the cache line at the given address.
// Returns StateInvalid if the line is not present.
GetState(addr uint64) State
// SetState updates the state of the cache line at the given address.
SetState(addr uint64, state State)
// GetData retrieves the data stored in the cache line at the given address.
// Returns nil if the line is invalid or not present.
GetData(addr uint64) []byte
// SetData updates the data stored in the cache line at the given address.
// This may also implicitly set the state to Modified if the line exists.
SetData(addr uint64, data []byte)
// Invalidate marks the cache line at the given address as invalid.
Invalidate(addr uint64)
// IsPresent checks if a cache line exists for the given address (regardless of state).
IsPresent(addr uint64) bool
// SetEvictCallback sets the callback function to be called when a cache line is evicted.
SetEvictCallback(callback EvictCallback)
// HandleSnoop handles a snoop request from another cache/directory.
// Protocol-agnostic: opcode interpretation depends on implementation.
// Parameters:
// - snoopOpcode: Protocol-specific snoop opcode
// - addr: Target address
// Returns:
// - *SnoopResponse: Response including data if needed
// - error: Any error encountered
HandleSnoop(snoopOpcode int, addr uint64) (*SnoopResponse, error)
// CanForward checks if this cache can forward data for the given address.
// Used in protocols that support direct cache-to-cache transfer (DMT).
// Returns true if the cache has the data in a state that allows forwarding.
CanForward(addr uint64) bool
}
Cache defines the interface for cache storage and state management. This interface is protocol-agnostic and focuses purely on state/data storage.
type EvictCallback ¶
EvictCallback is called when a cache line is evicted. Parameters: addr (address of evicted line), state (state before eviction), data (data before eviction)
type FullyAssociativeCache ¶
type FullyAssociativeCache struct {
// contains filtered or unexported fields
}
FullyAssociativeCache implements a simple fully-associative cache with random replacement.
func NewFullyAssociativeCache ¶
func NewFullyAssociativeCache(capacity int) *FullyAssociativeCache
NewFullyAssociativeCache creates a new fully-associative cache with the specified capacity.
func (*FullyAssociativeCache) CanForward ¶
func (c *FullyAssociativeCache) CanForward(addr uint64) bool
CanForward implements Cache.CanForward
func (*FullyAssociativeCache) GetCapacity ¶
func (c *FullyAssociativeCache) GetCapacity() int
GetCapacity returns the capacity of the cache.
func (*FullyAssociativeCache) GetData ¶
func (c *FullyAssociativeCache) GetData(addr uint64) []byte
GetData retrieves the data stored in the cache line at the given address.
func (*FullyAssociativeCache) GetSize ¶
func (c *FullyAssociativeCache) GetSize() int
GetSize returns the current number of cache lines.
func (*FullyAssociativeCache) GetState ¶
func (c *FullyAssociativeCache) GetState(addr uint64) State
GetState returns the current state of the cache line at the given address.
func (*FullyAssociativeCache) HandleSnoop ¶
func (c *FullyAssociativeCache) HandleSnoop(snoopOpcode int, addr uint64) (*SnoopResponse, error)
HandleSnoop implements Cache.HandleSnoop
func (*FullyAssociativeCache) Invalidate ¶
func (c *FullyAssociativeCache) Invalidate(addr uint64)
Invalidate marks the cache line at the given address as invalid.
func (*FullyAssociativeCache) IsPresent ¶
func (c *FullyAssociativeCache) IsPresent(addr uint64) bool
IsPresent checks if a cache line exists for the given address (regardless of state).
func (*FullyAssociativeCache) SetData ¶
func (c *FullyAssociativeCache) SetData(addr uint64, data []byte)
SetData updates the data stored in the cache line at the given address.
func (*FullyAssociativeCache) SetEvictCallback ¶
func (c *FullyAssociativeCache) SetEvictCallback(callback EvictCallback)
SetEvictCallback sets the callback function to be called when a cache line is evicted.
func (*FullyAssociativeCache) SetState ¶
func (c *FullyAssociativeCache) SetState(addr uint64, state State)
SetState updates the state of the cache line at the given address.
type SnoopResponse ¶
type SnoopResponse struct {
ResponseOpcode int // Protocol-specific response opcode
Data []byte // Data if forwarding
HasData bool // Whether data is included
}
SnoopResponse represents the response to a snoop request. Used by coherence protocols (e.g., CHI, MESI, MOESI).