Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions scripts/latency-histogram
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ proc which_exe {name} {
return -code error "$name: executable not found"
} ;# which_exe

proc check_rt_privileges {} {
# Without 'sudo make setuid' (or 'sudo make setcap') rtapi_app runs
# unprivileged: realtime threads get no SCHED_FIFO and no locked memory, so
# the latency readings are wildly inflated. Warn rather than mislead.
# Only meaningful on an RT-capable kernel; stay quiet on non-RT (e.g. dev).
set rt 0
if {![catch {exec uname -v} kv] && [string match *PREEMPT_RT* $kv]} {set rt 1}
if {[string first rtai [string tolower $::tcl_platform(osVersion)]] >= 0} {set rt 1}
if {!$rt} return
if {![catch {exec id -u} uid] && $uid == 0} return ;# root has every privilege
if {[catch {which_exe rtapi_app} rtapi]} return ;# cannot locate, stay quiet
if {![catch {file attributes $rtapi -permissions} mode] && ($mode & 04000)} return ;# setuid root
if {![catch {exec getcap $rtapi} caps] && [string match *cap_sys_nice* $caps]} return ;# file caps
set msg "Warning: rtapi_app is not setuid root and has no realtime capabilities."
append msg "\nRealtime threads get no SCHED_FIFO priority or locked memory,"
append msg "\nso the latency shown will be far worse than reality."
append msg "\nRun 'sudo make setuid' (or 'sudo make setcap') in src/."
puts stderr $msg
if {$::LH(use_x)} {
package require Tk
tk_messageBox -parent . -icon warning -type ok \
-title "Latency Warning" -message $msg
}
} ;# check_rt_privileges

proc program_check {plist} {
foreach prog $plist {
if [catch {
Expand Down Expand Up @@ -944,6 +969,7 @@ proc windowToFile { win } {
if ![info exists ::LH(start)] {
set_defaults
config
check_rt_privileges
progress "Loading packages"
load_packages
signal trap SIGINT finish
Expand Down
26 changes: 26 additions & 0 deletions scripts/latency-test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ kversion=$(uname -v)
calc() { awk "BEGIN { print ($1); }" < /dev/null; }
icalc() { awk "BEGIN { printf \"%.0f\n\", ($1); }" < /dev/null; }

# Without 'sudo make setuid' (or 'sudo make setcap') rtapi_app runs
# unprivileged: realtime threads get no SCHED_FIFO and no locked memory, so the
# latency readings are wildly inflated. Warn rather than mislead.
check_rt_privileges () {
# only meaningful on an RT-capable kernel; stay quiet on non-RT (e.g. dev)
case "$(uname -v) $(uname -r)" in
*PREEMPT_RT*|*rtai*) ;;
*) return 0 ;;
esac
[ "$(id -u)" = 0 ] && return 0 # root has every privilege
rtapi_app=$(command -v rtapi_app) || return 0
[ -n "$rtapi_app" ] || return 0
[ -u "$rtapi_app" ] && return 0 # setuid root
if command -v getcap >/dev/null 2>&1; then
case $(getcap "$rtapi_app" 2>/dev/null) in
*cap_sys_nice*) return 0 ;; # file capabilities
esac
fi
echo "Warning: rtapi_app is not setuid root and has no realtime capabilities." >&2
echo " Realtime threads get no SCHED_FIFO priority or locked memory," >&2
echo " so the latency shown will be far worse than reality." >&2
echo " Run 'sudo make setuid' (or 'sudo make setcap') in src/." >&2
}

parse_time () {
case $1 in
-) echo "0" ;;
Expand Down Expand Up @@ -170,4 +194,6 @@ L=\$(($SIGNALS
echo \$L > "$HOME"/.latency
EOF

check_rt_privileges

halrun lat.hal
Loading