11d73ba16SJesper Dangaard Brouer#!/bin/bash 2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 31d73ba16SJesper Dangaard Brouer# 41d73ba16SJesper Dangaard Brouer# Script for max single flow performance 51d73ba16SJesper Dangaard Brouer# - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2] 61d73ba16SJesper Dangaard Brouer# 71d73ba16SJesper Dangaard Brouer# Using pktgen "burst" option (use -b $N) 81d73ba16SJesper Dangaard Brouer# - To boost max performance 91d73ba16SJesper Dangaard Brouer# - Avail since: kernel v3.18 101d73ba16SJesper Dangaard Brouer# * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more") 111d73ba16SJesper Dangaard Brouer# - This avoids writing the HW tailptr on every driver xmit 121d73ba16SJesper Dangaard Brouer# - The performance boost is impressive, see commit and blog [2] 131d73ba16SJesper Dangaard Brouer# 141d73ba16SJesper Dangaard Brouer# Notice: On purpose generates a single (UDP) flow towards target, 151d73ba16SJesper Dangaard Brouer# reason behind this is to only overload/activate a single CPU on 161d73ba16SJesper Dangaard Brouer# target host. And no randomness for pktgen also makes it faster. 171d73ba16SJesper Dangaard Brouer# 181d73ba16SJesper Dangaard Brouer# Tuning see: 191d73ba16SJesper Dangaard Brouer# [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html 201d73ba16SJesper Dangaard Brouer# [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html 211d73ba16SJesper Dangaard Brouer# 221d73ba16SJesper Dangaard Brouerbasedir=`dirname $0` 231d73ba16SJesper Dangaard Brouersource ${basedir}/functions.sh 241d73ba16SJesper Dangaard Brouerroot_check_run_with_sudo "$@" 251d73ba16SJesper Dangaard Brouer 261d73ba16SJesper Dangaard Brouer# Parameter parsing via include 271d73ba16SJesper Dangaard Brouersource ${basedir}/parameters.sh 281d73ba16SJesper Dangaard Brouer# Set some default params, if they didn't get set 290f06a678SMartin KaFai Lauif [ -z "$DEST_IP" ]; then 300f06a678SMartin KaFai Lau [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1" 310f06a678SMartin KaFai Laufi 321d73ba16SJesper Dangaard Brouer[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff" 331d73ba16SJesper Dangaard Brouer[ -z "$BURST" ] && BURST=32 349efc44d7SJesper Dangaard Brouer[ -z "$CLONE_SKB" ] && CLONE_SKB="0" # No need for clones when bursting 3569137ea6STariq Toukan[ -z "$COUNT" ] && COUNT="0" # Zero means indefinitely 3640f843eeSDaniel T. Leeif [ -n "$DEST_IP" ]; then 3740f843eeSDaniel T. Lee validate_addr${IP6} $DEST_IP 3840f843eeSDaniel T. Lee read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP) 3940f843eeSDaniel T. Leefi 406e32a74aSDaniel T. Leeif [ -n "$DST_PORT" ]; then 41723d2904SDaniel T. Lee read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT) 42723d2904SDaniel T. Lee validate_ports $UDP_DST_MIN $UDP_DST_MAX 436e32a74aSDaniel T. Leefi 441d73ba16SJesper Dangaard Brouer 451d73ba16SJesper Dangaard Brouer# General cleanup everything since last run 46c8fd4852SIgor Russkikh[ -z "$APPEND" ] && pg_ctrl "reset" 471d73ba16SJesper Dangaard Brouer 481d73ba16SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS 49e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 501d73ba16SJesper Dangaard Brouer dev=${DEV}@${thread} 511d73ba16SJesper Dangaard Brouer 521d73ba16SJesper Dangaard Brouer # Add remove all other devices and add_device $dev to thread 53c8fd4852SIgor Russkikh [ -z "$APPEND" ] && pg_thread $thread "rem_device_all" 541d73ba16SJesper Dangaard Brouer pg_thread $thread "add_device" $dev 551d73ba16SJesper Dangaard Brouer 561d73ba16SJesper Dangaard Brouer # Base config 571d73ba16SJesper Dangaard Brouer pg_set $dev "flag QUEUE_MAP_CPU" 581d73ba16SJesper Dangaard Brouer pg_set $dev "count $COUNT" 591d73ba16SJesper Dangaard Brouer pg_set $dev "clone_skb $CLONE_SKB" 601d73ba16SJesper Dangaard Brouer pg_set $dev "pkt_size $PKT_SIZE" 611d73ba16SJesper Dangaard Brouer pg_set $dev "delay $DELAY" 621d73ba16SJesper Dangaard Brouer pg_set $dev "flag NO_TIMESTAMP" 631d73ba16SJesper Dangaard Brouer 641d73ba16SJesper Dangaard Brouer # Destination 651d73ba16SJesper Dangaard Brouer pg_set $dev "dst_mac $DST_MAC" 6640f843eeSDaniel T. Lee pg_set $dev "dst${IP6}_min $DST_MIN" 6740f843eeSDaniel T. Lee pg_set $dev "dst${IP6}_max $DST_MAX" 681d73ba16SJesper Dangaard Brouer 696e32a74aSDaniel T. Lee if [ -n "$DST_PORT" ]; then 706e32a74aSDaniel T. Lee # Single destination port or random port range 716e32a74aSDaniel T. Lee pg_set $dev "flag UDPDST_RND" 72723d2904SDaniel T. Lee pg_set $dev "udp_dst_min $UDP_DST_MIN" 73723d2904SDaniel T. Lee pg_set $dev "udp_dst_max $UDP_DST_MAX" 746e32a74aSDaniel T. Lee fi 756e32a74aSDaniel T. Lee 76460a9aa2SLorenzo Bianconi [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM" 77460a9aa2SLorenzo Bianconi 781d73ba16SJesper Dangaard Brouer # Setup burst, for easy testing -b 0 disable bursting 791d73ba16SJesper Dangaard Brouer # (internally in pktgen default and minimum burst=1) 801d73ba16SJesper Dangaard Brouer if [[ ${BURST} -ne 0 ]]; then 811d73ba16SJesper Dangaard Brouer pg_set $dev "burst $BURST" 821d73ba16SJesper Dangaard Brouer else 831d73ba16SJesper Dangaard Brouer info "$dev: Not using burst" 841d73ba16SJesper Dangaard Brouer fi 851d73ba16SJesper Dangaard Brouerdone 861d73ba16SJesper Dangaard Brouer 871d73ba16SJesper Dangaard Brouer# Run if user hits control-c 88*c0e9422cSJuhee Kangfunction print_result() { 891d73ba16SJesper Dangaard Brouer # Print results 90e0e16672STariq Toukan for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do 911d73ba16SJesper Dangaard Brouer dev=${DEV}@${thread} 921d73ba16SJesper Dangaard Brouer echo "Device: $dev" 931d73ba16SJesper Dangaard Brouer cat /proc/net/pktgen/$dev | grep -A2 "Result:" 941d73ba16SJesper Dangaard Brouer done 951d73ba16SJesper Dangaard Brouer} 961d73ba16SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C) 97*c0e9422cSJuhee Kangtrap true SIGINT 981d73ba16SJesper Dangaard Brouer 99c8fd4852SIgor Russkikhif [ -z "$APPEND" ]; then 1001d73ba16SJesper Dangaard Brouer echo "Running... ctrl^C to stop" >&2 1011d73ba16SJesper Dangaard Brouer pg_ctrl "start" 102*c0e9422cSJuhee Kang 103*c0e9422cSJuhee Kang print_result 104c8fd4852SIgor Russkikhelse 105c8fd4852SIgor Russkikh echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" 106c8fd4852SIgor Russkikhfi 107