1481eaec3SMichael S. Tsirkin#!/bin/sh
2481eaec3SMichael S. Tsirkin
3481eaec3SMichael S. Tsirkin#use last CPU for host. Why not the first?
4481eaec3SMichael S. Tsirkin#many devices tend to use cpu0 by default so
5481eaec3SMichael S. Tsirkin#it tends to be busier
6481eaec3SMichael S. TsirkinHOST_AFFINITY=$(cd /dev/cpu; ls|grep -v '[a-z]'|sort -n|tail -1)
7481eaec3SMichael S. Tsirkin
8481eaec3SMichael S. Tsirkin#run command on all cpus
9481eaec3SMichael S. Tsirkinfor cpu in $(cd /dev/cpu; ls|grep -v '[a-z]'|sort -n);
10481eaec3SMichael S. Tsirkindo
11481eaec3SMichael S. Tsirkin	#Don't run guest and host on same CPU
12481eaec3SMichael S. Tsirkin	#It actually works ok if using signalling
13481eaec3SMichael S. Tsirkin	if
14481eaec3SMichael S. Tsirkin		(echo "$@" | grep -e "--sleep" > /dev/null) || \
15481eaec3SMichael S. Tsirkin			test $HOST_AFFINITY '!=' $cpu
16481eaec3SMichael S. Tsirkin	then
17481eaec3SMichael S. Tsirkin		echo "GUEST AFFINITY $cpu"
18481eaec3SMichael S. Tsirkin		"$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu
19481eaec3SMichael S. Tsirkin	fi
20481eaec3SMichael S. Tsirkindone
21481eaec3SMichael S. Tsirkinecho "NO GUEST AFFINITY"
22481eaec3SMichael S. Tsirkin"$@" --host-affinity $HOST_AFFINITY
23481eaec3SMichael S. Tsirkinecho "NO AFFINITY"
24481eaec3SMichael S. Tsirkin"$@"
25