bcを使いますので、yum/aptなどで導入しておく必要があります。
CPUコア数は自動的に判定し、適切(全てのコアへ分散する)な設定を行います。
/etc/init.d/rpsxps
#!/bin/sh
# chkconfig: - 85 15
### BEGIN INIT INFO
# Provides: rpsxps
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: rpsxps
# Description: rpsxps
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
### Environment variables
action="$1"
prog=$(basename $0)
fullbit=32
# Feel free to change any of the following variables for your app:
start(){
echo -n $"Starting $prog: "
for if in `ls /sys/class/net| grep -v lo`; do
I=0
for q in `ls /sys/class/net/${if}/queues/tx-*/xps_cpus`;do
echo 2^${I}|bc > ${q}
I=$(( ${I}+1 ))
done
for q in `ls -dF /sys/class/net/${if}/queues/rx-*`;do
n=$(cat /proc/cpuinfo | grep ^processor|wc -l)
if [ ${n} -ge ${fullbit} ]; then n=${fullbit}; fi
echo "obase=16;2^${n}-1"| bc > ${q}/rps_cpus
echo 4096 > ${q}/rps_flow_cnt
done
done
echo 32768 > /proc/sys/net/core/rps_sock_flow_entries
echo
}
stop(){
echo
}
case $action in
start)
start
;;
stop)
stop
;;
*)
echo >&2 "Usage: $0 <start|stop>"
exit 1
;;
esac
exit 0```