core

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneMetadata

func CloneMetadata(src map[string]string) map[string]string

CloneMetadata creates a shallow copy of the metadata map.

Types

type CHIMessageType

type CHIMessageType string

CHIMessageType represents CHI protocol message types.

const (
	CHIMsgReq     CHIMessageType = "Req"     // Request message
	CHIMsgResp    CHIMessageType = "Resp"    // Response message
	CHIMsgData    CHIMessageType = "Data"    // Data message
	CHIMsgComp    CHIMessageType = "Comp"    // Completion message
	CHIMsgSnp     CHIMessageType = "Snp"     // Snoop request message
	CHIMsgSnpResp CHIMessageType = "SnpResp" // Snoop response message
)

type CHIResponseType

type CHIResponseType string

CHIResponseType represents CHI response types.

const (
	CHIRespCompData   CHIResponseType = "CompData"   // Completion with data
	CHIRespCompAck    CHIResponseType = "CompAck"    // Completion acknowledgment
	CHIRespSnpData    CHIResponseType = "SnpData"    // Snoop response with data
	CHIRespSnpInvalid CHIResponseType = "SnpInvalid" // Snoop response invalidating cache
	CHIRespSnpNoData  CHIResponseType = "SnpNoData"  // Snoop response with no data
)

type CHITransactionType

type CHITransactionType string

CHITransactionType represents CHI protocol transaction types.

const (
	CHITxnReadNoSnp   CHITransactionType = "ReadNoSnp"
	CHITxnWriteNoSnp  CHITransactionType = "WriteNoSnp"
	CHITxnReadOnce    CHITransactionType = "ReadOnce"
	CHITxnWriteUnique CHITransactionType = "WriteUnique"
)

type CacheState

type CacheState string

CacheState represents cache line state.

const (
	CacheStateInvalid CacheState = "Invalid"
	CacheStateShared  CacheState = "Shared"
	CacheStateUnique  CacheState = "Unique"
)

type CacheStateTransition

type CacheStateTransition struct {
	Cycle     int
	FromState CacheState
	ToState   CacheState
	Reason    string
}

CacheStateTransition represents a cache state transition.

type DependencyType

type DependencyType string

DependencyType represents the type of dependency between transactions.

const (
	// Causal dependency: Transaction B is directly triggered by Transaction A
	DepCausal DependencyType = "Causal"

	// Cache dependencies: Transaction B triggered due to Transaction A's cache operations
	DepCacheMiss       DependencyType = "CacheMiss"
	DepCacheEvict      DependencyType = "CacheEvict"
	DepCacheInvalidate DependencyType = "CacheInvalidate"

	// Ordering dependencies: Transaction B must wait for Transaction A to complete
	DepSameAddrOrdering DependencyType = "SameAddrOrdering"
	DepGlobalOrdering   DependencyType = "GlobalOrdering"

	// Directory dependencies: Transaction B needs to wait for Transaction A's directory operation
	DepDirectoryQuery  DependencyType = "DirectoryQuery"
	DepDirectoryUpdate DependencyType = "DirectoryUpdate"

	// Resource contention: Transaction B competes with Transaction A for the same resource
	DepResourceContention DependencyType = "ResourceContention"
)

type DirectoryOperation

type DirectoryOperation struct {
	Cycle     int
	Operation string
	Address   uint64
}

DirectoryOperation represents a directory operation.

type DirectoryState

type DirectoryState string

DirectoryState represents directory state.

const (
	DirectoryStateExclusive DirectoryState = "Exclusive"
	DirectoryStateShared    DirectoryState = "Shared"
	DirectoryStateInvalid   DirectoryState = "Invalid"
)

type EdgeKey

type EdgeKey struct {
	FromID int `json:"fromID"`
	ToID   int `json:"toID"`
}

EdgeKey represents a unique edge in the network (fromID -> toID).

type MESIState

type MESIState string

MESIState represents the MESI cache coherence protocol state.

const (
	MESIInvalid   MESIState = "Invalid"   // Cache line is invalid (not present or stale)
	MESIShared    MESIState = "Shared"    // Cache line is shared (multiple caches may have it)
	MESIExclusive MESIState = "Exclusive" // Cache line is exclusive (only this cache has it, clean)
	MESIModified  MESIState = "Modified"  // Cache line is modified (only this cache has it, dirty)
)

func (MESIState) CanProvideData

func (s MESIState) CanProvideData() bool

CanProvideData returns true if the cache line can provide data to other caches.

