114 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Benchmark script:5# - developed for benchmarking ingress qdisc path6#7# Script for injecting packets into RX path of the stack with pktgen8# "xmit_mode netif_receive". With an invalid dst_mac this will only9# measure the ingress code path as packets gets dropped in ip_rcv().10#11# This script don't really need any hardware. It benchmarks software12# RX path just after NIC driver level. With bursting is also13# "removes" the SKB alloc/free overhead.14#15# Setup scenarios for measuring ingress qdisc (with invalid dst_mac):16# ------------------------------------------------------------------17# (1) no ingress (uses static_key_false(&ingress_needed))18#19# (2) ingress on other dev (change ingress_needed and calls20# handle_ing() but exit early)21#22# config: tc qdisc add dev $SOMEDEV handle ffff: ingress23#24# (3) ingress on this dev, handle_ing() -> tc_classify()25#26# config: tc qdisc add dev $DEV handle ffff: ingress27#28# (4) ingress on this dev + drop at u32 classifier/action.29#30basedir=`dirname $0`31source ${basedir}/functions.sh32root_check_run_with_sudo "$@"33 34# Parameter parsing via include35source ${basedir}/parameters.sh36 37# Trap EXIT first38trap_exit39 40# Using invalid DST_MAC will cause the packets to get dropped in41# ip_rcv() which is part of the test42if [ -z "$DEST_IP" ]; then43 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"44fi45[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"46[ -z "$BURST" ] && BURST=102447[ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely48if [ -n "$DEST_IP" ]; then49 validate_addr${IP6} $DEST_IP50 read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)51fi52if [ -n "$DST_PORT" ]; then53 read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)54 validate_ports $UDP_DST_MIN $UDP_DST_MAX55fi56 57# General cleanup everything since last run58pg_ctrl "reset"59 60# Threads are specified with parameter -t value in $THREADS61for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do62 # The device name is extended with @name, using thread number to63 # make then unique, but any name will do.64 dev=${DEV}@${thread}65 66 # Add remove all other devices and add_device $dev to thread67 pg_thread $thread "rem_device_all"68 pg_thread $thread "add_device" $dev69 70 # Base config of dev71 pg_set $dev "flag QUEUE_MAP_CPU"72 pg_set $dev "count $COUNT"73 pg_set $dev "pkt_size $PKT_SIZE"74 pg_set $dev "delay $DELAY"75 pg_set $dev "flag NO_TIMESTAMP"76 77 # Destination78 pg_set $dev "dst_mac $DST_MAC"79 pg_set $dev "dst${IP6}_min $DST_MIN"80 pg_set $dev "dst${IP6}_max $DST_MAX"81 82 if [ -n "$DST_PORT" ]; then83 # Single destination port or random port range84 pg_set $dev "flag UDPDST_RND"85 pg_set $dev "udp_dst_min $UDP_DST_MIN"86 pg_set $dev "udp_dst_max $UDP_DST_MAX"87 fi88 89 # Inject packet into RX path of stack90 pg_set $dev "xmit_mode netif_receive"91 92 # Burst allow us to avoid measuring SKB alloc/free overhead93 pg_set $dev "burst $BURST"94done95 96# Run if user hits control-c97function print_result() {98 # Print results99 for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do100 dev=${DEV}@${thread}101 echo "Device: $dev"102 cat /proc/net/pktgen/$dev | grep -A2 "Result:"103 done104}105# trap keyboard interrupt (Ctrl-C)106trap true SIGINT107 108# start_run109echo "Running... ctrl^C to stop" >&2110pg_ctrl "start"111echo "Done" >&2112 113print_result114