builds and runs on intel-x86 and rpi4 with acceptable realtime performance

This commit is contained in:
vaughn committed 2026-09-25 17:29:14 -04:00
1 parent 2bce6fa556
commit 3faf544f0b
120 files changed
+6317 -1

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
#!/bin/sh
##modifiable variables
#high-level parameters
runtime=3600
corelist=-1
interval=200
full_test=0
do_stress=1
mode="svg"
out_dir=$(pwd)
#stress parameters
c_hogs=2
v_hogs=2
v_mem="128M"
d_hogs=1
i_hogs=2
#constants
start_dir=$(pwd)
work_dir="/tmp/tuned"
hist_max=400
#handle optional arguments
#end option handling
c_str=""
v_str=""
d_str=""
i_str=""
if [ $c_hogs -gt 0 ]; then
c_str="-c $c_hogs"
fi
if [ $v_hogs -gt 0 ]; then
v_str="--vm $v_hogs --vm-bytes $v_mem"
fi
if [ $d_hogs -gt 0 ]; then
d_str="-d $d_hogs"
fi
if [ $i_hogs -gt 0 ]; then
i_str="-i $i_hogs"
fi
n_intervals=$(($runtime*1000000/$interval))
mkdir -p $work_dir && cd $work_dir
if [ $do_stress = 1 ]; then
stress $c_str $v_str $d_str $i_str -t $((runtime+1)) &
fi
sudo cyclictest -m -t -a2-3 -c1 -p98 -i$interval -h$hist_max -l$n_intervals --mainaffinity=0 -q >output
max=`grep "Max Latencies" output | tr " " "\n" | sort -n | tail -1 | sed s/^0*//`
grep -v -e "^#" -e "^$" output | tr " " "\t" >histogram
ncores=2
fn="plot."$mode
for j in `seq 1 $ncores`
do
column=`expr $j + 1`
cut -f1,$column histogram >histogram$j
done
echo -n -e "set title \"Latency plot\"\n\
set terminal $mode\n\
set xlabel \"Latency (us), max $max us\"\n\
set logscale y\n\
set xrange [0:$hist_max]\n\
set yrange [0.8:*]\n\
set ylabel \"Number of latency samples\"\n\
set output \"$fn\"\n\
plot " >plotcmd
for j in `seq 1 $ncores`
do
if test $j != 1
then
echo -n ", " >>plotcmd
fi
cpuno=`expr $j - 1`
if test $cpuno -lt 10
then
title=" CPU$cpuno"
else
title="CPU$cpuno"
fi
echo -n "\"histogram$j\" using 1:2 title \"$title\" with histeps" >>plotcmd
done
gnuplot -persist <plotcmd
cp $fn $out_dir
cd $start_dir
rm -rf $work_dir
+46
View File
@@ -0,0 +1,46 @@
LICENSE = "CLOSED"
#MY_FILES =
#LIC_FILES_CHKSUM = "file://cf/install-sh;beginline=6;endline=16;md5=6c39b6a36ad775d09cc9ee0e33fe9e6c"
SRC_URI = "file://lat-plot \
"
# python3targetconfig: configuration for the target machine is accessible (such as correct installation directories)
# autotools-brokensep: autotools build process (without support for building outside of ${S})
# pkgconfig: standard way to get header and library information by using pkg-config
#inherit autotools-brokensep pkgconfig python3native
# Modify these as desired
PV = "0.1"
#SRCREV = "bcbf35634ccf49ff39261b291f01ca0c4a5fddd5"
#S = "${WORKDIR}/git"
# LinuxCNC build separation is broken, so we need to build in src
#B = "${S}/src"
S = '${UNPACKDIR}'
TARGET_CC_ARCH += " ${LDFLAGS}"
#######################################################
# autotools fixes
#######################################################
#AUTOTOOLS_SCRIPT_PATH = "${B}"
# We need to replace autotools_preconfigure with our own, because it deletes ${B} otherwise
# since S != B in our case (but B is still *inside* S)
#DEPENDS += " tk8 tcl8 tcl8-native tk8-native freetype"
RDEPENDS:${PN} += " rt-tests gnuplot stress"
#RDEPENDS:${PN} += "cairo pango gd"
#PREFERRED_VERSION:tk8 = "8.6.%"
#RDEPENDS:${PN}-dev += " tk8 "
#inherit autotools
FILES:${PN} += " /lat-plot;/usr/bin/lat-plot \
"
FILES:${PN}-dev = " "
FILES:${PN}-dbg = " "
do_install () {
install -m 777 ${UNPACKDIR}/lat-plot ${D}/lat-plot
}
+17
View File
@@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+71
View File
@@ -0,0 +1,71 @@
#!/bin/bash
#### BEGIN INIT INFO
# PROVIDES: realtime environment setup
# Required-Start:
# Required-Stop:
# Default-Start: S
# Short-Description: Isolate RT Cores
### END INIT INFO
#total number of physical cores
#N_TOT=$(( $(lscpu | awk '/^Socket\(s\)/{ print $2 }') * $(lscpu | awk '/^Core\(s\) per socket/{ print $4 }') ))
#requested number of realtime cores
#N_RT_REQ=1
#if [ "$#" >= "1" ]; then
# N_RT_REQ=$1
#fi
REALTIME_RESTART_THRESHOLD=1
RESTART_FILE="/var/tmp/realtime_setup_restarts"
GRUB_FILE="/boot/EFI/BOOT/grub.cfg"
GRUB_LINUX_CFG="/etc/grub.d/10_linux"
touch /var/tmp/realtime_setup_restarts
num_restarts=$(cat "$RESTART_FILE" | tr -dc '0-9')
curProfile=$(tuned-adm active | grep "realtime")
#TODO use tuned-adm verify instead, as active profile doesn't mean it has all parameters set correctly
if [[ -z "$num_restarts" ]] || [[ ! -z "$curProfile" ]]; then
num_restarts=0
echo "0" > $RESTART_FILE
fi
if [[ -z "$curProfile" ]] && (( $num_restarts <= $REALTIME_RESTART_THRESHOLD )); then
#TODO actually check grub file and only overwrite if it is not generated by grub-mkconfig
echo "updating GRUB file: $GRUB_FILE"
sed -i 's/GRUB_DISABLE_LINUX_PARTUUID=true/GRUB_DISABLE_LINUX_PARTUUID=false/g' $GRUB_LINUX_CFG
grub-mkconfig > $GRUB_FILE
sed -i '/\tload_video/d' $GRUB_FILE
sed -i '/gzio/d' $GRUB_FILE
sed -i '/echo/d' $GRUB_FILE
tuned-adm profile realtime
num_restarts=$((num_restarts+1))
echo "$num_restarts" > $RESTART_FILE
systemctl reboot --message="applied realtime profile; rebooting"
fi
if (( $num_restarts > $REALTIME_RESTART_THRESHOLD )); then
echo "unable to set real-time Tuned profile after $num_restarts system restarts"
return 1
fi
echo 0 > /sys/devices/system/machinecheck/machinecheck0/check_interval
#TODO the following should really adjust dynamically based on the actual cores allocated by tuned
pqos -R
pqos -e 'l2:0=0x0f;l2:1=0xf0'
pqos -a 'llc:0=0,1;llc:2=2,3'
for i in $(cat /proc/interrupts | grep '^ *[0-9]*[0-9]:' | awk {'print $1'} | sed 's/:$//');
do
if [ "$i" = "0" ]; then
continue
fi
if [ "$i" = "2" ]; then
continue
fi
echo 1 > /proc/irq/$i/smp_affinity
done
for i in $(pgrep rcu);
do
flags=$(cut -f 9 -d ' ' /proc/$i/stat)
if [ ! $((flags & 0x04000000)) ]; then
taskset -pc 0 $i > /dev/null
fi
done
+8
View File
@@ -0,0 +1,8 @@
[Unit]
Description=Initialize RT Cores
[Service]
ExecStart=/bin/bash /usr/bin/rt-setup
[Install]
WantedBy=multi-user.target
+58
View File
@@ -0,0 +1,58 @@
LICENSE = "MIT"
#MY_FILES =
LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
inherit systemd
SYSTEMD_AUTO_ENABLE:${PN} = "enable"
SYSTEMD_SERVICE:${PN} = "rt.service"
SRC_URI:append = "file://rt-setup \
file://rt.service \
file://COPYING.MIT \
"
# python3targetconfig: configuration for the target machine is accessible (such as correct installation directories)
# autotools-brokensep: autotools build process (without support for building outside of ${S})
# pkgconfig: standard way to get header and library information by using pkg-config
#inherit autotools-brokensep pkgconfig python3native
# Modify these as desired
PV = "0.0"
#SRCREV = "bcbf35634ccf49ff39261b291f01ca0c4a5fddd5"
#S = "${WORKDIR}/git"
# LinuxCNC build separation is broken, so we need to build in src
#B = "${S}/src"
S = '${UNPACKDIR}'
TARGET_CC_ARCH += " ${LDFLAGS}"
#######################################################
# autotools fixes
#######################################################
#AUTOTOOLS_SCRIPT_PATH = "${B}"
# We need to replace autotools_preconfigure with our own, because it deletes ${B} otherwise
# since S != B in our case (but B is still *inside* S)
#DEPENDS += " tk8 tcl8 tcl8-native tk8-native freetype"
#RDEPENDS:${PN} += " rt-tests "
#PREFERRED_VERSION:tk8 = "8.6.%"
RDEPENDS:${PN} += " bash "
#inherit autotools
FILES:${PN} += " /usr/bin/rt-setup \
${systemd_unitdir}/system/rt.service \
"
FILES:${PN}-dev = " "
FILES:${PN}-dbg = " "
do_install () {
install -d ${D}/usr/bin
#install -d ${D}${sysconfdir}/init.d
install -d ${D}${systemd_unitdir}/system
install -m 0755 ${UNPACKDIR}/rt.service ${D}${systemd_unitdir}/system/rt.service
install -m 0755 ${UNPACKDIR}/rt-setup ${D}/usr/bin/rt-setup
#update-rc.d -r ${D} rt-setup start 03 S .
}
+14
View File
@@ -0,0 +1,14 @@
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
default=boot graphics console
timeout=5
menuentry 'boot graphics console'{
linux /@KERNEL_IMAGETYPE@ LABEL=initrd-install @APPEND@
initrd /wrlinux-image-installer-initramfs-@MACHINE@.rootfs.@INITRAMFS_FSTYPES@
}
menuentry 'boot serial console'{
linux /@KERNEL_IMAGETYPE@ LABEL=initrd-install console=ttyS0,115200 @APPEND@
initrd /wrlinux-image-installer-initramfs-@MACHINE@.rootfs.@INITRAMFS_FSTYPES@
}
@@ -0,0 +1,26 @@
diff --git a/tuned.spec b/tuned.spec
index 0b7dc03..6213976 100644
--- a/tuned.spec
+++ b/tuned.spec
@@ -397,7 +397,7 @@ if [ "$1" == 0 ]; then
# cleanup for Boot loader specification (BLS)
# clear grubenv variables
- grub2-editenv - unset tuned_params tuned_initrd &>/dev/null || :
+ grub2-editenv /boot/EFI/BOOT/grubenv unset tuned_params tuned_initrd &>/dev/null || :
# unpatch BLS entries
MACHINE_ID=`cat /etc/machine-id 2>/dev/null`
if [ "$MACHINE_ID" ]
diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py
index 2711e11..c327384 100644
--- a/tuned/plugins/plugin_bootloader.py
+++ b/tuned/plugins/plugin_bootloader.py
@@ -481,7 +481,7 @@ class BootloaderPlugin(base.Plugin):
def _update_grubenv(self, d):
log.debug("updating grubenv, setting %s" % str(d))
l = ["%s=%s" % (str(option), str(value)) for option, value in d.items()]
- (rc, out) = self._cmd.execute(["grub2-editenv", "-", "set"] + l)
+ (rc, out) = self._cmd.execute(["grub2-editenv", "/boot/EFI/BOOT/grubenv", "set"] + l)
if rc != 0:
log.warning("cannot update grubenv: '%s'" % out)
return False
@@ -0,0 +1,27 @@
Upstream-Status: Inappropriate [oe specific]
diff --git a/tuned.spec b/tuned.spec
index 0b7dc03..6213976 100644
--- a/tuned.spec
+++ b/tuned.spec
@@ -397,7 +397,7 @@ if [ "$1" == 0 ]; then
# cleanup for Boot loader specification (BLS)
# clear grubenv variables
- grub2-editenv - unset tuned_params tuned_initrd &>/dev/null || :
+ grub2-editenv "/boot/EFI/BOOT/grubenv" unset tuned_params tuned_initrd &>/dev/null || :
# unpatch BLS entries
MACHINE_ID=`cat /etc/machine-id 2>/dev/null`
if [ "$MACHINE_ID" ]
diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py
index 2711e11..c327384 100644
--- a/tuned/plugins/plugin_bootloader.py
+++ b/tuned/plugins/plugin_bootloader.py
@@ -481,7 +481,7 @@ class BootloaderPlugin(base.Plugin):
def _update_grubenv(self, d):
log.debug("updating grubenv, setting %s" % str(d))
l = ["%s=%s" % (str(option), str(value)) for option, value in d.items()]
- (rc, out) = self._cmd.execute(["grub2-editenv", "-", "set"] + l)
+ (rc, out) = self._cmd.execute(["grub2-editenv", "/boot/EFI/BOOT/grubenv", "set"] + l)
if rc != 0:
log.warning("cannot update grubenv: '%s'" % out)
return False
+49
View File
@@ -0,0 +1,49 @@
diff --git a/tuned.spec b/tuned.spec
index 0b7dc03..6213976 100644
--- a/tuned.spec
+++ b/tuned.spec
@@ -397,7 +397,7 @@ if [ "$1" == 0 ]; then
# cleanup for Boot loader specification (BLS)
# clear grubenv variables
- grub2-editenv - unset tuned_params tuned_initrd &>/dev/null || :
+ grub2-editenv /boot/EFI/BOOT/grubenv unset tuned_params tuned_initrd &>/dev/null || :
# unpatch BLS entries
MACHINE_ID=`cat /etc/machine-id 2>/dev/null`
if [ "$MACHINE_ID" ]
diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py
index 2711e11..451a642 100644
--- a/tuned/plugins/plugin_bootloader.py
+++ b/tuned/plugins/plugin_bootloader.py
@@ -361,9 +361,13 @@ class BootloaderPlugin(base.Plugin):
log.debug("initial patching of grub.cfg")
s = r"\1\n\n" + consts.GRUB2_TEMPLATE_HEADER_BEGIN + "\n"
for opt in d:
+ log.debug("opt: " + opt)
s += r"set " + self._cmd.escape(opt) + "=\"" + self._cmd.escape(d[opt]) + "\"\n"
s += consts.GRUB2_TEMPLATE_HEADER_END + r"\n"
+ log.debug("\n\ns = \n" + s)
+ log.debug("\n\n#1 grub_cfg = \n" + grub_cfg)
grub2_cfg = re.sub(r"^(\s*###\s+END\s+[^#]+/00_header\s+### *)\n", s, grub2_cfg, flags = re.MULTILINE)
+ log.debug("\n\n#2 grub_cfg = \n" + grub_cfg)
d2 = {"linux" : consts.GRUB2_TUNED_VAR, "initrd" : consts.GRUB2_TUNED_INITRD_VAR}
for i in d2:
@@ -373,6 +377,8 @@ class BootloaderPlugin(base.Plugin):
grub2_cfg = re.sub(r"^(\s*" + i + r"(?:16|efi)?\s+\S+rescue.*)\$" + d2[i] + r" *(.*)$", r"\1\2", grub2_cfg, flags = re.MULTILINE)
# fix whitespaces in rescue kernels
grub2_cfg = re.sub(r"^(\s*" + i + r"(?:16|efi)?\s+\S+rescue.*) +$", r"\1", grub2_cfg, flags = re.MULTILINE)
+
+ log.debug("\n\n#3 grub_cfg = \n" + grub_cfg)
return grub2_cfg
def _grub2_default_env_patch(self):
@@ -481,7 +487,7 @@ class BootloaderPlugin(base.Plugin):
def _update_grubenv(self, d):
log.debug("updating grubenv, setting %s" % str(d))
l = ["%s=%s" % (str(option), str(value)) for option, value in d.items()]
- (rc, out) = self._cmd.execute(["grub2-editenv", "-", "set"] + l)
+ (rc, out) = self._cmd.execute(["grub2-editenv", "/boot/EFI/BOOT/grubenv", "set"] + l)
if rc != 0:
log.warning("cannot update grubenv: '%s'" % out)
return False
+93
View File
@@ -0,0 +1,93 @@
LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
SRC_URI = "git://github.com/redhat-performance/tuned;protocol=https;branch=master"
SRC_URI[sha256sum] = "66fa95b07b73a1ceafb6712b140fbbd77136d4cf86de47d6cabef9137a9bbdfa"
SRC_URI += " file://tuned-boot-path.patch "
#SRC_URI += " file://grubenv_location.patch "
# Modify these as desired
PV = "2.26+git${SRCPV}"
SRCREV = "181472a0be2125c8cd36c7673ec546d75d396a3d"
# LinuxCNC build separation is broken, so we need to build in src
#S = '${UNPACKDIR}/git'
#TARGET_CC_ARCH += " ${LDFLAGS}"
INHERIT += "grub-efi"
DEPENDS += " desktop-file-utils-native python3"
RDEPENDS:${PN} += "grub-bootconf grub-efi grub-efi-editenv python3 python3-core bash systemtap python3-dbus python3-pygobject python3-pyudev python3-linux-procfs irqbalance "
#RDEPENDS:${PN} += " grub grub-editenv grub-bootconf grub-common grub-efi grub-efi-editenv "
inherit pkgconfig
inherit systemd
SYSTEMD_AUTO_ENABLE:${PN} = "enable"
SYSTEMD_SERVICE:${PN} = "tuned.service"
BASELIB:${PN} = "lib64"
#TODO make file callouts explicit, or at least somehow filter down to ensure only required files are packaged
FILES:${PN} += "\
/usr/lib64/* \
/usr/lib/* \
/usr/local/* \
/usr/share/* \
/usr/bin/grub2-editenv \
/etc/default/grub \
"
FILES:${PN}-dev = " "
FILES:${PN}-dbg = " "
do_configure:append () {
cd ${S}
oe_runmake
}
do_install:append () {
cd ${S}
oe_runmake install DESTDIR=${D}
mkdir -p ${RECIPE_SYSROOT}/etc
#TODO this is mad hacky, we don't want user account info tied up in the build enviornment
cp /etc/passwd ${RECIPE_SYSROOT}/etc/passwd
cp /etc/group ${RECIPE_SYSROOT}/etc/group
rm ${D}/run -rf
rm ${PKGD}/var/volatile -rf
PYVER=$(find ${RECIPE_SYSROOT}/usr/${BASELIB} -maxdepth 1 -type d -name python3\.* -exec basename {} \;)
mkdir -p ${D}/usr/${BASELIB}/${PYVER}/site-packages
#PYTHON_SITELIB might break on a future update to tuned; this line is copied manually from the makefile
PYTHON_SITELIB=$(python3 -c 'from sysconfig import get_path; print(get_path("purelib"));')
mv ${D}${PYTHON_SITELIB}/${PN} ${D}/usr/${BASELIB}/${PYVER}/site-packages
ln -s /boot/EFI/BOOT/grub.cfg ${D}/etc/grub2.cfg
ln -s grub-editenv ${D}/usr/bin/grub2-editenv
ln -s grub-mkconfig ${D}/usr/bin/grub2-mkconfig
mkdir -p ${D}/etc/default
echo "#this file was generated by the Tuned bitbake install script" > ${D}/etc/default/grub
#mkdir -p ${D}/boot/grub
#mkdir -p ${DEPLOY_DIR_IMAGE}/boot
#ln -s /boot/EFI/BOOT/ ${DEPLOY_DIR_IMAGE}/boot/grub
#source Makefile
}
#raspberry pi seems to struggle with only 1 housekeeping core, so we set a second one here
#unclear why, or if this will extend to other ARM systems (as a stab in the dark, possibly where u-boot is required?)
#Specifically, an RPi 5 reports kernel panic if isolcpus=1-3, or even 1-2 (although it boots normally if isolcpus=2-3).
# with isolcpus=1-2, a boot delay of 2s allowed the Pi to boot successfully
# with isolcpus=1-3, Pi reports a kernel panic with boot delay even up to 4s
do_install:append:rpi () {
sed -i "s/1}/2}/" ${D}/etc/${PN}/realtime-variables.conf
}
do_package_qa:prepend () {
import shutil
_dir = d.getVar('PKGD') + "/var/volatile"
if os.path.isdir(_dir):
shutil.rmtree(_dir)
_dir = d.getVar('PKGDEST') + "/" + d.getVar('PN') + "/var/volatile"
if os.path.isdir(_dir):
shutil.rmtree(_dir)
}
#IMAGE_BOOT_FILES += "grub"
#IMAGE_EFI_BOOT_FILES += "/boot/grub"
INSANE_SKIP:${PN} += "host-user-contaminated"