qualcomm/qbox
Loading...
Searching...
No Matches
McipsPlugin Class Reference
Inheritance diagram for McipsPlugin:
Collaboration diagram for McipsPlugin:

Public Member Functions

 McipsPlugin (const sc_core::sc_module_name &nm, qemu::LibQemu &inst)
void idle_tick_method ()
 SC_METHOD woken by m_idle_tick. When a CPU is active it does iothread-livelock recovery (bumps qemu_time if it has frozen). When all CPUs are idle it does nothing: just being scheduled was enough to step the SystemC kernel forward (the "idle pump").
void shutdown_cleanup ()
 Shared shutdown logic used by both the destructor and end_of_simulation().
void end_of_simulation () override
 Called by SystemC at end of simulation; stops all QEMU callbacks.
void end_of_elaboration () override
 Set up the plugin, register QEMU callbacks, and send the first sync window.
vCPUTime * get_vcpu (unsigned int cpu_index)
 Helper function to get vCPU time structure from scoreboard.
void attach_sync_window ()
void detach_sync_window ()
bool set_vcpu_insn_per_second (unsigned int cpu_index, uint64_t insn_per_second)
 Set the instructions per second for a specific vCPU.
void sync_qemu_time_ns ()
 Copy m_qemu_time into the atomic nanosecond field. Must hold m_mcips_mutex when calling.
sc_core::sc_time cpu_time_now (const vCPUTime *vcpu)
 Current time for a specific CPU (base + in-flight delta). Must hold m_mcips_mutex when calling.
sc_core::sc_time qemu_time_now ()
 Current QEMU time (base + active CPU's in-flight delta).
sc_core::sc_time qemu_time_now (const vCPUTime *active)
 Overload for callers that already hold m_mcips_mutex and have the active pointer.
vCPUTime * slowest_none_idle_cpu ()
 Find the CPU that is furthest behind in time.
vCPUTime * select_active_vcpu ()
 Pick the first non-idle CPU and make it the active one.
void pause_if_ahead (vCPUTime *vcpu, const vCPUTime *active, sc_core::sc_time current_qemu_time, sc_core::sc_time threshold)
 Pause the CPU if it has run too far ahead of the allowed limit. m_mcips_mutex must be held.
void resume_if_behind (const vCPUTime *active, sc_core::sc_time current_qemu_time, sc_core::sc_time threshold)
 Resume paused CPUs that are still within the allowed time limit. m_mcips_mutex must be held.
sc_core::sc_time compute_threshold ()
 Compute the time threshold that determines which CPUs may run.
void rebalance_and_sync (vCPUTime *vcpu=nullptr)
 Rebalance CPUs and notify SystemC. m_mcips_mutex must be held.
void set_systemc_window (const sc_core::sc_sync_window< sc_core::sc_sync_policy_tlm_quantum >::window *custom_window=nullptr)
 Set the SystemC synchronization window.
void receive_window_cb (const sc_core::sc_sync_window< sc_core::sc_sync_policy_tlm_quantum >::window &sc_w)
 Called by SystemC when a new time window is ready.
void vcpu_init (unsigned int cpu_index)
 Called under BQL before simulation starts; does not hold m_mcips_mutex.
void cpu_end_delta_quota (vCPUTime *vcpu)
 Called when a CPU has run its full instruction quota. Adds the time used, pauses/resumes CPUs as needed, and sends a new window. Takes and releases m_mcips_mutex inside.
void vcpu_tb_exec_cond (unsigned int cpu_index, void *)
 Called when a CPU has run at least global_quantum instructions.
void vcpu_tb_trans (qemu_plugin_tb *tb)
 Called when QEMU translates a block, adds instruction counting and quota check.
void vcpu_idle (unsigned int cpu_index)
 Called when a CPU goes idle (QEMU holds BQL; we additionally take m_mcips_mutex).
void vcpu_resume (unsigned int cpu_index)
 Called when a CPU wakes up (QEMU holds BQL; we additionally take m_mcips_mutex).
int64_t get_qemu_clock (void *)
 Returns the current simulation time in nanoseconds to QEMU's timer thread.
std::string get_mcips_status_json ()
 Returns a JSON string with the current state of all CPUs (for debugging). Reads without m_mcips_mutex so values may be slightly out of date.
Public Member Functions inherited from LibQemuPlugin
 LibQemuPlugin (const sc_core::sc_module_name &nm, qemu::LibQemu &inst)
void push_plugin_args (const std::string &plugin_path)
void shutdown_bridge ()
 Stop bridge dispatch and drain in-flight callbacks.
void * handle_as_userdata () const

Static Public Member Functions

static sc_core::sc_time cpu_delta_time (const vCPUTime *vcpu)
 Time represented by the in-flight instructions in delta_insn.
Static Public Member Functions inherited from LibQemuPlugin
template<typename Body>
static void dispatch_userdata (void *userdata, Body body)
 Run body on the live plugin instance, holding a refcount for the duration. No-op when the handle is null or alive==false.

Additional Inherited Members

Protected Attributes inherited from LibQemuPlugin
cci::cci_param< uint64_t > m_id
qemu::LibQemu & m_inst
PluginHandle * m_handle

Member Function Documentation

◆ compute_threshold()

sc_core::sc_time McipsPlugin::compute_threshold ( )
inline

Compute the time threshold that determines which CPUs may run.

The threshold is the lesser of (a) the end of the current SystemC window and (b) the slowest active CPU's time plus one quantum. m_mcips_mutex must be held.

Returns
The threshold, or SC_ZERO_TIME if there are no active CPUs.

◆ get_qemu_clock()

int64_t McipsPlugin::get_qemu_clock ( void * )
inline

Returns the current simulation time in nanoseconds to QEMU's timer thread.

This runs without holding m_mcips_mutex or BQL. When idle, it follows SystemC time and schedules idle ticks so timers keep working.

Note
delta_insn is read without m_mcips_mutex but it is updated atomically by QEMU, so reading it from another thread is safe. insn_per_second is set once during initialization and never changes at runtime, so reading it without the mutex is also safe.

◆ qemu_time_now()

sc_core::sc_time McipsPlugin::qemu_time_now ( )
inline

Current QEMU time (base + active CPU's in-flight delta).

When called under m_mcips_mutex, prefer the overload that takes an explicit active pointer to avoid a redundant atomic load.

◆ rebalance_and_sync()

void McipsPlugin::rebalance_and_sync ( vCPUTime * vcpu = nullptr)
inline

Rebalance CPUs and notify SystemC. m_mcips_mutex must be held.

Computes the current threshold, pauses vcpu if it is ahead, resumes any paused CPUs that are behind, and sends a new window. If vcpu is nullptr only resume + window are performed.

◆ receive_window_cb()

void McipsPlugin::receive_window_cb ( const sc_core::sc_sync_window< sc_core::sc_sync_policy_tlm_quantum >::window & sc_w)
inline

Called by SystemC when a new time window is ready.

This runs on the SystemC thread. It only takes the m_mcips_mutex. Saves the new window, detaches if no CPU is active, resumes the active CPU if the new window gives it room, then sends a new window back.

◆ select_active_vcpu()

vCPUTime * McipsPlugin::select_active_vcpu ( )
inline

Pick the first non-idle CPU and make it the active one.

Returns
The chosen CPU, or nullptr if every CPU is idle.

◆ set_systemc_window()

void McipsPlugin::set_systemc_window ( const sc_core::sc_sync_window< sc_core::sc_sync_policy_tlm_quantum >::window * custom_window = nullptr)
inline

Set the SystemC synchronization window.

Parameters
custom_windowOptional custom window to set; if nullptr, calculates window from current QEMU time

◆ set_vcpu_insn_per_second()

bool McipsPlugin::set_vcpu_insn_per_second ( unsigned int cpu_index,
uint64_t insn_per_second )
inline

Set the instructions per second for a specific vCPU.

Parameters
cpu_indexIndex of the vCPU
insn_per_secondInstructions per second value to set
Returns
true if successful, false if vCPU not found in scoreboard

◆ shutdown_cleanup()

void McipsPlugin::shutdown_cleanup ( )
inline

Shared shutdown logic used by both the destructor and end_of_simulation().

Stops the idle pump, marks shutdown, clears the active CPU, waits for any in-flight receive_window_cb to finish, and detaches the sync window. Safe to call more than once (subsequent calls are no-ops).

◆ vcpu_idle()

void McipsPlugin::vcpu_idle ( unsigned int cpu_index)
inline

Called when a CPU goes idle (QEMU holds BQL; we additionally take m_mcips_mutex).

RUNNING → IDLE: save the time used, pick a new active CPU or start the idle pump. Takes m_mcips_mutex to protect shared McipsPlugin state.

◆ vcpu_resume()

void McipsPlugin::vcpu_resume ( unsigned int cpu_index)
inline

Called when a CPU wakes up (QEMU holds BQL; we additionally take m_mcips_mutex).

IDLE → RUNNING: first CPU to wake re-attaches the sync window. PAUSED → RUNNING: only if the CPU is still within the allowed time range. RUNNING: nothing to do (plugin already set it to RUNNING earlier). Takes m_mcips_mutex to protect shared McipsPlugin state.


The documentation for this class was generated from the following file: