1481eaec3SMichael S. Tsirkin#!/bin/sh
2481eaec3SMichael S. Tsirkin
321f5eda9SHalil PasicCPUS_ONLINE=$(lscpu --online -p=cpu|grep -v -e '#')
4481eaec3SMichael S. Tsirkin#use last CPU for host. Why not the first?
5481eaec3SMichael S. Tsirkin#many devices tend to use cpu0 by default so
6481eaec3SMichael S. Tsirkin#it tends to be busier
721f5eda9SHalil PasicHOST_AFFINITY=$(echo "${CPUS_ONLINE}"|tail -n 1)
8481eaec3SMichael S. Tsirkin
9481eaec3SMichael S. Tsirkin#run command on all cpus
1021f5eda9SHalil Pasicfor cpu in $CPUS_ONLINE
11481eaec3SMichael S. Tsirkindo
12481eaec3SMichael S. Tsirkin	#Don't run guest and host on same CPU
13481eaec3SMichael S. Tsirkin	#It actually works ok if using signalling
14481eaec3SMichael S. Tsirkin	if
15481eaec3SMichael S. Tsirkin		(echo "$@" | grep -e "--sleep" > /dev/null) || \
16481eaec3SMichael S. Tsirkin			test $HOST_AFFINITY '!=' $cpu
17481eaec3SMichael S. Tsirkin	then
18481eaec3SMichael S. Tsirkin		echo "GUEST AFFINITY $cpu"
19481eaec3SMichael S. Tsirkin		"$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu
20481eaec3SMichael S. Tsirkin	fi
21481eaec3SMichael S. Tsirkindone
22481eaec3SMichael S. Tsirkinecho "NO GUEST AFFINITY"
23481eaec3SMichael S. Tsirkin"$@" --host-affinity $HOST_AFFINITY
24481eaec3SMichael S. Tsirkinecho "NO AFFINITY"
25481eaec3SMichael S. Tsirkin"$@"
26