Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Forked from SaveTheRbtz/set_qdisc.sh
Created February 27, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyaevseev/233aca6f689f3ee2c1defd1b3b6373f8 to your computer and use it in GitHub Desktop.
Save ilyaevseev/233aca6f689f3ee2c1defd1b3b6373f8 to your computer and use it in GitHub Desktop.
mq+fq
#!/bin/bash -ue
#
# Sets up mq+$shed combo for given interface.
#
# NB! To not degrade upload speeds, fq should only be used on kernels >= 3.19:
# https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9878196578286c5ed494778ada01da094377a686
#
if [ $# -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: $0 interface scheduler" >&2
echo " e.g: $0 eth0 fq" >&2
echo " e.g: $0 eth0 pfifo_fast" >&2
exit 64 # EX_USAGE
fi
# There is a bug in our version of `tc` that prevents setting scheduler back to
# pfifo_fast with an error:
# "qdisc 'pfifo_fast' does not support option parsing"
#
# Bug was fixed here:
# https://kernel.googlesource.com/pub/scm/linux/kernel/git/shemminger/iproute2/+/e9e78b0db0e023035e346ba67de838be851eb665%5E%21/
# Therefore verify that we can roll back by checking default qdisc
if [ "$(cat /proc/sys/net/core/default_qdisc)" != "pfifo_fast" ]; then
echo "default qdisc is not 'pfifo_fast'" >&2
exit 2
fi
intf="$1"
shed="$2"
cpus=(/sys/devices/system/cpu/cpu*/driver)
cpu_num=${#cpus[@]}
/sbin/tc qd del dev "$intf" root || :
if [ "$shed" == "pfifo_fast" ]; then
echo "default qdisc selected; skipping creation" >&2
exit 0
fi
/sbin/tc qd add dev "$intf" root handle 1: mq
for i in $(seq 1 $cpu_num); do
slot="$(printf %x $i)"
/sbin/tc qd add dev "$intf" parent 1:"$slot" "$shed"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment