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