27 lines · bash
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.03 4CPUS_ONLINE=$(lscpu --online -p=cpu|grep -v -e '#')5#use last CPU for host. Why not the first?6#many devices tend to use cpu0 by default so7#it tends to be busier8HOST_AFFINITY=$(echo "${CPUS_ONLINE}"|tail -n 1)9 10#run command on all cpus11for cpu in $CPUS_ONLINE12do13 #Don't run guest and host on same CPU14 #It actually works ok if using signalling15 if16 (echo "$@" | grep -e "--sleep" > /dev/null) || \17 test $HOST_AFFINITY '!=' $cpu18 then19 echo "GUEST AFFINITY $cpu"20 "$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu21 fi22done23echo "NO GUEST AFFINITY"24"$@" --host-affinity $HOST_AFFINITY25echo "NO AFFINITY"26"$@"27