pktgen_sample06_numa_awared_queue_irq_affinity.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. #
  3. # Multiqueue: Using pktgen threads for sending on multiple CPUs
  4. # * adding devices to kernel threads which are in the same NUMA node
  5. # * bound devices queue's irq affinity to the threads, 1:1 mapping
  6. # * notice the naming scheme for keeping device names unique
  7. # * nameing scheme: dev@thread_number
  8. # * flow variation via random UDP source port
  9. #
  10. basedir=`dirname $0`
  11. source ${basedir}/functions.sh
  12. root_check_run_with_sudo "$@"
  13. #
  14. # Required param: -i dev in $DEV
  15. source ${basedir}/parameters.sh
  16. # Base Config
  17. DELAY="0" # Zero means max speed
  18. [ -z "$COUNT" ] && COUNT="20000000" # Zero means indefinitely
  19. [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
  20. # Flow variation random source port between min and max
  21. UDP_SRC_MIN=9
  22. UDP_SRC_MAX=109
  23. node=`get_iface_node $DEV`
  24. irq_array=(`get_iface_irqs $DEV`)
  25. cpu_array=(`get_node_cpus $node`)
  26. [ $THREADS -gt ${#irq_array[*]} -o $THREADS -gt ${#cpu_array[*]} ] && \
  27. err 1 "Thread number $THREADS exceeds: min (${#irq_array[*]},${#cpu_array[*]})"
  28. # (example of setting default params in your script)
  29. if [ -z "$DEST_IP" ]; then
  30. [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
  31. fi
  32. [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
  33. if [ -n "$DEST_IP" ]; then
  34. validate_addr${IP6} $DEST_IP
  35. read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
  36. fi
  37. if [ -n "$DST_PORT" ]; then
  38. read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
  39. validate_ports $UDP_DST_MIN $UDP_DST_MAX
  40. fi
  41. # General cleanup everything since last run
  42. pg_ctrl "reset"
  43. # Threads are specified with parameter -t value in $THREADS
  44. for ((i = 0; i < $THREADS; i++)); do
  45. # The device name is extended with @name, using thread number to
  46. # make then unique, but any name will do.
  47. # Set the queue's irq affinity to this $thread (processor)
  48. # if '-f' is designated, offset cpu id
  49. thread=${cpu_array[$((i+F_THREAD))]}
  50. dev=${DEV}@${thread}
  51. echo $thread > /proc/irq/${irq_array[$i]}/smp_affinity_list
  52. info "irq ${irq_array[$i]} is set affinity to `cat /proc/irq/${irq_array[$i]}/smp_affinity_list`"
  53. # Add remove all other devices and add_device $dev to thread
  54. pg_thread $thread "rem_device_all"
  55. pg_thread $thread "add_device" $dev
  56. # select queue and bind the queue and $dev in 1:1 relationship
  57. queue_num=$i
  58. info "queue number is $queue_num"
  59. pg_set $dev "queue_map_min $queue_num"
  60. pg_set $dev "queue_map_max $queue_num"
  61. # Notice config queue to map to cpu (mirrors smp_processor_id())
  62. # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
  63. pg_set $dev "flag QUEUE_MAP_CPU"
  64. # Base config of dev
  65. pg_set $dev "count $COUNT"
  66. pg_set $dev "clone_skb $CLONE_SKB"
  67. pg_set $dev "pkt_size $PKT_SIZE"
  68. pg_set $dev "delay $DELAY"
  69. # Flag example disabling timestamping
  70. pg_set $dev "flag NO_TIMESTAMP"
  71. # Destination
  72. pg_set $dev "dst_mac $DST_MAC"
  73. pg_set $dev "dst${IP6}_min $DST_MIN"
  74. pg_set $dev "dst${IP6}_max $DST_MAX"
  75. if [ -n "$DST_PORT" ]; then
  76. # Single destination port or random port range
  77. pg_set $dev "flag UDPDST_RND"
  78. pg_set $dev "udp_dst_min $UDP_DST_MIN"
  79. pg_set $dev "udp_dst_max $UDP_DST_MAX"
  80. fi
  81. # Setup random UDP port src range
  82. pg_set $dev "flag UDPSRC_RND"
  83. pg_set $dev "udp_src_min $UDP_SRC_MIN"
  84. pg_set $dev "udp_src_max $UDP_SRC_MAX"
  85. done
  86. # start_run
  87. echo "Running... ctrl^C to stop" >&2
  88. pg_ctrl "start"
  89. echo "Done" >&2
  90. # Print results
  91. for ((i = 0; i < $THREADS; i++)); do
  92. thread=${cpu_array[$((i+F_THREAD))]}
  93. dev=${DEV}@${thread}
  94. echo "Device: $dev"
  95. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  96. done