run-on-all.sh 670 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. CPUS_ONLINE=$(lscpu --online -p=cpu|grep -v -e '#')
  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
  7. HOST_AFFINITY=$(echo "${CPUS_ONLINE}"|tail -n 1)
  8. #run command on all cpus
  9. for cpu in $CPUS_ONLINE
  10. do
  11. #Don't run guest and host on same CPU
  12. #It actually works ok if using signalling
  13. if
  14. (echo "$@" | grep -e "--sleep" > /dev/null) || \
  15. test $HOST_AFFINITY '!=' $cpu
  16. then
  17. echo "GUEST AFFINITY $cpu"
  18. "$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu
  19. fi
  20. done
  21. echo "NO GUEST AFFINITY"
  22. "$@" --host-affinity $HOST_AFFINITY
  23. echo "NO AFFINITY"
  24. "$@"