Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Skip to content
BoardRunner

Measure and improve performance

FastDyn provides several mechanisms that can reduce avoidable work: shared host-analysis sessions, prepared runtime artifacts, inline modifier operations, in-process model execution, incremental model builds, and parallel independent campaigns. Their value depends on the workload. Measure the complete experiment as well as the boundary being optimized.

This chapter describes a measurement workflow. It does not claim a universal speedup or report a new benchmark result.

Name the quantity first

QuantityWhat it answersWhat it does not establish
Host wall-clock durationHow long the experiment costs on this hostGuest-realistic execution timing
Preparation phase durationTime spent parsing, analyzing, building, and launchingSteady-state callback cost
Guest virtual timeTime visible to modeled firmware eventsPhysical CPU cycle accuracy
Explicit co-simulation budget/progressHow much scheduled guest work was admittedUniversal hardware instruction timing
Plant simulation timeHow far the physical scenario evolvedHost performance
Completed trials per secondCampaign throughput at the defined completion conditionEquivalent trial behavior by itself

The native virtual_icount() helper is a separate implementation detail. In the inspected main revision it returns FastDyn's internal counter, whose increment callback is enabled with twintrace; it may remain zero in ordinary runs. Do not substitute it for the co-simulation protocol's progress accounting or assume every trace's icount field is a universal retired-instruction count.

Start with phase timing

Add or adjust the existing profiling table in an experiment configuration:

[Run.profiling]
timing = true
timing_echo = true
python = false
perf = "off"
fmu = true

Run the configuration with a dedicated work directory, then summarize its event log:

fastdyn timing-summary out/experiment/fastdyn_timing.jsonl

The filename above assumes that the experiment used -o out/experiment. Timing records include phase names, durations, process identities, and status. The runner records preparation and execution phases; optional components contribute their own events. JSONL fields such as duration_s, time_monotonic_s, and time_wall_s are in seconds. The native guest-time API and scheduling fields ending in _ns use nanoseconds.

Phase intervals may nest or overlap across processes. Adding every reported duration can double-count work. Use the enclosing run interval for end-to-end cost and the component intervals to explain it. Report failures and early exits separately from successfully completed experiments.

Profile a specific remaining bottleneck

To inspect Python helper scripts and QEMU on a compatible Linux host, use:

[Run.profiling]
timing = true
python = true
perf = "record"
perf_frequency_hz = 99
fmu = true

The Python wrapper uses cProfile for supported script commands. QEMU profiling uses Linux perf when it is available and permitted. Profile outputs live under the run's profiles/ directory. Read the actual filenames reported by the run before opening them with pstats or perf report.

Profilers themselves affect cost. Use them to locate work, then repeat the measurement with the selected production instrumentation settings. Enabling Python profiling does not magically profile native code, and a perf request that cannot run is not a captured profile.

Compare equivalent work

Before timing two variants, establish that both reach the same completion condition with equivalent relevant behavior. A variant that returns sooner because it skipped a controller update or stopped on an error is not a speedup.

Keep the following fixed unless the experiment explicitly studies them: firmware and compiler build, QEMU and FastDyn revisions, machine configuration, model implementation, initial state, inputs, virtual-time policy, enabled observations, and termination rule. Keep host configuration and worker concurrency in the record as well.

Use separate trials for cold preparation and warm/incremental work. An FMU build or a first model compilation can dominate an initial run; a later run that reuses artifacts answers a different question. Measure both when both matter to users.

For each comparison, report the baseline and variant durations and the chosen summary across repeated successful runs. Define the arithmetic explicitly:

speedup = baseline_duration / variant_duration
overhead_percent = 100 * (variant_duration / baseline_duration - 1)

The comparison is meaningful only for the stated baseline. Comparing a full environment against a permissive stub also changes behavior and fidelity, which must be explained separately.

Where to look for improvement

Repeated analysis. Reuse the run-scoped host-analysis session rather than reopening the ELF and rebuilding the same indexes in each preprocessor. Keep feature-specific planning outside the shared fact services.

