Skip to content

Commit a3df81c

Browse files
committed
latency: detect realtime via halcmd getrt instead of setuid heuristic
Query realtime status with 'halcmd getrt' (hdiethelm's PR) rather than probing the setuid bit. latency-histogram asks inside its own running session, so no stray HAL segment is created. latency-test drops its check and relies on the existing "POSIX non-realtime" note.
1 parent ecc6b29 commit a3df81c

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+
# Query the running session (realtime already up) via 'halcmd getrt'.
116+
# Warn on "No realtime available", usually a missing 'sudo make setuid'.
117+
set out ""
118+
catch {exec $::LH(prog,halcmd) getrt 2>@1} out
119+
if {![string match {*No realtime available*} $out]} return
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
@@ -647,6 +640,7 @@ proc start_collection {} {
647640
}
648641
}
649642
hal start
643+
check_rt_privileges
650644
if {!$::LH(legacy)} {
651645
# Attach the Tcl hal_stream binding (added in halsh.c) to each
652646
# thread's latencybinstream FIFO. The handle stays open for the
@@ -969,7 +963,6 @@ proc windowToFile { win } {
969963
if ![info exists ::LH(start)] {
970964
set_defaults
971965
config
972-
check_rt_privileges
973966
progress "Loading packages"
974967
load_packages
975968
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)