Repository navigation
Add an Opt-In Virtual-Time Mode for Accelerated Userspace Simulation #4863
Replies: 1 comment 7 replies
|
NML is strictly non-RT and only necessary to feed the top level data and has a top-level view of the status. The name RTAPI is an internal thing (at compile time). Task's cycle time can be decreased as well. Not sure whether there is any wall time dependency here. The trajectory planner is still in RT where the thread period is used. When the trajectory planner eventually moves to non-RT, then things will get slightly different, but the moves then fed into RT are still calculated on basis of the RT thread's period and not task's wall time. The non-RT/RT interface between task and the motion controller is a one-deep queue, which should remain that way or you can cause a swath of synchronization problems. You would loose correlation between command/answer/status as the queue was never intended to queue multiple commands and only serve as a non-RT <=> RT interface. |
Uh oh!
There was an error while loading. Please reload this page.
Please consider adding a supported virtual-time mode for isolated LinuxCNC userspace simulations. It would allow a simulation to advance through complete LinuxCNC cycles without waiting for each cycle’s real-time period.
The motion planner and configured machine-time period would remain unchanged. The mode would change how quickly computation proceeds in wall-clock time—not the simulated motion or its timing.
A local proof of concept was tested with LinuxCNC 2.10.0~pre2. In one representative 2.10 run, approximately 890 seconds of simulated machine time were computed in 12.9 seconds of wall time, about 69× faster than real time.
Problem
A userspace simulation normally waits for real time to pass between servo cycles. Removing sleeps in an external runner is not sufficient to accelerate it correctly:
Servo, task, and I/O cycles must stay coordinated and execute in the correct order.
RTAPI/NML time must advance consistently with the configured simulation period.
Motion-command acknowledgements may require additional planner cycles.
Trace sampling must not lose data when simulation runs faster than its consumer.
Watchdogs must still use real wall-clock time so they can detect a stalled simulation.
Without coordination inside LinuxCNC, accelerating only the caller can change planner behavior, produce incomplete traces, or leave simulation time inconsistent.
Proposed Architecture
Use an explicit virtual tick to coordinate the LinuxCNC execution roles. Each tick represents one nominal servo period.
`sequenceDiagram
participant Runner as Simulation runner
participant Clock as Virtual clock
participant Servo as Servo / HAL thread
participant Task as Task work
participant IO as I/O work
participant Sampler as Trace sampler
participant Watchdog as Real-time watchdog
If the task is waiting for a motion-command acknowledgement, the virtual-time mechanism should advance a complete servo cycle before checking that acknowledgement. It should not service only the command while skipping the rest of the servo work.
RTAPI/NML simulation time should advance from the virtual tick count and nominal period. Watchdogs and external timeouts should continue to use a real monotonic clock.
Proposed Changes
The proof of concept required coordinated changes in several parts of LinuxCNC. An upstream implementation could use different mechanisms, but it should provide equivalent behavior:
Servo/HAL loop: Add a virtual-tick gate before the full servo function list. Preserve function ordering and the configured thread-period argument.
Userspace RTAPI timing: When virtual time is active, bypass the real-period wait and derive simulation time from the virtual tick and nominal period. Preserve existing behavior when virtual time is inactive.
Task loop: Replace the real-time wait with a task gate in virtual mode, while preserving task iterations required to make progress.
I/O work: Coordinate I/O waits with the same tick protocol. If a LinuxCNC version runs I/O in the task process rather than a separate role, the implementation should account for that without duplicating or omitting work.
Motion acknowledgements: Ensure that waiting for a motion-command acknowledgement advances complete planner/servo cycles before checking for completion.
Time helpers: Make simulation-facing time functions, such as elapsed-time queries, use virtual time while the mode is active.
Trace sampler: Apply backpressure when its FIFO is full instead of dropping samples. Ensure the consumer can drain buffered samples during shutdown and retain sufficient numeric precision in trace output.
Watchdogs and shutdown: Keep watchdogs on real monotonic time. Make virtual waits periodically check for aborts so a stalled simulation can be stopped.
Activation and failure handling: Make virtual time explicitly opt-in and limited to supported simulation workflows. If activation fails or a version is unsupported, report an error rather than silently falling back to real-time operation.
Scope and Safety Boundaries
The initial use case is isolated userspace simulation, not hardware operation. Virtual time must not be presented as a way to run LinuxCNC against real machinery faster than real time or as a real-time capability.
The proof of concept covers a restricted motion workflow. It does not establish support for all LinuxCNC behavior, including real homing, spindle operation, tool changes, dwell semantics, arbitrary machine I/O, or every controller feature. The supported program and component scope should be documented explicitly.
The virtual clock should change the wall-clock delay between calculations, not the planner, requested machine-time period, or intended motion.
Acceptance Criteria
Suggested Tests
All reactions