High-frequency callbacks. Count how often an event occurs and how much work its handler performs. A small cost in a polling loop may dominate a larger initialization operation. Inline device modeling covers the legacy manual finline path in a lab pinned to 5b8bf3d; the JIT patcher covers admitted register-only guest instruction fragments. Automatic MMIO optimization covers the experimental mmio_opt implementation reviewed at e44dca2edbc3b32cb1f2a48d3d0be203bd9b5576, including its separate correctness limits.

For the automatic path, retain discovery.json and installation.json along with phase timings. The native report distinguishes prepared and registered sites from fast and fallback execution counts. Registration alone does not establish that a site used the fast arm. The integration script compares its specific million-read workload with substitution enabled and disabled; it is a workload-specific demonstration, not a general equivalence or speed guarantee.

That comparison also changes observation volume: the fast arm bypasses ordinary device dispatch, per-access logging, and MMIO observer notification. Report the reduction in dispatch and logging work together, and decide whether the experiment requires those observations before comparing durations. Current code declines read substitutions when an observer is active and uses a live guard for observers registered after translation; the fast path without observers still skips ordinary per-access logging.

Saved MMIO PC and fixed-PC redirect hot paths. The current main revision passes a scalar saved_pc through the QEMU MMIO exporter instead of allocating a register-value buffer on every ordinary MMIO callback. A separate ARM32 optimization chains a strictly eligible r15 <- immediate modifier directly to another translated block. These optimize different vCPU paths and do not require automatic MMIO substitution. See Hot-path optimization contracts for the exact architecture contracts, disabling switch, test commands, and source-recorded measurements. Its 1.1169× ordinary-MMIO and 2.565× redirect-loop median ratios come from different bounded workloads, not general firmware throughput measurements.

Repeated translation. Supercache covers persistence and reuse of translated code in the separate backend that implements it. Distinguish a cold cache population run, a subsequent reuse run, and the complete experiment duration. Keep firmware, backend, plugin, machine, and instrumentation identities fixed; inspect cache compatibility and invalidation before attributing a timing difference to reuse.

Offline native-code optimization. The Supercache optimizer operates on a captured snapshot on the scopt branch. Measure pass-specific benefits against the same unoptimized warm cache: identity output is the no-change control, while accepted layout, cross-block, state-sync, and host-inline artifacts have distinct contracts. Keep capture, profiling, optimization, and validation costs separate from the final timed run. A published artifact or accepted inline site establishes a completed transformation; measured throughput still needs a successful matched workload and equivalent observations.

Firmware binary optimization. FirmBOLT applies an extended BOLT pipeline to the firmware ELF and checks which emitted bodies can be published under the selected firmware contract. Record whether the policy preserves modeled guest instruction count or explicitly relaxes it. Count installed bodies and changed bytes separately from timing results, and compare the same completed work and ordered observations. Its recorded Cortex-M publication checks and x86-64 application measurements exercise different targets; one cannot establish the other's performance.

Observation volume. Function traces, register logs, MMIO observations, and detailed QEMU logs can materially change throughput and output volume. Select the evidence the experiment needs. The current finite logging buffer and drain thread do not establish universal lossless observation under arbitrary load.

Physics and communication. Separate FMU stepping cost from adapter conversion, telemetry, viewers, and mission helpers. An embedded FMU removes a simulator-process boundary from that path, but does not eliminate physical-model computation.

Campaign scaling. Measure completed valid trials as worker count changes. Workers need isolated memory, files, sockets, and ports. More processes can contend for CPU, storage, or a shared external service rather than improve throughput.

A useful result record

Retain the exact experiment inputs, success criterion, timing log, optional profile, number of successful and failed trials, baseline definition, and raw durations. For a translation optimization, also retain functional equivalence checks and the fraction of accesses or instructions that actually used the optimized path.

This record connects an implementation choice to a reproducible result. It is also more useful to the next developer than an isolated claim that a particular run was fast.

Source guide