Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ljjjustin/bcbc4691bd25a6ddf501d5a09da519cc to your computer and use it in GitHub Desktop.
Save ljjjustin/bcbc4691bd25a6ddf501d5a09da519cc to your computer and use it in GitHub Desktop.
calculate rps cpu mask
#!/bin/bash
# 96 core at most
calc_rps_cpus()
{
local cpu_ids=$(echo $@ | sort)
local h=0
local m=0
local l=0
for i in $(echo $cpu_ids)
do
if [ $i -lt 32 ]; then
l=$((0x1<<$i | $l))
elif [ $i -lt 64 ]; then
i=$((i-32))
m=$((0x1<<$i | $m))
elif [ $i -lt 96 ]; then
i=$((i-64))
h=$((0x1<<$i | $h))
fi
done
printf "%08x,%08x,%08x" $h $m $l
}
# examples
echo $(calc_rps_cpus 0 95)
echo $(calc_rps_cpus 0 1 2 3)
echo $(calc_rps_cpus 64 65 66 67)
echo $(calc_rps_cpus 92 93 94 95)
echo $(calc_rps_cpus 8 9 10 11 12 13 14 15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment