Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Benchmark script:
0005 #  - developed for benchmarking ingress qdisc path
0006 #
0007 # Script for injecting packets into RX path of the stack with pktgen
0008 # "xmit_mode netif_receive".  With an invalid dst_mac this will only
0009 # measure the ingress code path as packets gets dropped in ip_rcv().
0010 #
0011 # This script don't really need any hardware.  It benchmarks software
0012 # RX path just after NIC driver level.  With bursting is also
0013 # "removes" the SKB alloc/free overhead.
0014 #
0015 # Setup scenarios for measuring ingress qdisc (with invalid dst_mac):
0016 # ------------------------------------------------------------------
0017 # (1) no ingress (uses static_key_false(&ingress_needed))
0018 #
0019 # (2) ingress on other dev (change ingress_needed and calls
0020 #     handle_ing() but exit early)
0021 #
0022 #  config:  tc qdisc add dev $SOMEDEV handle ffff: ingress
0023 #
0024 # (3) ingress on this dev, handle_ing() -> tc_classify()
0025 #
0026 #  config:  tc qdisc add dev $DEV handle ffff: ingress
0027 #
0028 # (4) ingress on this dev + drop at u32 classifier/action.
0029 #
0030 basedir=`dirname $0`
0031 source ${basedir}/functions.sh
0032 root_check_run_with_sudo "$@"
0033 
0034 # Parameter parsing via include
0035 source ${basedir}/parameters.sh
0036 # Using invalid DST_MAC will cause the packets to get dropped in
0037 # ip_rcv() which is part of the test
0038 if [ -z "$DEST_IP" ]; then
0039     [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
0040 fi
0041 [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
0042 [ -z "$BURST" ] && BURST=1024
0043 [ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely
0044 if [ -n "$DEST_IP" ]; then
0045     validate_addr${IP6} $DEST_IP
0046     read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
0047 fi
0048 if [ -n "$DST_PORT" ]; then
0049     read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
0050     validate_ports $UDP_DST_MIN $UDP_DST_MAX
0051 fi
0052 
0053 # General cleanup everything since last run
0054 pg_ctrl "reset"
0055 
0056 # Threads are specified with parameter -t value in $THREADS
0057 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
0058     # The device name is extended with @name, using thread number to
0059     # make then unique, but any name will do.
0060     dev=${DEV}@${thread}
0061 
0062     # Add remove all other devices and add_device $dev to thread
0063     pg_thread $thread "rem_device_all"
0064     pg_thread $thread "add_device" $dev
0065 
0066     # Base config of dev
0067     pg_set $dev "flag QUEUE_MAP_CPU"
0068     pg_set $dev "count $COUNT"
0069     pg_set $dev "pkt_size $PKT_SIZE"
0070     pg_set $dev "delay $DELAY"
0071     pg_set $dev "flag NO_TIMESTAMP"
0072 
0073     # Destination
0074     pg_set $dev "dst_mac $DST_MAC"
0075     pg_set $dev "dst${IP6}_min $DST_MIN"
0076     pg_set $dev "dst${IP6}_max $DST_MAX"
0077 
0078     if [ -n "$DST_PORT" ]; then
0079         # Single destination port or random port range
0080         pg_set $dev "flag UDPDST_RND"
0081         pg_set $dev "udp_dst_min $UDP_DST_MIN"
0082         pg_set $dev "udp_dst_max $UDP_DST_MAX"
0083     fi
0084 
0085     # Inject packet into RX path of stack
0086     pg_set $dev "xmit_mode netif_receive"
0087 
0088     # Burst allow us to avoid measuring SKB alloc/free overhead
0089     pg_set $dev "burst $BURST"
0090 done
0091 
0092 # Run if user hits control-c
0093 function print_result() {
0094     # Print results
0095     for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
0096         dev=${DEV}@${thread}
0097         echo "Device: $dev"
0098         cat /proc/net/pktgen/$dev | grep -A2 "Result:"
0099     done
0100 }
0101 # trap keyboard interrupt (Ctrl-C)
0102 trap true SIGINT
0103 
0104 # start_run
0105 echo "Running... ctrl^C to stop" >&2
0106 pg_ctrl "start"
0107 echo "Done" >&2
0108 
0109 print_result