func (MESIState) IsValid

func (s MESIState) IsValid() bool

IsValid returns true if the cache line is valid (not Invalid).

type NodeInfo

type NodeInfo struct {
	ID    int      `json:"id"`
	Label string   `json:"label"`
	Type  NodeType `json:"type"`
}

NodeInfo represents node information for timeline.

type NodeType

type NodeType string

NodeType represents the CHI protocol node type.

const (
	NodeTypeRN NodeType = "RN" // Request Node - initiates transactions
	NodeTypeHN NodeType = "HN" // Home Node - manages cache coherence
	NodeTypeSN NodeType = "SN" // Slave Node - provides data
)

type OrderingDecision

type OrderingDecision struct {
	Cycle       int
	Decision    string
	RelatedTxns []int64
}

OrderingDecision represents an ordering decision point.

type Packet

type Packet struct {
	ID    int64  // unique packet id
	Type  string // legacy: "request" or "response" - use MessageType instead (kept for compatibility)
	SrcID int    // source node id
	DstID int    // destination node id

	GeneratedAt int // cycle when generated (for requests)
	SentAt      int // cycle when sent to channel
	ReceivedAt  int // cycle when received by next hop
	CompletedAt int // cycle when processed (for requests)

	// Legacy fields (deprecated, kept for backward compatibility)
	// These fields are maintained for compatibility with older code but should not be used in new code.
	// Migration: Use CHI protocol fields (MessageType, TransactionType) instead of Type.
	// MasterID is equivalent to the original Request Node ID in CHI terminology.
	MasterID  int   // legacy: original master/request node id - use CHI MessageType + DstID instead
	RequestID int64 // legacy: request id - same as ID for request packets, preserved for compatibility

	// CHI protocol fields (preferred)
	// These are the primary fields for packet identification and routing in CHI protocol.
	TransactionType CHITransactionType // CHI transaction type (ReadNoSnp, WriteNoSnp, etc.)
	MessageType     CHIMessageType     // CHI message type (Req, Resp, Data, Comp) - primary field for message type
	ResponseType    CHIResponseType    // CHI response type (CompData, CompAck, etc.)
	Address         uint64             // memory address for the transaction
	DataSize        int                // data size in bytes (default: DefaultCacheLineSize)

	// Transaction tracking
	TransactionID int64 // ID of the transaction this packet belongs to (0 if not associated)

	// Snoop-related fields
	OriginalTxnID int64 // For Snoop responses: the original transaction ID that triggered this snoop
	SnoopTargetID int   // For Snoop requests: the target Request Node ID to snoop

	// Packet generation tracking
	ParentPacketID int64 // ID of the parent packet that generated this packet (0 if no parent)

	// Extension metadata, used by plugins to attach custom fields.
	Metadata map[string]string
}

Packet represents a CHI protocol message flowing through the simulator. Migration status: - Primary fields: Use CHI protocol fields (TransactionType, MessageType, ResponseType) - Legacy fields: Kept for backward compatibility, will be deprecated in future versions - When to use: New code should prefer CHI fields; legacy fields are checked as fallback

func (*Packet) DeleteMetadata

func (p *Packet) DeleteMetadata(key string)

DeleteMetadata removes a metadata key from the packet.

func (*Packet) GetMetadata

func (p *Packet) GetMetadata(key string) (string, bool)

GetMetadata returns the value for a metadata key.

func (*Packet) SetMetadata

func (p *Packet) SetMetadata(key, value string)

SetMetadata attaches a key/value pair to the packet metadata.

type PacketEvent

type PacketEvent struct {
	Sequence       int64             `json:"sequence"`
	TransactionID  int64             `json:"transactionID"`
	PacketID       int64             `json:"packetID"`
	ParentPacketID int64             `json:"parentPacketID"` // 0 means no parent packet
	NodeID         int               `json:"nodeID"`
	NodeLabel      string            `json:"nodeLabel"` // "RN 0", "SN 1", etc.
	EventType      PacketEventType   `json:"eventType"`
	Cycle          int               `json:"cycle"`
	EdgeKey        *EdgeKey          `json:"edgeKey,omitempty"` // nil for in-node events
	Metadata       map[string]string `json:"metadata,omitempty"`
}

PacketEvent represents a packet event in the transaction timeline.

type PacketEventType

type PacketEventType string

PacketEventType represents the type of packet event.

