Skip to content

Instantly share code, notes, and snippets.

@weldpua2008
Created August 15, 2018 09:14
Show Gist options
  • Save weldpua2008/92c803225ea095434f3e65b560c0f3ff to your computer and use it in GitHub Desktop.
Save weldpua2008/92c803225ea095434f3e65b560c0f3ff to your computer and use it in GitHub Desktop.
Optimize max RX/TX for ixgbe with ethtool on bond interfaces
#!/bin/bash
### BEGIN INIT INFO
# Provides: optimize-nics
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# chkconfig: 2345 98 90
# Short-Description: Enable optimization of NICs RX/TX
# Description: Sets RX/TX to maximum, to improve
# network performance and decrease drops counters.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
INTERFACES="bond0 bond1"
LOCK_FILE=/tmp/.optimize-nics.lock
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:$PATH"
export PATH
[ -f /etc/sysconfig/cedato-optimize-nics ] && . /etc/sysconfig/cedato-optimize-nics
case "$1" in
start)
if [ -e "$LOCK_FILE" ];then
echo "Already applied"
success $"Already applied"
exit 0
fi
for bond_int in $(echo $INTERFACES);do
if [[ -e "/sys/class/net/$bond_int/bonding/slaves" ]];then
echo -n $"Starting optimization on $bond_int: "
is_updated=""
for en in `cat /sys/class/net/$bond_int/bonding/slaves 2> /dev/null`;do
# check if ixgbe
ethtool -i $en|grep -q ixgbe
if [[ $? -ne 0 ]];then
echo ""
echo -n "Unsupported interface driver "
success $"Nic $en"
continue
fi
update_str=""
max_rx=$(ethtool -g $en|awk '/^RX:/ {print$2}'|tr '\n' ' '|awk '{print $1}')
curr_rx=$(ethtool -g $en|awk '/^RX:/ {print$2}'|tr '\n' ' '|awk '{print $2}')
[[ ${curr_rx} -lt ${max_rx} ]] && update_str="rx ${max_rx}"
max_tx=$(ethtool -g $en|awk '/^TX:/ {print$2}'|tr '\n' ' '|awk '{print $1}')
curr_tx=$(ethtool -g $en|awk '/^TX:/ {print$2}'|tr '\n' ' '|awk '{print $2}')
[[ ${curr_tx} -lt ${max_tx} ]] && update_str="$update_str tx ${max_tx}"
if [[ "$update_str" != "" ]];then
is_updated="${is_updated}$update_str"
ethtool -G $en $update_str && success $"Nic $en" || failure $"Nic $en"
RETVAL=$?
[ $RETVAL -ne 0 ] && exit $RETVAL
fi
[[ "$is_updated" = "" ]] && success
done
fi
done
touch "$LOCK_FILE"
success
echo
exit 0
;;
stop)
success
;;
status)
if [ -e "$LOCK_FILE" ];then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment