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.
client_stall InterfaceThe 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.
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.
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.
Each stall carries a stall_flags_t that classifies its purpose:
Sim_Stall_Model
The stall is required for model correctness. For example, a device that
must prevent the processor from executing during a hardware reset must
use this flag. Model stalls are never ignored.
Sim_Stall_Simulation_Performance
The stall improves simulation quality by pretending an operation takes
time, allowing other clocks to progress. For example, a device model can
stall after a polling access so that a target polling loop does not execute
many iterations while waiting for the device. These stalls can be skipped
per CPU by setting the ignore_simulation_performance_stalls attribute to
true, which is useful when timing is not important.
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 macro | Reason string |
|---|---|
SIM_STALL_REASON_CACHE_MISS | stall-cache-miss |
SIM_STALL_REASON_MEMORY_ACCESS | stall-memory-access |
SIM_STALL_REASON_IO_OPERATION | stall-io-operation |
SIM_STALL_REASON_INTERCONNECT | stall-interconnect |
SIM_STALL_REASON_DEVICE_ACCESS | stall-device-access |
SIM_STALL_REASON_DMA_TRANSFER | stall-dma-transfer |
SIM_STALL_REASON_SYNCHRONIZATION | stall-synchronization |
SIM_STALL_REASON_PIPELINE_HAZARD | stall-pipeline-hazard |
SIM_STALL_REASON_SIM_PERFORMANCE | stall-simulation-performance |
SIM_STALL_REASON_MULTI_CYCLE_OPERATION | stall-multi-cycle-operation |
These macros are provided for C and C++ models. Python callers pass the corresponding reason string directly.
#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);
}
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)
processor_disable InterfaceFor 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.
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 macro | Reason string | Description |
|---|---|---|
SIM_DISABLE_REASON_USER | disabled-by-user | User-initiated disable (disable CLI command) |
SIM_DISABLE_REASON_RESET_ASSERTED | disabled-by-reset-asserted | Processor held in reset |
SIM_DISABLE_REASON_EXTERNAL_DEVICE | disabled-by-external-device | Disabled by an external device (plug/unplug) |
SIM_DISABLE_REASON_THREAD_MANAGEMENT | disabled-by-thread-management | Thread management (plug/unplug) |
SIM_DISABLE_REASON_DEBUGGER | disabled-by-debugger | Debugger-initiated halt |
SIM_DISABLE_REASON_MICROCODE | disabled-by-microcode | Microcode / BIOS guard |
SIM_DISABLE_REASON_NON_ARCH | disabled-by-non-arch | Non-architectural disable |
SIM_DISABLE_REASON_WAITING_INSTRUCTION | disabled-by-waiting-instruction | Waiting for instruction completion |
SIM_DISABLE_REASON_POWER | disabled-by-power | Power controller unit |
SIM_DISABLE_REASON_MICROCODE_INTEGRATION | disabled-by-microcode-integration | Microcode 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.
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:
stall_handle_t value (or n/a for legacy stalls).n/a for legacy/unspecified)indefinitely for disabled stalls.stall().model or simulation.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.
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.
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%
| Probe kind | Type | Description |
|---|---|---|
cpu.stall.cycles | integer | Total stall and disabled cycles on one processor |
cpu.stall.histogram | histogram | Breakdown of cycles by reason string |
cell.stall.cycles | integer | Aggregated stall cycles across a cell |
cell.stall.histogram | histogram | Aggregated histogram across a cell |
sim.stall.cycles | integer | Total stall cycles across the entire simulation |
sim.stall.histogram | histogram | Global 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.
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}
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], ...]
| Mechanism | Use case |
|---|---|
client_stall with Sim_Stall_Model | Device must prevent execution (reset, clock gate) |
client_stall with Sim_Stall_Simulation_Performance | Timing realism (cache latency, I/O delays) |
processor_disable | Indefinite 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.