Skip to content

rtapi: add opt-in virtual time for accelerated uspace simulation - #4893

Open
grenzland64 wants to merge 1 commit into
LinuxCNC:masterfrom
grenzland64:virtual-time
Open

grenzland64 wants to merge 1 commit into
LinuxCNC:masterfrom
grenzland64:virtual-time

Conversation

@grenzland64

@grenzland64 grenzland64 commented Nov 23, 2026 •

Copy link
Copy Markdown

Follow-up to the discussion in #4863. This is the small in-tree part I proposed there: an opt-in switch for uspace rtapi_app that lets a simulation run faster than real time. Everything specific to my use case (trace capture, gating of task and I/O) stays out of tree.

What it does

With RTAPI_VIRTUAL_TIME=1 in the environment of rtapi_app:

  • the POSIX non-realtime backend is selected, regardless of the kernel,
  • the realtime thread never sleeps between cycles,
  • rtapi_get_time() returns the thread start time plus exactly one period per completed cycle, so components see a jitter-free clock,
  • rtapi_app drops root and all capabilities at startup.

Without the variable nothing changes; all new code paths are behind the check.

RTAPI_VIRTUAL_TIME=1 halrun setup.hal

Limits

  • Single realtime thread only. Starting a second thread fails with -EBUSY. Several threads would need a scheduler that orders them in virtual time; I left that out to keep the change small.
  • Simulation only. Because root and capabilities are dropped, drivers that need privileged hardware access fail to load. This does not catch drivers that work without privileges (for example hm2_eth over UDP or gpiod). If you would prefer an explicit refusal, I am happy to add one; suggestions for the right place are welcome.
  • Only the realtime side is accelerated. Non-realtime programs (task, I/O, UIs) still run on the wall clock, so a complete LinuxCNC session needs additional coordination, which is what I keep out of tree.

Testing

  • New test tests/virtual-time: every cycle sees exactly one period on timedelta, more than 10 s of virtual time pass within 1 s of real time, and a second thread is refused.
  • scripts/runtests on tests/virtual-time, tests/threads.*, tests/rtapi*, tests/hal*, tests/uspace: 35 of 36 pass. The one failure is tests/halrmt, which needs nc; it was not installed in my build container, so I have not confirmed the cause.
  • Built run-in-place on Debian trixie (uspace, documentation build disabled), on top of 65f7467.
  • Checked by hand that with the switch rtapi_app runs with the real uid and empty capability sets, and without it behaves as before.

Not tested: RT-PREEMPT, Xenomai and RTAI hosts (the switch is meant to bypass them, but I could only run on a non-realtime kernel), and the documentation build for the new ENVIRONMENT section in rtapi_app.1.

RTAPI_VIRTUAL_TIME=1 selects the POSIX non-realtime backend, skips the
period sleep and makes rtapi_get_time() advance by exactly one period
per cycle. It is off by default and limited to a single realtime
thread. rtapi_app drops root and all capabilities in this mode, so
hardware drivers that need privileged access cannot be loaded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant