Skip to content

Commit 228e6ef

Browse files
committed
latency: detect realtime via halcmd getrt instead of setuid heuristic
Replace the bash/tcl setuid-bit/getcap probing with a single 'halcmd getrt' query (hdiethelm's PR), the authoritative rtapi_is_realtime() check. Warn only on "No realtime available"; rtai/non-uspace builds and older halcmd without getrt stay silent. LINUXCNC_NO_RT_WARN suppresses on dev boxes.
1 parent ecc6b29 commit 228e6ef

2 files changed

Lines changed: 18 additions & 34 deletions

File tree

scripts/latency-histogram

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,16 @@ proc which_exe {name} {
112112
} ;# which_exe
113113

114114
proc check_rt_privileges {} {
115-
# Without 'sudo make setuid' (or 'sudo make setcap') rtapi_app runs
116-
# unprivileged: realtime threads get no SCHED_FIFO and no locked memory, so
117-
# the latency readings are wildly inflated. Warn rather than mislead.
118-
# Only meaningful on an RT-capable kernel; stay quiet on non-RT (e.g. dev).
119-
set rt 0
120-
if {![catch {exec uname -v} kv] && [string match *PREEMPT_RT* $kv]} {set rt 1}
121-
if {[string first rtai [string tolower $::tcl_platform(osVersion)]] >= 0} {set rt 1}
122-
if {!$rt} return
123-
if {![catch {exec id -u} uid] && $uid == 0} return ;# root has every privilege
124-
if {[catch {which_exe rtapi_app} rtapi]} return ;# cannot locate, stay quiet
125-
if {![catch {file attributes $rtapi -permissions} mode] && ($mode & 04000)} return ;# setuid root
126-
if {![catch {exec getcap $rtapi} caps] && [string match *cap_sys_nice* $caps]} return ;# file caps
127-
set msg "Warning: rtapi_app is not setuid root and has no realtime capabilities."
128-
append msg "\nRealtime threads get no SCHED_FIFO priority or locked memory,"
115+
# Warn if rtapi reports no realtime ('halcmd getrt'), usually a missing
116+
# 'sudo make setuid'. LINUXCNC_NO_RT_WARN suppresses it on dev boxes.
117+
if {[info exists ::env(LINUXCNC_NO_RT_WARN)]} return
118+
set out ""
119+
catch {exec $::LH(prog,halcmd) getrt 2>@1} out
120+
if {![string match {*No realtime available*} $out]} return
121+
set msg "Warning: realtime is not available."
122+
append msg "\nThreads get no SCHED_FIFO priority or locked memory,"
129123
append msg "\nso the latency shown will be far worse than reality."
130-
append msg "\nRun 'sudo make setuid' (or 'sudo make setcap') in src/."
124+
append msg "\nOn a run-in-place build, run 'sudo make setuid' (or 'sudo make setcap') in src/."
131125
puts stderr $msg
132126
if {$::LH(use_x)} {
133127
package require Tk

scripts/latency-test

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,18 @@ kversion=$(uname -v)
1616
calc() { awk "BEGIN { print ($1); }" < /dev/null; }
1717
icalc() { awk "BEGIN { printf \"%.0f\n\", ($1); }" < /dev/null; }
1818

19-
# Without 'sudo make setuid' (or 'sudo make setcap') rtapi_app runs
20-
# unprivileged: realtime threads get no SCHED_FIFO and no locked memory, so the
21-
# latency readings are wildly inflated. Warn rather than mislead.
19+
# Warn if rtapi reports no realtime ('halcmd getrt'), usually a missing
20+
# 'sudo make setuid'. LINUXCNC_NO_RT_WARN suppresses it on dev boxes.
2221
check_rt_privileges () {
23-
# only meaningful on an RT-capable kernel; stay quiet on non-RT (e.g. dev)
24-
case "$(uname -v) $(uname -r)" in
25-
*PREEMPT_RT*|*rtai*) ;;
22+
[ -n "$LINUXCNC_NO_RT_WARN" ] && return 0
23+
case $(halcmd getrt 2>&1) in
24+
*"No realtime available"*) ;;
2625
*) return 0 ;;
2726
esac
28-
[ "$(id -u)" = 0 ] && return 0 # root has every privilege
29-
rtapi_app=$(command -v rtapi_app) || return 0
30-
[ -n "$rtapi_app" ] || return 0
31-
[ -u "$rtapi_app" ] && return 0 # setuid root
32-
if command -v getcap >/dev/null 2>&1; then
33-
case $(getcap "$rtapi_app" 2>/dev/null) in
34-
*cap_sys_nice*) return 0 ;; # file capabilities
35-
esac
36-
fi
37-
echo "Warning: rtapi_app is not setuid root and has no realtime capabilities." >&2
38-
echo " Realtime threads get no SCHED_FIFO priority or locked memory," >&2
39-
echo " so the latency shown will be far worse than reality." >&2
40-
echo " Run 'sudo make setuid' (or 'sudo make setcap') in src/." >&2
27+
echo "Warning: realtime is not available: threads get no SCHED_FIFO priority" >&2
28+
echo " or locked memory, so the latency shown will be far worse than" >&2
29+
echo " reality. On a run-in-place build, run 'sudo make setuid'" >&2
30+
echo " (or 'sudo make setcap') in src/." >&2
4131
}
4232

4333
parse_time () {

0 commit comments

Comments
 (0)