Skip to contentSkip to conversation

pktgen: scripts improvements

PATCH Superseded Igor Russkikh 2 participants 6 messages Feb 11, 2021 – Feb 12, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover pktgen: scripts improvements

Hello netdev community,

Please consider small improvements to pktgen scripts we use in our environment.

Adding delay parameter through command line, Adding new -a (append) parameter to make flex runs

v2: Review comments from Jesper

CC Jesper Dangaard Brouer <[email protected]>

Igor Russkikh (2):
samples: pktgen: allow to specify delay parameter via new opt
samples: pktgen: new append mode

 samples/pktgen/README.rst                     | 18 +++++++++++
 samples/pktgen/functions.sh                   |  7 ++++-
 samples/pktgen/parameters.sh                  | 15 ++++++++-
 .../pktgen_bench_xmit_mode_netif_receive.sh   |  3 --
 .../pktgen_bench_xmit_mode_queue_xmit.sh      |  3 --
 samples/pktgen/pktgen_sample01_simple.sh      | 25 ++++++++-------
 samples/pktgen/pktgen_sample02_multiqueue.sh  | 29 +++++++++--------
 .../pktgen_sample03_burst_single_flow.sh      | 15 ++++-----
 samples/pktgen/pktgen_sample04_many_flows.sh  | 17 +++++-----
 .../pktgen/pktgen_sample05_flow_per_thread.sh | 17 +++++-----
 ...sample06_numa_awared_queue_irq_affinity.sh | 31 ++++++++++---------
 11 files changed, 110 insertions(+), 70 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 samples: pktgen: allow to specify delay parameter via new opt

DELAY may now be explicitly specified via common parameter -w

---
 samples/pktgen/parameters.sh                           | 10 +++++++++-
 samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh |  3 ---
 samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh    |  3 ---
 samples/pktgen/pktgen_sample01_simple.sh               |  3 ---
 samples/pktgen/pktgen_sample02_multiqueue.sh           |  1 -
 samples/pktgen/pktgen_sample03_burst_single_flow.sh    |  3 ---
 samples/pktgen/pktgen_sample04_many_flows.sh           |  3 ---
 samples/pktgen/pktgen_sample05_flow_per_thread.sh      |  3 ---
 .../pktgen_sample06_numa_awared_queue_irq_affinity.sh  |  1 -
 9 files changed, 9 insertions(+), 21 deletions(-)
samples/pktgen/parameters.sh +9 -1
index ff0ed474fee9..70cc2878d479 100644
@@ -19,12 +19,13 @@ function usage() {
     echo "  -v : (\$VERBOSE)   verbose"
     echo "  -x : (\$DEBUG)     debug"
     echo "  -6 : (\$IP6)       IPv6"
+    echo "  -w : (\$DELAY)     Tx Delay value (us)"
     echo ""
 }
 
 ##  --- Parse command line arguments / parameters ---
 ## echo "Commandline options:"
-while getopts "s:i:d:m:p:f:t:c:n:b:vxh6" option; do
+while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6" option; do
     case $option in
         i) # interface
           export DEV=$OPTARG
@@ -66,6 +67,10 @@ while getopts "s:i:d:m:p:f:t:c:n:b:vxh6" option; do
 	  export BURST=$OPTARG
 	  info "SKB bursting: BURST=$BURST"
           ;;
+        w)
+	  export DELAY=$OPTARG
+	  info "DELAY=$DELAY"
+          ;;
         v)
           export VERBOSE=yes
           info "Verbose mode: VERBOSE=$VERBOSE"
@@ -100,6 +105,9 @@ if [ -z "$THREADS" ]; then
     export THREADS=1
 fi
 
+# default DELAY
+[ -z "$DELAY" ] && export DELAY=0 # Zero means max speed
+
 export L_THREAD=$(( THREADS + F_THREAD - 1 ))
 
 if [ -z "$DEV" ]; then
samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh +0 -3
index 1b6204125d2d..30a610b541ad 100755
@@ -50,9 +50,6 @@ if [ -n "$DST_PORT" ]; then
     validate_ports $UDP_DST_MIN $UDP_DST_MAX
 fi
 
-# Base Config
-DELAY="0"        # Zero means max speed
-
 # General cleanup everything since last run
 pg_ctrl "reset"
 
samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh +0 -3
index e607cb369b20..a6195bd77532 100755
@@ -33,9 +33,6 @@ if [ -n "$DST_PORT" ]; then
     validate_ports $UDP_DST_MIN $UDP_DST_MAX
 fi
 
