72 lines
2.2 KiB
Bash
72 lines
2.2 KiB
Bash
#!/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
|