const (
	PacketEnqueued        PacketEventType = "PacketEnqueued"
	PacketDequeued        PacketEventType = "PacketDequeued"
	PacketProcessingStart PacketEventType = "PacketProcessingStart"
	PacketProcessingEnd   PacketEventType = "PacketProcessingEnd"
	PacketSent            PacketEventType = "PacketSent"
	PacketInTransitEnd    PacketEventType = "PacketInTransitEnd"
	PacketReceived        PacketEventType = "PacketReceived"
	PacketGenerated       PacketEventType = "PacketGenerated"
)

type PacketInfo

type PacketInfo struct {
	ID              int64              `json:"id"`
	Type            string             `json:"type"`
	SrcID           int                `json:"srcID"`
	DstID           int                `json:"dstID"`
	GeneratedAt     int                `json:"generatedAt"`
	SentAt          int                `json:"sentAt"`
	ReceivedAt      int                `json:"receivedAt"`
	CompletedAt     int                `json:"completedAt"`
	MasterID        int                `json:"masterID"`
	RequestID       int64              `json:"requestID"`
	TransactionType CHITransactionType `json:"transactionType"`
	MessageType     CHIMessageType     `json:"messageType"`
	ResponseType    CHIResponseType    `json:"responseType"`
	Address         uint64             `json:"address"`
	DataSize        int                `json:"dataSize"`
	TransactionID   int64              `json:"transactionID"` // Transaction ID this packet belongs to
	Metadata        map[string]string  `json:"metadata,omitempty"`
}

PacketInfo represents packet information for visualization.

type Position

type Position struct {
	X, Y float64
}

Position represents the position of a node in visualization.

type QueueInfo

type QueueInfo struct {
	Name     string       `json:"name"`
	Length   int          `json:"length"`
	Capacity int          `json:"capacity"` // -1 means unlimited capacity
	Packets  []PacketInfo `json:"packets,omitempty"`
}

QueueInfo represents queue information for visualization.

type StateTransition

type StateTransition struct {
	Cycle        int              // Cycle when transition occurred
	FromState    TransactionState // Previous state
	ToState      TransactionState // New state
	Reason       string           // Reason for transition (brief description)
	RelatedTxnID *int64           // Related transaction ID (if any)
}

StateTransition represents a key state transition in a transaction's lifecycle.

type TimeRange

type TimeRange struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

TimeRange represents a time range.

type Transaction

type Transaction struct {
	Context *TransactionContext
}

Transaction represents a CHI protocol transaction.

type TransactionContext

type TransactionContext struct {
	// Basic information (must store)
	TransactionID   int64
	TransactionType CHITransactionType
	Address         uint64

	// State information (simplified)
	State        TransactionState
	StateHistory []StateTransition // Only record key state transition points
	InitiatedAt  int
	CompletedAt  int

	// Dependency relationships (must store, for graph construction)
	SameAddrOrdering      []int64 // Transaction IDs with same-address ordering dependency
	GlobalOrdering        []int64 // Transaction IDs with global ordering dependency
	GeneratedTransactions []int64 // Child transaction IDs generated by this transaction

	// Metadata (lightweight extension fields)
	Metadata map[string]string // Use string instead of interface{} to reduce storage
}

TransactionContext represents the context of a CHI transaction. Design principle: Only store essential information, detailed state queried via interfaces.

type TransactionDependency

type TransactionDependency struct {
	FromTransactionID int64          // Source transaction ID
	ToTransactionID   int64          // Target transaction ID
	DependencyType    DependencyType // Type of dependency
	Reason            string         // Reason for dependency (CacheMiss, SameAddrOrdering, etc.)
	Cycle             int            // Cycle when dependency was created
}

TransactionDependency represents a dependency relationship between two transactions.

type TransactionState

type TransactionState string

TransactionState represents the state of a CHI transaction.

const (
	TxStateInitiated TransactionState = "Initiated" // Transaction created
	TxStateInFlight  TransactionState = "InFlight"  // Transaction in progress
	TxStateCompleted TransactionState = "Completed" // Transaction completed successfully
	TxStateAborted   TransactionState = "Aborted"   // Transaction aborted
)

type TransactionTimeline

type TransactionTimeline struct {
	TransactionID int64          `json:"transactionID"`
	Events        []*PacketEvent `json:"events"`
	Nodes         []NodeInfo     `json:"nodes"`
	TimeRange     TimeRange      `json:"timeRange"`
	Packets       []PacketInfo   `json:"packets"`
}

TransactionTimeline represents the timeline data for a transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL