pktgen_sample06_numa_awared_queue_irq_affinity.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_MIN=9
  22. UDP_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. # General cleanup everything since last run
  34. pg_ctrl "reset"
  35. # Threads are specified with parameter -t value in $THREADS
  36. for ((i = 0; i < $THREADS; i++)); do
  37. # The device name is extended with @name, using thread number to
  38. # make then unique, but any name will do.
  39. # Set the queue's irq affinity to this $thread (processor)
  40. # if '-f' is designated, offset cpu id
  41. thread=${cpu_array[$((i+F_THREAD))]}
  42. dev=${DEV}@${thread}
  43. echo $thread > /proc/irq/${irq_array[$i]}/smp_affinity_list
  44. info "irq ${irq_array[$i]} is set affinity to `cat /proc/irq/${irq_array[$i]}/smp_affinity_list`"
  45. # Add remove all other devices and add_device $dev to thread
  46. pg_thread $thread "rem_device_all"
  47. pg_thread $thread "add_device" $dev
  48. # select queue and bind the queue and $dev in 1:1 relationship
  49. queue_num=$i
  50. info "queue number is $queue_num"
  51. pg_set $dev "queue_map_min $queue_num"
  52. pg_set $dev "queue_map_max $queue_num"
  53. # Notice config queue to map to cpu (mirrors smp_processor_id())
  54. # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
  55. pg_set $dev "flag QUEUE_MAP_CPU"
  56. # Base config of dev
  57. pg_set $dev "count $COUNT"
  58. pg_set $dev "clone_skb $CLONE_SKB"
  59. pg_set $dev "pkt_size $PKT_SIZE"
  60. pg_set $dev "delay $DELAY"
  61. # Flag example disabling timestamping
  62. pg_set $dev "flag NO_TIMESTAMP"
  63. # Destination
  64. pg_set $dev "dst_mac $DST_MAC"
  65. pg_set $dev "dst$IP6 $DEST_IP"
  66. # Setup random UDP port src range
  67. pg_set $dev "flag UDPSRC_RND"
  68. pg_set $dev "udp_src_min $UDP_MIN"
  69. pg_set $dev "udp_src_max $UDP_MAX"
  70. done
  71. # start_run
  72. echo "Running... ctrl^C to stop" >&2
  73. pg_ctrl "start"
  74. echo "Done" >&2
  75. # Print results
  76. for ((i = 0; i < $THREADS; i++)); do
  77. thread=${cpu_array[$((i+F_THREAD))]}
  78. dev=${DEV}@${thread}
  79. echo "Device: $dev"
  80. cat /proc/net/pktgen/$dev | grep -A2 "Result:"
  81. done