15.6 Write Buffer Implementation

<< Click to Display Table of Contents >>

Navigation:  ASA-EMulatR Reference Guide > Introduction > Architecture Overview > Chapter 15 – Memory System Implementation Details >

15.6 Write Buffer Implementation

15.6.1 Per-CPU Write Buffer State

 

The WriteBufferManager maintains a CPUWriteBufferState for each CPU, containing a fixed array of 8 WriteBufferEntry slots (MAX_ENTRIES = 8), an atomic pendingCount, atomic drainRequested and drainInProgress flags, a per-CPU QMutex, and a QWaitCondition for drain synchronization. The manager is constructed with the active CPU count and supports up to MAX_CPUS (compile-time constant).

 


 

15.6.2 Draining Rules

 

Write buffers are drained (all buffered stores committed) when any of the following conditions are met:

 

MB instruction executes (full memory barrier)

WMB instruction executes (write memory barrier)

EXCB or TRAPB requires serialization

PAL entry or exit occurs

Certain exceptions are delivered

System shutdown (flushAllBuffers() drains all CPUs in order)

 

The CBox calls drainCPU(cpuId, commitCallback) with a callback that commits each WriteBufferEntry to GuestMemory. The drain dequeues entries in FIFO order via dequeueWrite(), ensuring stores become visible in program order.

 


 

15.6.3 Source Files

 

File

Lines (approx)

Content

memoryLib/WriteBufferManager.h

~218

WriteBufferManager class, CPUWriteBufferState structure

memoryLib/WriteBufferManager.cpp

~272

Drain, enqueue, dequeue, flush implementations

coreLib/WriteBufferEntry.h

~67

WriteBufferEntry structure: address, data, size, valid, mmio, timestamp

 

See Also: memoryLib/global_writeBufferManager.h – Singleton accessor and lifecycle; 14.5 CBox – Cache / Control Box (write buffer responsibilities).