diff --git a/scripts/latency-histogram b/scripts/latency-histogram index 014b63f582f..409ed5ca144 100755 --- a/scripts/latency-histogram +++ b/scripts/latency-histogram @@ -111,6 +111,25 @@ proc which_exe {name} { return -code error "$name: executable not found" } ;# which_exe +proc check_rt_privileges {} { + # Warn if rtapi reports no realtime ('halcmd getrt'), usually a missing + # 'sudo make setuid'. LINUXCNC_NO_RT_WARN suppresses it on dev boxes. + if {[info exists ::env(LINUXCNC_NO_RT_WARN)]} return + set out "" + catch {exec $::LH(prog,halcmd) getrt 2>@1} out + if {![string match {*No realtime available*} $out]} return + set msg "Warning: realtime is not available." + append msg "\nThreads get no SCHED_FIFO priority or locked memory," + append msg "\nso the latency shown will be far worse than reality." + append msg "\nOn a run-in-place build, run '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 { @@ -944,6 +963,7 @@ proc windowToFile { win } { if ![info exists ::LH(start)] { set_defaults config + check_rt_privileges progress "Loading packages" load_packages signal trap SIGINT finish diff --git a/scripts/latency-test b/scripts/latency-test index 63b34c0034d..8da38e8e1ba 100755 --- a/scripts/latency-test +++ b/scripts/latency-test @@ -16,6 +16,20 @@ kversion=$(uname -v) calc() { awk "BEGIN { print ($1); }" < /dev/null; } icalc() { awk "BEGIN { printf \"%.0f\n\", ($1); }" < /dev/null; } +# Warn if rtapi reports no realtime ('halcmd getrt'), usually a missing +# 'sudo make setuid'. LINUXCNC_NO_RT_WARN suppresses it on dev boxes. +check_rt_privileges () { + [ -n "$LINUXCNC_NO_RT_WARN" ] && return 0 + case $(halcmd getrt 2>&1) in + *"No realtime available"*) ;; + *) return 0 ;; + esac + echo "Warning: realtime is not available: threads get no SCHED_FIFO priority" >&2 + echo " or locked memory, so the latency shown will be far worse than" >&2 + echo " reality. On a run-in-place build, run 'sudo make setuid'" >&2 + echo " (or 'sudo make setcap') in src/." >&2 +} + parse_time () { case $1 in -) echo "0" ;; @@ -170,4 +184,6 @@ L=\$(($SIGNALS echo \$L > "$HOME"/.latency EOF +check_rt_privileges + halrun lat.hal