Created
July 4, 2022 15:09
-
-
Save ljjjustin/bcbc4691bd25a6ddf501d5a09da519cc to your computer and use it in GitHub Desktop.
calculate rps cpu mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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