#!/bin/sh #use last CPU for host. Why not the first? #many devices tend to use cpu0 by default so #it tends to be busier global HOST_AFFINITY := $[lscpu -p=cpu | tail -1] #run command on all cpus for cpu in [$[seq 0 $HOST_AFFINITY]] { #Don't run guest and host on same CPU #It actually works ok if using signalling if shell {echo @Argv | grep -e "--sleep" > /dev/null} || \ test $HOST_AFFINITY '!=' $cpu { echo "GUEST AFFINITY $cpu" @Argv --host-affinity $HOST_AFFINITY --guest-affinity $cpu } } echo "NO GUEST AFFINITY" @Argv --host-affinity $HOST_AFFINITY echo "NO AFFINITY" @Argv (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOST_AFFINITY) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(lscpu)} {(-p) (Lit_Other "=") (cpu)}) (C {(tail)} {(-1)})] negated: False ) ] ) left_token: spids: [14 26] ) } spids: [13] ) ] spids: [13] ) (ForEach iter_name: cpu iter_words: [ { (CommandSubPart command_list: (CommandList children:[(C {(seq)} {(0)} {($ VSub_Name "$HOST_AFFINITY")})]) left_token: spids: [38 44] ) } ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_At "$@"))}) (SimpleCommand words: [{(grep)} {(-e)} {(DQ (--sleep))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [77] ) ] ) ] negated: False ) spids: [60 80] ) (C {(test)} {($ VSub_Name "$HOST_AFFINITY")} {(SQ <"!=">)} {($ VSub_Name "$cpu")}) ] op_id: Op_DPipe ) ] action: [ (C {(echo)} {(DQ ("GUEST AFFINITY ") ($ VSub_Name "$cpu"))}) (C {(DQ ($ VSub_At "$@"))} {(--host-affinity)} {($ VSub_Name "$HOST_AFFINITY")} {(--guest-affinity)} {($ VSub_Name "$cpu")} ) ] spids: [-1 97] ) ] spids: [-1 121] ) ] spids: [46 123] ) spids: [37 -1] ) (C {(echo)} {(DQ ("NO GUEST AFFINITY"))}) (C {(DQ ($ VSub_At "$@"))} {(--host-affinity)} {($ VSub_Name "$HOST_AFFINITY")}) (C {(echo)} {(DQ ("NO AFFINITY"))}) (C {(DQ ($ VSub_At "$@"))}) ] )