run-on-all.sh 585 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. #use last CPU for host. Why not the first?
  3. #many devices tend to use cpu0 by default so
  4. #it tends to be busier
  5. HOST_AFFINITY=$(lscpu -p=cpu | tail -1)
  6. #run command on all cpus
  7. for cpu in $(seq 0 $HOST_AFFINITY)
  8. do
  9. #Don't run guest and host on same CPU
  10. #It actually works ok if using signalling
  11. if
  12. (echo "$@" | grep -e "--sleep" > /dev/null) || \
  13. test $HOST_AFFINITY '!=' $cpu
  14. then
  15. echo "GUEST AFFINITY $cpu"
  16. "$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu
  17. fi
  18. done
  19. echo "NO GUEST AFFINITY"
  20. "$@" --host-affinity $HOST_AFFINITY
  21. echo "NO AFFINITY"
  22. "$@"