-# Base Config
-DELAY="0"        # Zero means max speed
-
 # General cleanup everything since last run
 pg_ctrl "reset"
 
samples/pktgen/pktgen_sample01_simple.sh +0 -3
index a4e250b45dce..c2ad1fa32d3f 100755
@@ -31,9 +31,6 @@ if [ -n "$DST_PORT" ]; then
     validate_ports $UDP_DST_MIN $UDP_DST_MAX
 fi
 
-# Base Config
-DELAY="0"        # Zero means max speed
-
 # Flow variation random source port between min and max
 UDP_SRC_MIN=9
 UDP_SRC_MAX=109
samples/pktgen/pktgen_sample02_multiqueue.sh +0 -1
index cb2495fcdc60..49e1e81a2945 100755
@@ -17,7 +17,6 @@ source ${basedir}/parameters.sh
 [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
 
 # Base Config
-DELAY="0"        # Zero means max speed
 [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
 
 # Flow variation random source port between min and max
samples/pktgen/pktgen_sample03_burst_single_flow.sh +0 -3
index fff50765a5aa..f9b67affb567 100755
@@ -42,9 +42,6 @@ if [ -n "$DST_PORT" ]; then
     validate_ports $UDP_DST_MIN $UDP_DST_MAX
 fi
 
-# Base Config
-DELAY="0"  # Zero means max speed
-
 # General cleanup everything since last run
 pg_ctrl "reset"
 
samples/pktgen/pktgen_sample04_many_flows.sh +0 -3
index 2cd6b701400d..ac2d037a6160 100755
@@ -34,9 +34,6 @@ fi
 [ -z "$FLOWS" ]     && FLOWS="8000"
 [ -z "$FLOWLEN" ]   && FLOWLEN="10"
 
-# Base Config
-DELAY="0"  # Zero means max speed
-
 if [[ -n "$BURST" ]]; then
     err 1 "Bursting not supported for this mode"
 fi
samples/pktgen/pktgen_sample05_flow_per_thread.sh +0 -3
index 4cb6252ade39..85256484c86f 100755
@@ -31,9 +31,6 @@ if [ -n "$DST_PORT" ]; then
     validate_ports $UDP_DST_MIN $UDP_DST_MAX
 fi
 
-# Base Config
-DELAY="0"  # Zero means max speed
-
 # General cleanup everything since last run
 pg_ctrl "reset"
 
samples/pktgen/pktgen_sample06_numa_awared_queue_irq_affinity.sh +0 -1
index 728106060a02..7c73ab8fbe3c 100755
@@ -15,7 +15,6 @@ root_check_run_with_sudo "$@"
 source ${basedir}/parameters.sh
 
 # Base Config
-DELAY="0"        # Zero means max speed
 [ -z "$COUNT" ]     && COUNT="20000000"   # Zero means indefinitely
 [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
 
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 net-next 1/2] samples: pktgen: allow to specify delay parameter via new opt

samples/pktgen/parameters.sh function usage() { · line 22

Quoted 9 lines · On Thu, 11 Feb 2021 16:56:25 +0100 Igor Russkikh <[email protected]> wrote:
samples/pktgen/parameters.sh +1 -0
index ff0ed474fee9..70cc2878d479 100644
@@ -19,12 +19,13 @@ function usage() {
     echo "  -v : (\$VERBOSE)   verbose"
     echo "  -x : (\$DEBUG)     debug"
     echo "  -6 : (\$IP6)       IPv6"
+    echo "  -w : (\$DELAY)     Tx Delay value (us)"

This is not in "us" it is in "ns" (nanosec). (Like I pointed out last time...)

Quoted 2 lines
samples/pktgen/parameters.sh +0 -0
     echo ""
 }
Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
#3 lore raw

RE: [EXT] Re: [PATCH v2 net-next 1/2] samples: pktgen: allow to specify delay parameter via new opt

Quoted 2 lines
Quoted 1 line

+ echo " -w : (\$DELAY) Tx Delay value (us)"

This is not in "us" it is in "ns" (nanosec). (Like I pointed out last time...)

Ah, sorry lost that. Will fix.

One extra thing I wanted to raise is "set -o errexit" in functions.sh. It basically contradicts with the usecase I'm using (doing source ./functions.sh). After that, any error in current shell makes it to quit.

Honestly, for my tests, I do always disable that line.

Igor

#4 lore raw

Re: [EXT] Re: [PATCH v2 net-next 1/2] samples: pktgen: allow to specify delay parameter via new opt

Quoted 4 lines · On Thu, 11 Feb 2021 17:39:35 +0000 Igor Russkikh <[email protected]> wrote:
Quoted 2 lines
Quoted 1 line

+ echo " -w : (\$DELAY) Tx Delay value (us)"

This is not in "us" it is in "ns" (nanosec). (Like I pointed out last time...)

Ah, sorry lost that. Will fix.

Also remember that you made similar mistake in next patch. When adding documentation in samples/pktgen/README.rst. Strictly speaking, the doc update for DELAY belongs in patch-1.

Quoted 3 lines

One extra thing I wanted to raise is "set -o errexit" in functions.sh. It basically contradicts with the usecase I'm using (doing source ./functions.sh). After that, any error in current shell makes it to quit.

Cc. Daniel T. Lee, can you remember why this 'errexit' was added?

Quoted 1 line

Honestly, for my tests, I do always disable that line.

In your shell script, using "append", you can disable that shell feature in your script (instead of removing the line from functions.sh).

Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
#5 lore raw

PATCH v2 2/2 samples: pktgen: new append mode

In reply to Igor Russkikh

To configure various complex flows we for sure can create custom pktgen init scripts, but sometimes thats not that easy.

New "-a" (append) option in all the existing sample scripts allows to append more "devices" into pktgen threads.

The most straightforward usecases for that are:
- using multiple devices. We have to generate full linerate on all physical functions (ports) of our multiport device.
- pushing multiple flows (with different packet options)

---
 samples/pktgen/README.rst                     | 18 +++++++++++
 samples/pktgen/functions.sh                   |  7 ++++-
 samples/pktgen/parameters.sh                  |  7 ++++-
 samples/pktgen/pktgen_sample01_simple.sh      | 22 ++++++++------
 samples/pktgen/pktgen_sample02_multiqueue.sh  | 28 +++++++++--------
 .../pktgen_sample03_burst_single_flow.sh      | 12 +++++---
 samples/pktgen/pktgen_sample04_many_flows.sh  | 14 +++++----
 .../pktgen/pktgen_sample05_flow_per_thread.sh | 14 +++++----
 ...sample06_numa_awared_queue_irq_affinity.sh | 30 +++++++++++--------
 9 files changed, 102 insertions(+), 50 deletions(-)
samples/pktgen/README.rst +18 -0
index f9c53ca5cf93..e1615bbfd386 100644
@@ -28,10 +28,28 @@ across the sample scripts.  Usage example is printed on errors::
   -b : ($BURST)     HW level bursting of SKBs
   -v : ($VERBOSE)   verbose
   -x : ($DEBUG)     debug
+  -6 : ($IP6)       IPv6
+  -w : ($DELAY)     Tx Delay value (us)
+  -a : ($APPEND)    Script will not reset generator's state, but will append its config
 
 The global variable being set is also listed.  E.g. the required
 interface/device parameter "-i" sets variable $DEV.
 
+"-a" parameter may be used to create different flows simultaneously.
+In this mode script will keep the existing config, will append its settings.
+In this mode you'll have to manually run traffic with "pg_ctrl start".
+
+For example you may use:
+
+    source ./samples/pktgen/functions.sh
+    pg_ctrl reset
+    # add first device
+    ./pktgen_sample06_numa_awared_queue_irq_affinity.sh -a -i ens1f0 -m 34:80:0d:a3:fc:c9 -t 8
+    # add second device
+    ./pktgen_sample06_numa_awared_queue_irq_affinity.sh -a -i ens1f1 -m 34:80:0d:a3:fc:c9 -t 8
+    # run joint traffic on two devs
+    pg_ctrl start
+
 Common functions
 ----------------
 The functions.sh file provides; Three different shell functions for
samples/pktgen/functions.sh +6 -1
index dae06d5b38fa..a335393157eb 100644
@@ -108,7 +108,12 @@ function pgset() {
     fi
 }
 
-[[ $EUID -eq 0 ]] && trap 'pg_ctrl "reset"' EXIT
+if [[ -z "$APPEND" ]]; then
+	if [[ $EUID -eq 0 ]]; then
+		# Cleanup pktgen setup on exit if thats not "append mode"
+		trap 'pg_ctrl "reset"' EXIT
+	fi
+fi
 
 ## -- General shell tricks --
 
samples/pktgen/parameters.sh +6 -1
index 70cc2878d479..d88c450d3f75 100644
@@ -20,12 +20,13 @@ function usage() {
     echo "  -x : (\$DEBUG)     debug"
     echo "  -6 : (\$IP6)       IPv6"
     echo "  -w : (\$DELAY)     Tx Delay value (us)"
+    echo "  -a : (\$APPEND)    Script will not reset generator's state, but will append its config"
     echo ""
 }
 
 ##  --- Parse command line arguments / parameters ---
 ## echo "Commandline options:"
-while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6" option; do
+while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6a" option; do
     case $option in
         i) # interface
           export DEV=$OPTARG
@@ -83,6 +84,10 @@ while getopts "s:i:d:m:p:f:t:c:n:b:w:vxh6" option; do
 	  export IP6=6
 	  info "IP6: IP6=$IP6"
 	  ;;
+        a)
+          export APPEND=yes
+          info "Append mode: APPEND=$APPEND"
+          ;;
         h|?|*)
           usage;
           err 2 "[ERROR] Unknown parameters!!!"
