Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Script for max single flow performance
0005 #  - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]
0006 #
0007 # Using pktgen "burst" option (use -b $N)
0008 #  - To boost max performance
0009 #  - Avail since: kernel v3.18
0010 #   * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")
0011 #  - This avoids writing the HW tailptr on every driver xmit
0012 #  - The performance boost is impressive, see commit and blog [2]
0013 #
0014 # Notice: On purpose generates a single (UDP) flow towards target,
0015 #   reason behind this is to only overload/activate a single CPU on
0016 #   target host.  And no randomness for pktgen also makes it faster.
0017 #
0018 # Tuning see:
0019 #  [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
0020 #  [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html
0021 #
0022 basedir=`dirname $0`
0023 source ${basedir}/functions.sh
0024 root_check_run_with_sudo "$@"
0025 
0026 # Parameter parsing via include
0027 source ${basedir}/parameters.sh
0028 # Set some default params, if they didn't get set
0029 if [ -z "$DEST_IP" ]; then
0030     [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
0031 fi
0032 [ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
0033 [ -z "$BURST" ]     && BURST=32
0034 [ -z "$CLONE_SKB" ] && CLONE_SKB="0" # No need for clones when bursting
0035 [ -z "$COUNT" ]     && COUNT="0" # Zero means indefinitely
0036 if [ -n "$DEST_IP" ]; then
0037     validate_addr${IP6} $DEST_IP
0038     read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
0039 fi
0040 if [ -n "$DST_PORT" ]; then
0041     read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
0042     validate_ports $UDP_DST_MIN $UDP_DST_MAX
0043 fi
0044 
0045 # General cleanup everything since last run
0046 [ -z "$APPEND" ] && pg_ctrl "reset"
0047 
0048 # Threads are specified with parameter -t value in $THREADS
0049 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
0050     dev=${DEV}@${thread}
0051 
0052     # Add remove all other devices and add_device $dev to thread
0053     [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
0054     pg_thread $thread "add_device" $dev
0055 
0056     # Base config
0057     pg_set $dev "flag QUEUE_MAP_CPU"
0058     pg_set $dev "count $COUNT"
0059     pg_set $dev "clone_skb $CLONE_SKB"
0060     pg_set $dev "pkt_size $PKT_SIZE"
0061     pg_set $dev "delay $DELAY"
0062     pg_set $dev "flag NO_TIMESTAMP"
0063 
0064     # Destination
0065     pg_set $dev "dst_mac $DST_MAC"
0066     pg_set $dev "dst${IP6}_min $DST_MIN"
0067     pg_set $dev "dst${IP6}_max $DST_MAX"
0068 
0069     if [ -n "$DST_PORT" ]; then
0070         # Single destination port or random port range
0071         pg_set $dev "flag UDPDST_RND"
0072         pg_set $dev "udp_dst_min $UDP_DST_MIN"
0073         pg_set $dev "udp_dst_max $UDP_DST_MAX"
0074     fi
0075 
0076     [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
0077 
0078     # Setup burst, for easy testing -b 0 disable bursting
0079     # (internally in pktgen default and minimum burst=1)
0080     if [[ ${BURST} -ne 0 ]]; then
0081         pg_set $dev "burst $BURST"
0082     else
0083         info "$dev: Not using burst"
0084     fi
0085 done
0086 
0087 # Run if user hits control-c
0088 function print_result() {
0089     # Print results
0090     for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
0091         dev=${DEV}@${thread}
0092         echo "Device: $dev"
0093         cat /proc/net/pktgen/$dev | grep -A2 "Result:"
0094     done
0095 }
0096 # trap keyboard interrupt (Ctrl-C)
0097 trap true SIGINT
0098 
0099 if [ -z "$APPEND" ]; then
0100     echo "Running... ctrl^C to stop" >&2
0101     pg_ctrl "start"
0102 
0103     print_result
0104 else
0105     echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
0106 fi