Michael S. Tsirkin | 481eaec | 2016-01-21 14:44:10 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Halil Pasic | 12274f2 | 2016-08-29 18:25:22 +0200 | [diff] [blame] | 3 | CPUS_ONLINE=$(lscpu --online -p=cpu|grep -v -e '#') |
Michael S. Tsirkin | 481eaec | 2016-01-21 14:44:10 +0200 | [diff] [blame] | 4 | #use last CPU for host. Why not the first? |
| 5 | #many devices tend to use cpu0 by default so |
| 6 | #it tends to be busier |
Halil Pasic | 12274f2 | 2016-08-29 18:25:22 +0200 | [diff] [blame] | 7 | HOST_AFFINITY=$(echo "${CPUS_ONLINE}"|tail -n 1) |
Michael S. Tsirkin | 481eaec | 2016-01-21 14:44:10 +0200 | [diff] [blame] | 8 | |
| 9 | #run command on all cpus |
Halil Pasic | 12274f2 | 2016-08-29 18:25:22 +0200 | [diff] [blame] | 10 | for cpu in $CPUS_ONLINE |
Michael S. Tsirkin | 481eaec | 2016-01-21 14:44:10 +0200 | [diff] [blame] | 11 | do |
| 12 | #Don't run guest and host on same CPU |
| 13 | #It actually works ok if using signalling |
| 14 | if |
| 15 | (echo "$@" | grep -e "--sleep" > /dev/null) || \ |
| 16 | test $HOST_AFFINITY '!=' $cpu |
| 17 | then |
| 18 | echo "GUEST AFFINITY $cpu" |
| 19 | "$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu |
| 20 | fi |
| 21 | done |
| 22 | echo "NO GUEST AFFINITY" |
| 23 | "$@" --host-affinity $HOST_AFFINITY |
| 24 | echo "NO AFFINITY" |
| 25 | "$@" |