samples/pktgen/pktgen_sample01_simple.sh +13 -9
index c2ad1fa32d3f..a09f3422fbcc 100755
@@ -37,11 +37,11 @@ UDP_SRC_MAX=109
 
 # General cleanup everything since last run
 # (especially important if other threads were configured by other scripts)
-pg_ctrl "reset"
+[ -z "$APPEND" ] && pg_ctrl "reset"
 
 # Add remove all other devices and add_device $DEV to thread 0
 thread=0
-pg_thread $thread "rem_device_all"
+[ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
 pg_thread $thread "add_device" $DEV
 
 # How many packets to send (zero means indefinitely)
@@ -77,11 +77,15 @@ pg_set $DEV "flag UDPSRC_RND"
 pg_set $DEV "udp_src_min $UDP_SRC_MIN"
 pg_set $DEV "udp_src_max $UDP_SRC_MAX"
 
-# start_run
-echo "Running... ctrl^C to stop" >&2
-pg_ctrl "start"
-echo "Done" >&2
+if [ -z "$APPEND" ]; then
+    # start_run
+    echo "Running... ctrl^C to stop" >&2
+    pg_ctrl "start"
+    echo "Done" >&2
 
-# Print results
-echo "Result device: $DEV"
-cat /proc/net/pktgen/$DEV
+    # Print results
+    echo "Result device: $DEV"
+    cat /proc/net/pktgen/$DEV
+else
+    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
+fi
\ No newline at end of file
samples/pktgen/pktgen_sample02_multiqueue.sh +16 -12
index 49e1e81a2945..acae8ede0d6c 100755
@@ -38,7 +38,7 @@ if [ -n "$DST_PORT" ]; then
 fi
 
 # General cleanup everything since last run
-pg_ctrl "reset"
+[ -z "$APPEND" ] && pg_ctrl "reset"
 
 # Threads are specified with parameter -t value in $THREADS
 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
@@ -47,7 +47,7 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
     dev=${DEV}@${thread}
 
     # Add remove all other devices and add_device $dev to thread
-    pg_thread $thread "rem_device_all"
+    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
     pg_thread $thread "add_device" $dev
 
     # Notice config queue to map to cpu (mirrors smp_processor_id())
@@ -81,14 +81,18 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
     pg_set $dev "udp_src_max $UDP_SRC_MAX"
 done
 
-# start_run
-echo "Running... ctrl^C to stop" >&2
-pg_ctrl "start"
-echo "Done" >&2
+if [ -z "$APPEND" ]; then
+    # start_run
+    echo "Running... ctrl^C to stop" >&2
+    pg_ctrl "start"
+    echo "Done" >&2
 
-# Print results
-for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
-    dev=${DEV}@${thread}
-    echo "Device: $dev"
-    cat /proc/net/pktgen/$dev | grep -A2 "Result:"
-done
+    # Print results
+    for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
+        dev=${DEV}@${thread}
+        echo "Device: $dev"
+        cat /proc/net/pktgen/$dev | grep -A2 "Result:"
+    done
+else
+    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
+fi
samples/pktgen/pktgen_sample03_burst_single_flow.sh +8 -4
index f9b67affb567..5adcf954de73 100755
@@ -43,14 +43,14 @@ if [ -n "$DST_PORT" ]; then
 fi
 
 # General cleanup everything since last run
-pg_ctrl "reset"
+[ -z "$APPEND" ] && pg_ctrl "reset"
 
 # Threads are specified with parameter -t value in $THREADS
 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
     dev=${DEV}@${thread}
 
     # Add remove all other devices and add_device $dev to thread
-    pg_thread $thread "rem_device_all"
+    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
     pg_thread $thread "add_device" $dev
 
     # Base config
@@ -94,5 +94,9 @@ function control_c() {
 # trap keyboard interrupt (Ctrl-C)
 trap control_c SIGINT
 
-echo "Running... ctrl^C to stop" >&2
-pg_ctrl "start"
+if [ -z "$APPEND" ]; then
+    echo "Running... ctrl^C to stop" >&2
+    pg_ctrl "start"
+else
+    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
+fi
samples/pktgen/pktgen_sample04_many_flows.sh +9 -5
index ac2d037a6160..ddce876635aa 100755
@@ -42,14 +42,14 @@ fi
 read -r SRC_MIN SRC_MAX <<< $(parse_addr 198.18.0.0/15)
 
 # General cleanup everything since last run
-pg_ctrl "reset"
+[ -z "$APPEND" ] && pg_ctrl "reset"
 
 # Threads are specified with parameter -t value in $THREADS
 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
     dev=${DEV}@${thread}
 
     # Add remove all other devices and add_device $dev to thread
-    pg_thread $thread "rem_device_all"
+    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
     pg_thread $thread "add_device" $dev
 
     # Base config
@@ -104,7 +104,11 @@ function print_result() {
 # trap keyboard interrupt (Ctrl-C)
 trap true SIGINT
 
-echo "Running... ctrl^C to stop" >&2
-pg_ctrl "start"
+if [ -z "$APPEND" ]; then
+    echo "Running... ctrl^C to stop" >&2
+    pg_ctrl "start"
 
-print_result
+    print_result
+else
+    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
+fi
samples/pktgen/pktgen_sample05_flow_per_thread.sh +9 -5
index 85256484c86f..4a65fe2fcee9 100755
@@ -32,14 +32,14 @@ if [ -n "$DST_PORT" ]; then
 fi
 
 # General cleanup everything since last run
-pg_ctrl "reset"
+[ -z "$APPEND" ] && pg_ctrl "reset"
 
 # Threads are specified with parameter -t value in $THREADS
 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
     dev=${DEV}@${thread}
 
     # Add remove all other devices and add_device $dev to thread
-    pg_thread $thread "rem_device_all"
+    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
     pg_thread $thread "add_device" $dev
 
     # Base config
@@ -88,7 +88,11 @@ function print_result() {
 # trap keyboard interrupt (Ctrl-C)
 trap true SIGINT
 
-echo "Running... ctrl^C to stop" >&2
-pg_ctrl "start"
+if [ -z "$APPEND" ]; then
+    echo "Running... ctrl^C to stop" >&2
+    pg_ctrl "start"
 
-print_result
+    print_result
+else
+    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
+fi
samples/pktgen/pktgen_sample06_numa_awared_queue_irq_affinity.sh +17 -13
index 7c73ab8fbe3c..10f1da571f40 100755
@@ -44,7 +44,7 @@ if [ -n "$DST_PORT" ]; then
 fi
 
 # General cleanup everything since last run
-pg_ctrl "reset"
+[ -z "$APPEND" ] && pg_ctrl "reset"
 
 # Threads are specified with parameter -t value in $THREADS
 for ((i = 0; i < $THREADS; i++)); do
@@ -58,7 +58,7 @@ for ((i = 0; i < $THREADS; i++)); do
     info "irq ${irq_array[$i]} is set affinity to `cat /proc/irq/${irq_array[$i]}/smp_affinity_list`"
 
     # Add remove all other devices and add_device $dev to thread
-    pg_thread $thread "rem_device_all"
+    [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
     pg_thread $thread "add_device" $dev
 
     # select queue and bind the queue and $dev in 1:1 relationship
@@ -99,14 +99,18 @@ for ((i = 0; i < $THREADS; i++)); do
 done
 
 # start_run
-echo "Running... ctrl^C to stop" >&2
-pg_ctrl "start"
-echo "Done" >&2
-
-# Print results
-for ((i = 0; i < $THREADS; i++)); do
-    thread=${cpu_array[$((i+F_THREAD))]}
-    dev=${DEV}@${thread}
-    echo "Device: $dev"
-    cat /proc/net/pktgen/$dev | grep -A2 "Result:"
-done
+if [ -z "$APPEND" ]; then
+    echo "Running... ctrl^C to stop" >&2
+    pg_ctrl "start"
+    echo "Done" >&2
+
+    # Print results
+    for ((i = 0; i < $THREADS; i++)); do
+        thread=${cpu_array[$((i+F_THREAD))]}
+        dev=${DEV}@${thread}
+        echo "Device: $dev"
+        cat /proc/net/pktgen/$dev | grep -A2 "Result:"
+    done
+else
+    echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
+fi
Signature · 1 line
2.25.1