run-on-all.sh 635 B

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