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