CPU0DEVS="" CPU1DEVS="eth0 eth1" CPU2DEVS="" CPU3DEVS="" CPU4DEVS="" CPU5DEVS="" CPU6DEVS="" CPU7DEVS="" ALLCPUS="0 1 2 3 4 5 6 7" ALLDEVS="${CPU0DEVS} ${CPU1DEVS} ${CPU2DEVS} ${CPU3DEVS}" ALLDEVS+="${CPU4DEVS} ${CPU5DEVS} ${CPU6DEVS} ${CPU7DEVS}" ACTIVECPUS="" function results() { for CPU in $ACTIVECPUS; do echo "Results for CPU" ${CPU} echo -n "Interfaces: " eval DEVS=\$CPU${CPU}DEVS for DEV in $DEVS; do echo -n "${DEV} " done echo grep -A 2 Result /proc/net/pktgen/kpktgend_${CPU} done } function pgset() { local result echo $1 > $PGDEV if [ $? != 0 ]; then exit 1 fi result=`cat $PGDEV | fgrep "Result: OK:"` if [ "$result" = "" ]; then cat $PGDEV | fgrep Result: fi } function cpu_clear() { for CPU in $ALLCPUS; do PGDEV=/proc/net/pktgen/kpktgend_${CPU} if [ ! -e ${PGDEV} ]; then continue; fi pgset "rem_device_all" eval DEVS=\$CPU${CPU}DEVS if [ -n "${DEVS}" ]; then ACTIVECPUS+="$CPU " fi done } function cpu_config() { for CPU in $ACTIVECPUS; do PGDEV=/proc/net/pktgen/kpktgend_${CPU} if [ ! -e ${PGDEV} ]; then continue; fi eval DEVS=\$CPU${CPU}DEVS MASK=`python -c "print 1 << ${CPU}"` for DEV in $DEVS; do echo "Adding ${DEV} to cpu ${CPU}" pgset "add_device ${DEV}" # Seetup IRQ affinity. IRQ=`grep ${DEV} /proc/interrupts | cut -f1 -d':'` echo $MASK > /proc/irq/${IRQ}/smp_affinity done # Fix cpu frequency at max cat /sys/devices/system/cpu/cpu${CPU}/cpufreq/scaling_max_freq > /sys/devices/system/cpu/cpu${CPU}/cpufreq/scaling_min_freq pgset "max_before_softirq 10000" done } function net_up() { for DEV in $ALLDEVS; do ifconfig $DEV up if [ $? != 0 ]; then exit 255 fi done } function net_config() { for DEV in $ALLDEVS; do echo "Initializing" $DEV PGDEV=/proc/net/pktgen/${DEV} pgset "pkt_size 1500" pgset "dst 10.10.10.2" pgset "dst_mac 00:02:B3:9F:B4:25" pgset "count 1000000" done } function net_set() { for DEV in $ALLDEVS; do PGDEV=/proc/net/pktgen/${DEV} pgset "$1" done } function run() { PGDEV=/proc/net/pktgen/pgctrl trap "results" INT echo "Running... ctrl^C to stop" pgset "start" trap - INT echo "Done" results } net_up cpu_clear cpu_config net_config net_set "prealloc 10000" run net_set "pktbuflen 10240" run net_set "smallfrags 3" run net_set "smallfrags 0" net_set "flag FAST_MEMCPY" run net_set "pktbuflen 0" net_set "prealloc 0" run