45 Memory Tracing and Timing 47 Connecting to the External World
Model Builder User’s Guide  /  VII Extending Simics  / 

46 Processor Stalling and Disabling

46.1 Overview

Device models and other simulation components sometimes need to prevent a processor from executing instructions for a number of cycles. Typical reasons include:

Simics has historically offered several stalling mechanisms (SIM_stall_cycle, the stall interface, and the timing_model return value) that were not unified and lacked visibility into why a processor was stalled. The client_stall interface addresses these gaps by providing a single interface with per-client tracking, cancellation, reason strings, and classification of stalls.

46.2 The client_stall Interface

The client_stall interface is defined in simics/model-iface/client-stall-interface.h and allows a device model to stall a processor for a given number of cycles:

handle = cpu.iface.client_stall.stall(
    client_obj,              # requesting object (or None)
    cycles,                  # number of cycles to stall
    "reason string",         # human-readable reason
    Sim_Stall_Model          # or Sim_Stall_Simulation_Performance
)

Python interface methods are bound to cpu, so the processor argument from the C interface signature is supplied automatically. The first Python argument is therefore the requesting client object. In C, pass the processor explicitly as shown in the C example below.

The method returns a stall_handle_t that can be used to cancel the stall before it expires:

cpu.iface.client_stall.cancel(handle)

To query the currently active stall time on the processor, use stall_cycles():

active = cpu.iface.client_stall.stall_cycles()

When multiple stalls are active simultaneously, the processor stalls until the longest one expires.

Internally, each active stall is represented by a cycle event. The processor is held by an indefinite internal stall until the last stall event completes or is cancelled. The stall_cycles() method still reports the actual longest remaining stall rather than that internal value.

46.2.1 When a Stall Takes Effect

A simulated instruction is atomic with respect to client stalls: a stall never interrupts an instruction that is already executing. A request made inside an instruction is recorded immediately, but starts only after that instruction has completed.

Thus, stalls always start at an instruction boundary. A request made between boundaries is deferred to the next boundary; this case can occur with the non-unity step rates described in the next section. A stall cancelled before reaching its boundary does not take effect.

46.2.2 Interaction with the Step Rate

The processor step rate specifies how many steps execute per cycle when the processor is not stalled. Each instruction completes according to that rate; client-stall cycles are inserted between instructions, never into the current instruction. A client stall is specified in cycles, not steps, and its duration is not multiplied or divided by the step rate. During those cycles, simulated cycle time advances but the processor executes no steps.

With a non-unity step rate, cycle counts measured around a stall can therefore include more than the requested stall duration. They may also include cycles needed to reach the next instruction boundary and the normal cycle cost of any steps included in the measurement. For example, at one step per 128 cycles, a 100-cycle stall still adds 100 cycles; it does not add 12,800 cycles. Any remaining cycles needed to reach a boundary are separate from those 100 stall cycles.

For more information about configuring the step rate, see Changing the Step Rate.

46.2.3 Model Stalls vs. Simulation Stalls

Each stall carries a stall_flags_t that classifies its purpose:

46.2.4 Predefined Stall Reasons

The client-stall-interface.h header defines C macros for common stall reasons. Using these names avoids spelling variations and makes related entries use the same cpu.stall.histogram bucket. They do not otherwise change stall behavior, and custom reason strings are also allowed.

C macroReason string
SIM_STALL_REASON_CACHE_MISSstall-cache-miss
SIM_STALL_REASON_MEMORY_ACCESSstall-memory-access
SIM_STALL_REASON_IO_OPERATIONstall-io-operation
SIM_STALL_REASON_INTERCONNECTstall-interconnect
SIM_STALL_REASON_DEVICE_ACCESSstall-device-access
SIM_STALL_REASON_DMA_TRANSFERstall-dma-transfer
SIM_STALL_REASON_SYNCHRONIZATIONstall-synchronization
SIM_STALL_REASON_PIPELINE_HAZARDstall-pipeline-hazard
SIM_STALL_REASON_SIM_PERFORMANCEstall-simulation-performance
SIM_STALL_REASON_MULTI_CYCLE_OPERATIONstall-multi-cycle-operation

These macros are provided for C and C++ models. Python callers pass the corresponding reason string directly.

46.2.5 C Example

#include <simics/model-iface/client-stall-interface.h>

static void
my_device_access(conf_object_t *obj, conf_object_t *cpu)
{
        /* Cache this interface in production code when cpu is stable. */
        const client_stall_interface_t *iface =
                SIM_C_GET_INTERFACE(cpu, client_stall);

        stall_handle_t h = iface->stall(
                cpu,            /* processor */
                obj,            /* requesting client */
                200,            /* cycles */
                SIM_STALL_REASON_DEVICE_ACCESS,
                Sim_Stall_Model);

        /* ... later, if the stall should be cancelled early: */
        iface->cancel(cpu, h);
}

46.2.6 Python Example

import simics

cpu = conf.cpu0
dev = conf.dev0
iface = cpu.iface.client_stall

# Stall the processor for 500 cycles (model-correctness stall)
handle = iface.stall(
    dev, 500, "stall-device-access", simics.Sim_Stall_Model)

# Cancel the stall early if the reset is deasserted
iface.cancel(handle)

46.3 The processor_disable Interface

For cases where a processor must stop executing instructions indefinitely, such as while reset is asserted or during a debugger-initiated halt, the processor_disable interface builds on top of client_stall:

handle = cpu.iface.processor_disable.disable(
  reset_controller, "disabled-by-reset-asserted")

# Re-enable after reset is deasserted.
cpu.iface.processor_disable.enable(handle)

Disabled processors continue to advance in simulated cycles but execute no instructions. The disable and its reason are visible in the list-active-stalls command and in the probes together with regular stalls.

46.4 Predefined Disable Reasons

The processor_disable interface recognises a set of predefined reason strings. When one of these strings is passed to disable(), the interface maps it to the corresponding internal disable flag, which is the same flag controlled by Simics CLI commands such as disable and enable on a processor. This means a device model can programmatically disable and enable a processor in exactly the same way as a user would from the command line.

The processor-disable-interface.h header defines C macros for these reason strings:

C macroReason stringDescription
SIM_DISABLE_REASON_USERdisabled-by-userUser-initiated disable (disable CLI command)
SIM_DISABLE_REASON_RESET_ASSERTEDdisabled-by-reset-assertedProcessor held in reset
SIM_DISABLE_REASON_EXTERNAL_DEVICEdisabled-by-external-deviceDisabled by an external device (plug/unplug)
SIM_DISABLE_REASON_THREAD_MANAGEMENTdisabled-by-thread-managementThread management (plug/unplug)
SIM_DISABLE_REASON_DEBUGGERdisabled-by-debuggerDebugger-initiated halt
SIM_DISABLE_REASON_MICROCODEdisabled-by-microcodeMicrocode / BIOS guard
SIM_DISABLE_REASON_NON_ARCHdisabled-by-non-archNon-architectural disable
SIM_DISABLE_REASON_WAITING_INSTRUCTIONdisabled-by-waiting-instructionWaiting for instruction completion
SIM_DISABLE_REASON_POWERdisabled-by-powerPower controller unit
SIM_DISABLE_REASON_MICROCODE_INTEGRATIONdisabled-by-microcode-integrationMicrocode integration block

C and C++ models should use these macros instead of repeating their string values. Python callers pass the corresponding reason string directly.

For example, to disable a processor the same way the CLI disable command does:

handle = cpu.iface.processor_disable.disable(
    None, "disabled-by-user")

# Later, re-enable (equivalent to the CLI 'enable' command):
cpu.iface.processor_disable.enable(handle)

A reason string that does not match any predefined name is treated as a custom reason.

46.5 Inspecting Active Stalls

The list-active-stalls command shows all stalls currently active on processors in the simulation:

simics> list-active-stalls
┌────┬──────┬──────┬─────────┬────────────┬──────────┐
│CPU │Handle│Client│Remaining│   Reason   │  Flags   │
├────┼──────┼──────┼─────────┼────────────┼──────────┤
│cpu0│n/a   │n/a   │     1000│legacy stall│n/a       │
│cpu0│2     │cpu0  │      600│cache-miss  │model     │
│cpu0│3     │cpu0  │      400│profiler    │simulation│
└────┴──────┴──────┴─────────┴────────────┴──────────┘

Each row shows:

Legacy stalls posted via the old stall interface or SIM_stall_cycle also appear in this listing, making it a single place to inspect all sources of stalling.

The active_stalls attribute used by this command contains the processor’s checkpointed client-stall state.

46.6 Stall Probes

The probe framework provides counters that track how many cycles each processor has spent stalled or disabled. These are useful for performance analysis and for debugging unexpected timing behavior. Unlike list-active-stalls, which is a snapshot of currently active requests, the probes retain history for completed stalls while subscribed.

46.6.1 Enabling and Reading Probes

simics> enable-probes
simics> probes.subscribe cpu.stall.cycles
simics> probes.subscribe cpu.stall.histogram

After running the simulation:

simics> probes.read cpu0:cpu.stall.cycles
4200

simics> probes.read cpu0:cpu.stall.histogram
cache-miss-L2     3200   76%
power-gated       1000   24%

46.6.2 Available Probe Kinds

Probe kindTypeDescription
cpu.stall.cyclesintegerTotal stall and disabled cycles on one processor
cpu.stall.histogramhistogramBreakdown of cycles by reason string
cell.stall.cyclesintegerAggregated stall cycles across a cell
cell.stall.histogramhistogramAggregated histogram across a cell
sim.stall.cyclesintegerTotal stall cycles across the entire simulation
sim.stall.histogramhistogramGlobal histogram across all processors

The probes require a subscription. Completed stalls are recorded only while at least one stall probe is subscribed. An ongoing stall is calculated from its activation time, so subscribing while it is active includes cycles elapsed before the subscription. Use probes.subscribe cpu.stall.cycles (or the specific probe kind) to activate them. The cpu-level probes automatically aggregate into the cell and sim variants.

The cycles probe counts the effective time for which the processor is stalled, so overlapping stalls count only once. The histogram attributes elapsed time to each reason independently; its buckets can therefore sum to more than the cycles probe when stalls overlap.

46.6.3 Reading Probes from Python

import probes

# Get the probe for a specific CPU
p = probes.get_probe_by_object("cpu.stall.histogram", conf.cpu0)
p.subscribe()

# ... run simulation ...

hist = p.value()  # returns [["reason-A", 500], ["reason-B", 300], ...]
reasons = {r: c for (r, c) in hist}

46.6.4 Reading the Global Histogram via CLI

run_command("probes.subscribe sim.stall.histogram")
output = run_command(
    "probes.read probe=sim:sim.stall.histogram -raw-values")
# output is [["reason-A", 500], ["reason-B", 300], ...]

46.7 Choosing the Right Stalling Mechanism

MechanismUse case
client_stall with Sim_Stall_ModelDevice must prevent execution (reset, clock gate)
client_stall with Sim_Stall_Simulation_PerformanceTiming realism (cache latency, I/O delays)
processor_disableIndefinite disable (reset, debugger halt)

The client_stall interface is preferred over the legacy SIM_stall_cycle and stall interface for new code. It provides reason tracking, cancellation, and integration with the stall probes.

45 Memory Tracing and Timing 47 Connecting to the External World