node

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalibrateCyclesPerUS

func CalibrateCyclesPerUS(duration time.Duration) float64

CalibrateCyclesPerUS measures and returns the number of CPU cycles per microsecond. It samples for the specified duration (e.g. 100ms) to average out noise.

func CreatePacket

func CreatePacket(src, dst int, payload string) packet.Packet

CreatePacket is a helper to create a packet (compatibility alias).

func GetCPUCycles

func GetCPUCycles() uint64

GetCPUCycles returns the current value of the CPU time-stamp counter (RDTSC). Implemented in cpu_amd64.s

func NewBufferlessRing

func NewBufferlessRing(nodeCount int, queueSize int, ringLatency int, queueBandwidth int) ([]*WorkerNode, []*BufferlessRingRouterNode, []Tickable)

NewBufferlessRing creates a complete bufferless ring network. Returns slices of workers, routers, and all tickable components (including links).

func Pause

func Pause()

Pause executes the PAUSE instruction to hint the processor that this is a spin-wait loop. Implemented in cpu_amd64.s

func SpinWait

func SpinWait(minUs, maxUs int)

SpinWait simulates processing time by busy-waiting. This is an estimate of GEM5 O3 CPU core execution time for a typical node operation. It occupies the CPU instead of yielding, which better simulates heavy compute loads.

func SpinWaitCycles

func SpinWaitCycles(cycles uint64)

SpinWaitCycles busy-waits for approximately the specified number of CPU cycles. This is more precise than SpinWait (us) if the CPU frequency is stable.

Types

type BaseNode

type BaseNode struct {
	// contains filtered or unexported fields
}

BaseNode implements the common logic for all nodes. Specific node types should embed BaseNode and implement NodeHandler.

func NewBaseNode

func NewBaseNode(id int, handler NodeHandler) *BaseNode

NewBaseNode creates a new BaseNode.

func (*BaseNode) AddCache

func (n *BaseNode) AddCache(c cache.Cache)

AddCache attaches a cache to the Node.

func (*BaseNode) AddDirectory

func (n *BaseNode) AddDirectory(d directory.Directory)

AddDirectory attaches a directory.

func (*BaseNode) AddInputQueue

func (n *BaseNode) AddInputQueue(q InputQueue) error

AddInputQueue registers an InputQueue.

func (*BaseNode) AddOutputQueue

func (n *BaseNode) AddOutputQueue(q OutputQueue) error

AddOutputQueue registers an OutputQueue.

func (*BaseNode) AdvanceTo

func (n *BaseNode) AdvanceTo(targetCycle int) error

AdvanceTo executes the configured cycles sequentially using Background context until the node reaches the target cycle.

func (*BaseNode) Caches

func (n *BaseNode) Caches() []cache.Cache

Caches returns attached caches.

func (*BaseNode) CurrentCycle

func (n *BaseNode) CurrentCycle() int

CurrentCycle returns the current cycle of the node.

func (*BaseNode) DeleteData

func (n *BaseNode) DeleteData(key string)

DeleteData removes protocol-specific data.

func (*BaseNode) Directories

func (n *BaseNode) Directories() []directory.Directory

Directories returns attached directories.

func (*BaseNode) GetAllData

func (n *BaseNode) GetAllData() map[string]interface{}

GetAllData returns a copy of all protocol-specific data.

func (*BaseNode) GetData

func (n *BaseNode) GetData(key string) interface{}

GetData retrieves protocol-specific data. Returns nil if key not found.

func (*BaseNode) GetOutputQueue

func (n *BaseNode) GetOutputQueue(index int) OutputQueue

GetOutputQueue safely retrieves an output queue by index.

func (*BaseNode) HasData

func (n *BaseNode) HasData(key string) bool

HasData checks if a key exists.

func (*BaseNode) ID

func (n *BaseNode) ID() int

ID returns the node identifier.

func (*BaseNode) InjectPacket

func (n *BaseNode) InjectPacket(pkt packet.Packet) error

InjectPacket is a helper to inject a packet into the first output queue.

func (*BaseNode) InputQueues

func (n *BaseNode) InputQueues() []InputQueue

InputQueues returns the registered inputs.

func (*BaseNode) OutputQueues

func (n *BaseNode) OutputQueues() []OutputQueue

OutputQueues returns the registered outputs.

func (*BaseNode) SetData

func (n *BaseNode) SetData(key string, value interface{})

SetData stores protocol-specific data. Key format recommendation: "{Protocol}_{Key}", e.g., "CHI_Role", "AXI_Config"

func (*BaseNode) Tick

func (n *BaseNode) Tick(cycle uint64, _ time.Duration) error

Tick executes one cycle of the node's logic. Order: Receive (Input) -> Process (Handler) -> Send (Output)

func (*BaseNode) UpdateData

func (n *BaseNode) UpdateData(modifier func(map[string]interface{}))

UpdateData atomically updates the entire protocol-specific data map.

func (*BaseNode) UpdateKeyData

func (n *BaseNode) UpdateKeyData(key string, modifier func(interface{}) interface{})

UpdateKeyData atomically updates a specific key in protocol-specific data.

type BufferlessRingRouterNode

type BufferlessRingRouterNode struct {
	*BaseNode // Embed BaseNode for base functionality
	// contains filtered or unexported fields
}

BufferlessRingRouterNode implements a router for bufferless ring topology.

