Created
November 3, 2022 11:15
-
-
Save suchasplus/45a23216a059c1c6345f9f897451da04 to your computer and use it in GitHub Desktop.
Receive Packet Steering Set
This file contains hidden or 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 | |
# Enable RPS (Receive Packet Steering) | |
cc=$(grep -c processor /proc/cpuinfo) | |
end=$(((cc-32)/4)) | |
#rpcc=$(head -c $end < /dev/zero | tr '\0' 'f') | |
#rpcc=$(printf "f%.0s" $(seq $end)) | |
rsfe=32768 | |
count=0 | |
j1=0 | |
j2=0 | |
# if cpu core > 32, split cpu bits to n,00000000 | |
MASK_FILL="" | |
MASK_RPS="" | |
MASK_FULLF="ffffffff" | |
MASK_ZERO="00000000" | |
idx=$((cc/32)) | |
# max 64 core cpus | |
#if [ $cc -lt 32 ] | |
#then | |
# rpcc=$(printf "f%.0s" $(seq $end)) | |
#else | |
# rpcc_tmp=$(printf "f%.0s" $(seq $end)) | |
# rpcc=$(printf "%s,%s" $rpcc_tmp $MASK_FULLF) | |
#fi | |
for ((i=1; i<=$idx; i++)) | |
do | |
MASK_FILL="${MASK_FILL},${MASK_ZERO}" | |
MASK_RPS="${MASK_RPS},${MASK_FULLF}" | |
done | |
for ((i=0; i<${cc}; i++)) | |
do | |
if [ $i -lt 32 ] | |
then | |
affinity_tmp=$((1<<i)) | |
affinity=$(printf "%X" $affinity_tmp) | |
[ $(($i%4)) -eq 0 ] && j1=$((j1+1)) | |
rpcc=$(printf "f%.0s" $(seq $j1)) | |
else | |
c=$((i-32*idx)) | |
affinity_tmp=$((1<<c)) | |
affinity=$(printf "%X%s" $affinity_tmp $MASK_FILL) | |
[ $(($c%4)) -eq 0 ] && j2=$((j2+1)) | |
rpcc_tmp=$(printf "f%.0s" $(seq $j2)) | |
rpcc=$(printf "%s%s" $rpcc_tmp $MASK_RPS) | |
fi | |
smplist+=($affinity) | |
done | |
echo ${smplist[@]} | |
sysctl -w net.core.rps_sock_flow_entries=$rsfe | |
q=$(ls /sys/class/net/*/queues/rx-*/rps_flow_cnt | wc -l) | |
for fileRfs in $(ls /sys/class/net/*/queues/rx-*/rps_flow_cnt) | |
do | |
echo $((rsfe/q)) > $fileRfs | |
done | |
for fileRps in $(ls /sys/class/net/*/queues/rx-*/rps_cpus) | |
do | |
echo $rpcc | |
echo $rpcc > $fileRps | |
done | |
# for i in `netstat -i | sed '1,2d'| awk '{print $1}' | grep -v lo | grep -v bond` | |
for i in `ip link | grep UP | awk -F'[: ]+' '{print $2}' | grep -v lo | grep -v bond` | |
do | |
irqs+=(`grep $i /proc/interrupts | awk -F'[: ]+' '{print $2}'`) | |
done | |
echo ${#irqs[@]} | |
for (( i=0; i<${#irqs[@]}; i++ )); | |
do | |
test -z ${smplist[$i]} && count=$((RANDOM%(cc-1)+1)) | |
echo ${smplist[$count]} | |
echo ${smplist[$count]} > /proc/irq/${irqs[$i]}/smp_affinity | |
count=$((count+1)) | |
done | |
cat /sys/class/net/*/queues/rx-*/{rps_cpus,rps_flow_cnt} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment