xref: /linux/samples/pktgen/pktgen_sample03_burst_single_flow.sh (revision 6e32a74a6f151c3e64d7d79e54948b8938be2cdc)
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
36*6e32a74aSDaniel T. Leeif [ -n "$DST_PORT" ]; then
37*6e32a74aSDaniel T. Lee    read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT)
38*6e32a74aSDaniel T. Lee    validate_ports $DST_MIN $DST_MAX
39*6e32a74aSDaniel T. Leefi
401d73ba16SJesper Dangaard Brouer
411d73ba16SJesper Dangaard Brouer# Base Config
421d73ba16SJesper Dangaard BrouerDELAY="0"  # Zero means max speed
431d73ba16SJesper Dangaard Brouer
441d73ba16SJesper Dangaard Brouer# General cleanup everything since last run
451d73ba16SJesper Dangaard Brouerpg_ctrl "reset"
461d73ba16SJesper Dangaard Brouer
471d73ba16SJesper Dangaard Brouer# Threads are specified with parameter -t value in $THREADS
48e0e16672STariq Toukanfor ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
491d73ba16SJesper Dangaard Brouer    dev=${DEV}@${thread}
501d73ba16SJesper Dangaard Brouer
511d73ba16SJesper Dangaard Brouer    # Add remove all other devices and add_device $dev to thread
521d73ba16SJesper Dangaard Brouer    pg_thread $thread "rem_device_all"
531d73ba16SJesper Dangaard Brouer    pg_thread $thread "add_device" $dev
541d73ba16SJesper Dangaard Brouer
551d73ba16SJesper Dangaard Brouer    # Base config
561d73ba16SJesper Dangaard Brouer    pg_set $dev "flag QUEUE_MAP_CPU"
571d73ba16SJesper Dangaard Brouer    pg_set $dev "count $COUNT"
581d73ba16SJesper Dangaard Brouer    pg_set $dev "clone_skb $CLONE_SKB"
591d73ba16SJesper Dangaard Brouer    pg_set $dev "pkt_size $PKT_SIZE"
601d73ba16SJesper Dangaard Brouer    pg_set $dev "delay $DELAY"
611d73ba16SJesper Dangaard Brouer    pg_set $dev "flag NO_TIMESTAMP"
621d73ba16SJesper Dangaard Brouer
631d73ba16SJesper Dangaard Brouer    # Destination
641d73ba16SJesper Dangaard Brouer    pg_set $dev "dst_mac $DST_MAC"
650f06a678SMartin KaFai Lau    pg_set $dev "dst$IP6 $DEST_IP"
661d73ba16SJesper Dangaard Brouer
67*6e32a74aSDaniel T. Lee    if [ -n "$DST_PORT" ]; then
68*6e32a74aSDaniel T. Lee	# Single destination port or random port range
69*6e32a74aSDaniel T. Lee	pg_set $dev "flag UDPDST_RND"
70*6e32a74aSDaniel T. Lee	pg_set $dev "udp_dst_min $DST_MIN"
71*6e32a74aSDaniel T. Lee	pg_set $dev "udp_dst_max $DST_MAX"
72*6e32a74aSDaniel T. Lee    fi
73*6e32a74aSDaniel T. Lee
741d73ba16SJesper Dangaard Brouer    # Setup burst, for easy testing -b 0 disable bursting
751d73ba16SJesper Dangaard Brouer    # (internally in pktgen default and minimum burst=1)
761d73ba16SJesper Dangaard Brouer    if [[ ${BURST} -ne 0 ]]; then
771d73ba16SJesper Dangaard Brouer	pg_set $dev "burst $BURST"
781d73ba16SJesper Dangaard Brouer    else
791d73ba16SJesper Dangaard Brouer	info "$dev: Not using burst"
801d73ba16SJesper Dangaard Brouer    fi
811d73ba16SJesper Dangaard Brouerdone
821d73ba16SJesper Dangaard Brouer
831d73ba16SJesper Dangaard Brouer# Run if user hits control-c
841d73ba16SJesper Dangaard Brouerfunction control_c() {
851d73ba16SJesper Dangaard Brouer    # Print results
86e0e16672STariq Toukan    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
871d73ba16SJesper Dangaard Brouer	dev=${DEV}@${thread}
881d73ba16SJesper Dangaard Brouer	echo "Device: $dev"
891d73ba16SJesper Dangaard Brouer	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
901d73ba16SJesper Dangaard Brouer    done
911d73ba16SJesper Dangaard Brouer}
921d73ba16SJesper Dangaard Brouer# trap keyboard interrupt (Ctrl-C)
931d73ba16SJesper Dangaard Brouertrap control_c SIGINT
941d73ba16SJesper Dangaard Brouer
951d73ba16SJesper Dangaard Brouerecho "Running... ctrl^C to stop" >&2
961d73ba16SJesper Dangaard Brouerpg_ctrl "start"
97