Skip to content

latency-test, latency-histogram: warn when rtapi_app lacks RT privileges#4107

Open
grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:fix/latency-setuid-warning-4044
Open

latency-test, latency-histogram: warn when rtapi_app lacks RT privileges#4107
grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:fix/latency-setuid-warning-4044

Conversation

@grandixximo
Copy link
Copy Markdown
Contributor

@grandixximo grandixximo commented Jun 2, 2026

What

Both latency tools now warn, for a non-root user, when rtapi_app is neither setuid root nor carrying the cap_sys_nice file capability. In that state the realtime threads cannot get SCHED_FIFO scheduling or locked memory, so the reported latency is wildly inflated and unrepresentative.

Why

In #4044 a run-in-place build was used without sudo make setuid. rtapi_app ran unprivileged, the latency numbers blew up, and this was initially mistaken for a code regression. It was not; the setuid/setcap step had simply been skipped. A plain warning would have saved the back-and-forth. @rodw-au suggested a geteuid()/setuid check in the issue thread.

How

A small check runs before the test starts:

  1. root: silent (already has every privilege).
  2. locate rtapi_app; if not found, stay silent.
  3. setuid-root bit present (sudo make setuid): silent.
  4. cap_sys_nice file capability present (sudo make setcap): silent.
  5. otherwise: print a warning that the numbers may be skewed and point at the missing setuid/setcap step.

A pure euid check was deliberately avoided: a normal deb install runs the scripts as an unprivileged user yet works fine via setuid-root rtapi_app, so euid alone would false-warn on every correct install. The real signal is the privilege state of rtapi_app itself.

latency-test (bash) prints to stderr; latency-histogram (tcl) prints to stderr and, in GUI mode, also shows a tk_messageBox.

Closes #4044

Without 'sudo make setuid' (or 'sudo make setcap') rtapi_app runs
unprivileged: no SCHED_FIFO, no locked memory, so latency readings are
wildly inflated and easy to mistake for a code regression. Warn, for a
non-root user, when rtapi_app is neither setuid root nor carries the
cap_sys_nice capability.

Closes LinuxCNC#4044
@grandixximo grandixximo force-pushed the fix/latency-setuid-warning-4044 branch from 77c1e3e to 8274d2d Compare June 2, 2026 13:19
@BsAtHome
Copy link
Copy Markdown
Contributor

BsAtHome commented Jun 2, 2026

These tests are moot when you run on a non-RT kernel (like I do in dev). I'm not sure the noise is really necessary in that case.

Only warn under PREEMPT_RT or RTAI; on a non-RT kernel the privileges
do not matter, so the check would be noise.
@grandixximo
Copy link
Copy Markdown
Contributor Author

silenced on non-rt

@rodw-au
Copy link
Copy Markdown
Contributor

rodw-au commented Jun 2, 2026

Great. Every little bit helps. Reduces user frustration and more importantly less developer time wasted on spurious issues.

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.

Latency test discrepancy after ethercat feature adding

3 participants