pktgen_sample03_burst_single_flow.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. #
  3. # Script for max single flow performance
  4. # - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]
  5. #
  6. # Using pktgen "burst" option (use -b $N)
  7. # - To boost max performance
  8. # - Avail since: kernel v3.18
  9. # * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")
  10. # - This avoids writing the HW tailptr on every driver xmit
  11. # - The performance boost is impressive, see commit and blog [2]
  12. #
  13. # Notice: On purpose generates a single (UDP) flow towards target,
  14. # reason behind this is to only overload/activate a single CPU on
  15. # target host. And no randomness for pktgen also makes it faster.
  16. #
  17. # Tuning see:
  18. # [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
  19. # [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html
  20. #
  21. basedir=`dirname $0`
  22. source ${basedir}/functions.sh
  23. root_check_run_with_sudo "$@"
  24. # Parameter parsing via include
  25. source ${basedir}/parameters.sh
  26. # Set some default params, if they didn't get set
  27. if [ -z "$DEST_IP" ]; then
  28. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  29. fi
  30. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  31. [ -z "$BURST" ] && BURST=32
  32. [ -z "$CLONE_SKB" ] && CLONE_SKB="100000"
  33. # Base Config
  34. DELAY="0" # Zero means max speed
  35. COUNT="0" # Zero means indefinitely
  36. # General cleanup everything since last run
  37. pg_ctrl "reset"
  38. # Threads are specified with parameter -t value in $THREADS
  39. for ((thread = 0; thread < $THREADS; thread++)); do
  40. dev=${DEV}@${thread}
  41. # Add remove all other devices and add_device $dev to thread
  42. pg_thread $thread "rem_device_all"
  43. pg_thread $thread "add_device" $dev
  44. # Base config
  45. pg_set $dev "flag QUEUE_MAP_CPU"
  46. pg_set $dev "count $COUNT"
  47. pg_set $dev "clone_skb $CLONE_SKB"
  48. pg_set $dev "pkt_size $PKT_SIZE"
  49. pg_set $dev "delay $DELAY"
  50. pg_set $dev "flag NO_TIMESTAMP"
  51. # Destination
  52. pg_set $dev "dst_mac $DST_MAC"
  53. pg_set $dev "dst$IP6 $DEST_IP"
  54. # Setup burst, for easy testing -b 0 disable bursting
  55. # (internally in pktgen default and minimum burst=1)
  56. if [[ ${BURST} -ne 0 ]]; then
  57. pg_set $dev "burst $BURST"
  58. else
  59. info "$dev: Not using burst"
  60. fi
  61. done
  62. # Run if user hits control-c
  63. function control_c() {
  64. # Print results
  65. for ((thread = 0; thread < $THREADS; thread++)); do
  66. dev=${DEV}@${thread}
  67. echo "Device: $dev"
  68. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  69. done
  70. }
  71. # trap keyboard interrupt (Ctrl-C)
  72. trap control_c SIGINT
  73. echo "Running... ctrl^C to stop" >&2
  74. pg_ctrl "start"