Path: blob/master/samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
26285 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Benchmark script:4# - developed for benchmarking ingress qdisc path5#6# Script for injecting packets into RX path of the stack with pktgen7# "xmit_mode netif_receive". With an invalid dst_mac this will only8# measure the ingress code path as packets gets dropped in ip_rcv().9#10# This script don't really need any hardware. It benchmarks software11# RX path just after NIC driver level. With bursting is also12# "removes" the SKB alloc/free overhead.13#14# Setup scenarios for measuring ingress qdisc (with invalid dst_mac):15# ------------------------------------------------------------------16# (1) no ingress (uses static_key_false(&ingress_needed))17#18# (2) ingress on other dev (change ingress_needed and calls19# handle_ing() but exit early)20#21# config: tc qdisc add dev $SOMEDEV handle ffff: ingress22#23# (3) ingress on this dev, handle_ing() -> tc_classify()24#25# config: tc qdisc add dev $DEV handle ffff: ingress26#27# (4) ingress on this dev + drop at u32 classifier/action.28#29basedir=`dirname $0`30source ${basedir}/functions.sh31root_check_run_with_sudo "$@"3233# Parameter parsing via include34source ${basedir}/parameters.sh3536# Trap EXIT first37trap_exit3839# Using invalid DST_MAC will cause the packets to get dropped in40# ip_rcv() which is part of the test41if [ -z "$DEST_IP" ]; then42[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"43fi44[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"45[ -z "$BURST" ] && BURST=102446[ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely47if [ -n "$DEST_IP" ]; then48validate_addr${IP6} $DEST_IP49read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)50fi51if [ -n "$DST_PORT" ]; then52read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)53validate_ports $UDP_DST_MIN $UDP_DST_MAX54fi5556# General cleanup everything since last run57pg_ctrl "reset"5859# Threads are specified with parameter -t value in $THREADS60for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do61# The device name is extended with @name, using thread number to62# make then unique, but any name will do.63dev=${DEV}@${thread}6465# Add remove all other devices and add_device $dev to thread66pg_thread $thread "rem_device_all"67pg_thread $thread "add_device" $dev6869# Base config of dev70pg_set $dev "flag QUEUE_MAP_CPU"71pg_set $dev "count $COUNT"72pg_set $dev "pkt_size $PKT_SIZE"73pg_set $dev "delay $DELAY"74pg_set $dev "flag NO_TIMESTAMP"7576# Destination77pg_set $dev "dst_mac $DST_MAC"78pg_set $dev "dst${IP6}_min $DST_MIN"79pg_set $dev "dst${IP6}_max $DST_MAX"8081if [ -n "$DST_PORT" ]; then82# Single destination port or random port range83pg_set $dev "flag UDPDST_RND"84pg_set $dev "udp_dst_min $UDP_DST_MIN"85pg_set $dev "udp_dst_max $UDP_DST_MAX"86fi8788# Inject packet into RX path of stack89pg_set $dev "xmit_mode netif_receive"9091# Burst allow us to avoid measuring SKB alloc/free overhead92pg_set $dev "burst $BURST"93done9495# Run if user hits control-c96function print_result() {97# Print results98for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do99dev=${DEV}@${thread}100echo "Device: $dev"101cat /proc/net/pktgen/$dev | grep -A2 "Result:"102done103}104# trap keyboard interrupt (Ctrl-C)105trap true SIGINT106107# start_run108echo "Running... ctrl^C to stop" >&2109pg_ctrl "start"110echo "Done" >&2111112print_result113114115