Skip to content

Commit 752a271

Browse files
committed
latency: detect realtime via 'realtime verify' instead of setuid heuristic
Query realtime status with 'realtime verify' (from #4132) rather than probing the setuid bit. latency-histogram asks the realtime layer directly; latency-test relies on the existing "POSIX non-realtime" note.
1 parent 66dab82 commit 752a271

2 files changed

Lines changed: 9 additions & 42 deletions

File tree

scripts/latency-histogram

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,15 @@ 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+
# Ask the realtime layer whether realtime is actually available, via
116+
# 'realtime verify' (exits 0 when realtime is up, non-zero otherwise,
117+
# usually a missing 'sudo make setuid' or 'sudo make setcap').
118+
if {[catch {exec linuxcnc_var REALTIME} rt]} return ;# cannot locate, stay quiet
119+
if {![catch {exec $rt verify 2>@1}]} return ;# realtime available
120+
set msg "Warning: realtime is not available."
121+
append msg "\nThreads get no SCHED_FIFO priority or locked memory,"
129122
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/."
123+
append msg "\nOn a run-in-place build, run 'sudo make setuid' (or 'sudo make setcap') in src/."
131124
puts stderr $msg
132125
if {$::LH(use_x)} {
133126
package require Tk
@@ -649,6 +642,7 @@ proc start_collection {} {
649642
}
650643
}
651644
hal start
645+
check_rt_privileges
652646
if {!$::LH(legacy)} {
653647
# Attach the Tcl hal_stream binding (added in halsh.c) to each
654648
# thread's latencybinstream FIFO. The handle stays open for the
@@ -997,7 +991,6 @@ proc windowToFile { win } {
997991
if ![info exists ::LH(start)] {
998992
set_defaults
999993
config
1000-
check_rt_privileges
1001994
progress "Loading packages"
1002995
load_packages
1003996
signal trap SIGINT finish

scripts/latency-test

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,6 @@ 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.
22-
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*) ;;
26-
*) return 0 ;;
27-
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
41-
}
42-
4319
parse_time () {
4420
case $1 in
4521
-) echo "0" ;;
@@ -194,6 +170,4 @@ L=\$(($SIGNALS
194170
echo \$L > "$HOME"/.latency
195171
EOF
196172

197-
check_rt_privileges
198-
199173
halrun lat.hal

0 commit comments

Comments
 (0)