pktgen_bench_xmit_mode_netif_receive.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Benchmark script:
  5. # - developed for benchmarking ingress qdisc path
  6. #
  7. # Script for injecting packets into RX path of the stack with pktgen
  8. # "xmit_mode netif_receive". With an invalid dst_mac this will only
  9. # measure the ingress code path as packets gets dropped in ip_rcv().
  10. #
  11. # This script don't really need any hardware. It benchmarks software
  12. # RX path just after NIC driver level. With bursting is also
  13. # "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 calls
  20. # handle_ing() but exit early)
  21. #
  22. # config: tc qdisc add dev $SOMEDEV handle ffff: ingress
  23. #
  24. # (3) ingress on this dev, handle_ing() -> tc_classify()
  25. #
  26. # config: tc qdisc add dev $DEV handle ffff: ingress
  27. #
  28. # (4) ingress on this dev + drop at u32 classifier/action.
  29. #
  30. basedir=`dirname $0`
  31. source ${basedir}/functions.sh
  32. root_check_run_with_sudo "$@"
  33. # Parameter parsing via include
  34. source ${basedir}/parameters.sh
  35. # Using invalid DST_MAC will cause the packets to get dropped in
  36. # ip_rcv() which is part of the test
  37. if [ -z "$DEST_IP" ]; then
  38. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  39. fi
  40. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  41. [ -z "$BURST" ] && BURST=1024
  42. [ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely
  43. if [ -n "$DEST_IP" ]; then
  44. validate_addr${IP6} $DEST_IP
  45. read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
  46. fi
  47. if [ -n "$DST_PORT" ]; then
  48. read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
  49. validate_ports $UDP_DST_MIN $UDP_DST_MAX
  50. fi
  51. # Base Config
  52. DELAY="0" # Zero means max speed
  53. # General cleanup everything since last run
  54. pg_ctrl "reset"
  55. # Threads are specified with parameter -t value in $THREADS
  56. for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
  57. # The device name is extended with @name, using thread number to
  58. # make then unique, but any name will do.
  59. dev=${DEV}@${thread}
  60. # Add remove all other devices and add_device $dev to thread
  61. pg_thread $thread "rem_device_all"
  62. pg_thread $thread "add_device" $dev
  63. # Base config of dev
  64. pg_set $dev "flag QUEUE_MAP_CPU"
  65. pg_set $dev "count $COUNT"
  66. pg_set $dev "pkt_size $PKT_SIZE"
  67. pg_set $dev "delay $DELAY"
  68. pg_set $dev "flag NO_TIMESTAMP"
  69. # Destination
  70. pg_set $dev "dst_mac $DST_MAC"
  71. pg_set $dev "dst${IP6}_min $DST_MIN"
  72. pg_set $dev "dst${IP6}_max $DST_MAX"
  73. if [ -n "$DST_PORT" ]; then
  74. # Single destination port or random port range
  75. pg_set $dev "flag UDPDST_RND"
  76. pg_set $dev "udp_dst_min $UDP_DST_MIN"
  77. pg_set $dev "udp_dst_max $UDP_DST_MAX"
  78. fi
  79. # Inject packet into RX path of stack
  80. pg_set $dev "xmit_mode netif_receive"
  81. # Burst allow us to avoid measuring SKB alloc/free overhead
  82. pg_set $dev "burst $BURST"
  83. done
  84. # start_run
  85. echo "Running... ctrl^C to stop" >&2
  86. pg_ctrl "start"
  87. echo "Done" >&2
  88. # Print results
  89. for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
  90. dev=${DEV}@${thread}
  91. echo "Device: $dev"
  92. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  93. done