Architecture: - 4 ports: ringIn, ringOut, localIn, localOut - Internal buffer ONLY for local injection (ring traffic never buffered) - Routing logic: check packet.TargetID to decide ejection vs. forwarding

Key Design Principles: - Ring traffic NEVER buffered in router (always forwarded immediately) - Packets that cannot eject continue on ring (loop around) - Only local injection needs buffering (when ring temporarily busy) - Backpressure only (no packet dropping)

Queue Assignment: - inputs[0]: ringInQueue (from previous router) - inputs[1]: localInQueue (from local worker) - outputs[0]: ringOutQueue (to next router) - outputs[1]: localOutQueue (to local worker)

func NewBufferlessRingRouter

func NewBufferlessRingRouter(routerID, workerID, bufferCapacity int) *BufferlessRingRouterNode

NewBufferlessRingRouter creates a router node for bufferless ring topology.

Parameters: - routerID: ID of this router node - workerID: ID of the connected worker node - bufferCapacity: internal buffer size for injection queue

func (*BufferlessRingRouterNode) GetBufferCapacity

func (r *BufferlessRingRouterNode) GetBufferCapacity() int

GetBufferCapacity returns the buffer capacity.

func (*BufferlessRingRouterNode) GetBufferOccupancy

func (r *BufferlessRingRouterNode) GetBufferOccupancy() int

GetBufferOccupancy returns the current injection buffer occupancy.

func (*BufferlessRingRouterNode) GetInjectionBufferOccupancy

func (r *BufferlessRingRouterNode) GetInjectionBufferOccupancy() int

GetInjectionBufferOccupancy returns the injection buffer occupancy.

func (*BufferlessRingRouterNode) GetVisualState

func (r *BufferlessRingRouterNode) GetVisualState() string

GetVisualState returns the visual representation of this router. Format depends on global visualization.VisualizationMode.

func (*BufferlessRingRouterNode) GetWorkerID

func (r *BufferlessRingRouterNode) GetWorkerID() int

GetWorkerID returns the ID of the connected worker node.

func (*BufferlessRingRouterNode) Process

func (r *BufferlessRingRouterNode) Process(cycle uint64, inputs [][]queue.PacketRef) error

Process implements the NodeHandler interface. It replaces the old Tick logic for custom packet collection and routing.

type InputQueue

type InputQueue interface {
	Pick() []packet.Packet
	PeekPickTo(out []queue.PacketRef) int
	Tick(cycle int) error
	Length() int
	Capacity() int
	IsFull() bool
}

InputQueue describes the behaviors Node needs from an input buffer.

type Node

type Node interface {
	ID() int
	Tick(cycle uint64, duration time.Duration) error
	AddInputQueue(q InputQueue) error
	AddOutputQueue(q OutputQueue) error
	InputQueues() []InputQueue
	OutputQueues() []OutputQueue

	AddCache(c cache.Cache)
	Caches() []cache.Cache
	AddDirectory(d directory.Directory)
	Directories() []directory.Directory

	InjectPacket(pkt packet.Packet) error
	AdvanceTo(targetCycle int) error
	CurrentCycle() int

	SetData(key string, value interface{})
	GetData(key string) interface{}
	HasData(key string) bool
	DeleteData(key string)
	UpdateData(modifier func(map[string]interface{}))
	UpdateKeyData(key string, modifier func(interface{}) interface{})
}

Node defines the public interface for all simulation nodes. Node defines the public interface for all simulation nodes.

type NodeHandler

type NodeHandler interface {
	// Process handles data for the current cycle.
	// It receives packets from all input queues, indexed by queue ID.
	// Returns an error if processing fails.
	// Implementations should use BaseNode.GetOutputQueue(i).InjectPackets() to send data.
	//
	// Parameters:
	//   cycle: current simulation cycle
	//   inputs: packets received in this cycle from each input queue (inputs[i] comes from InputQueue i)
	Process(cycle uint64, inputs [][]queue.PacketRef) error
}

NodeHandler defines the interface that specific node implementations must satisfy.

type OutputQueue

type OutputQueue interface {
	Tick(cycle int) error
	Length() int
	Capacity() int
	IsFull() bool
	InjectPackets(cycle int, packets []packet.Packet) error
	OutBandwidth() int
}

OutputQueue describes the behaviors Node needs from an output buffer.

type Tickable

type Tickable interface {
	Tick(cycle uint64, duration time.Duration) error
}

Tickable is an interface for components that can be ticked.

type WorkerNode

type WorkerNode struct {
	*BaseNode
	// contains filtered or unexported fields
}

WorkerNode is a concrete node type for general purpose use (e.g. in simulator). It allows injecting custom behavior via hooks.

func NewWorkerNode

func NewWorkerNode(id int) *WorkerNode

NewWorkerNode creates a new WorkerNode.

func (*WorkerNode) GetProcessBuffer

func (w *WorkerNode) GetProcessBuffer() []packet.Packet

GetProcessBuffer returns the last processed packets.

func (*WorkerNode) Process

func (w *WorkerNode) Process(cycle uint64, inputs [][]queue.PacketRef) error

Process implements the NodeHandler interface.

func (*WorkerNode) SetProcessHook

func (w *WorkerNode) SetProcessHook(hook func(cycle uint64, inputs [][]queue.PacketRef) error)

SetProcessHook sets the hook for processing packets.

Directories

Path Synopsis
cmd
ring_simulator command

Jump to

Keyboard shortcuts

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