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
11 source ${basedir}/functions.sh
12 root_check_run_with_sudo
"$@"
14 # Required param: -i dev in $DEV
15 source ${basedir}/parameters.sh
18 DELAY
="0" # Zero means max speed
19 [ -z "$COUNT" ] && COUNT
="20000000" # Zero means indefinitely
20 [ -z "$CLONE_SKB" ] && CLONE_SKB
="0"
22 # Flow variation random source port between min and max
26 node
=`get_iface_node $DEV`
27 irq_array
=(`get_iface_irqs $DEV`)
28 cpu_array
=(`get_node_cpus $node`)
30 [ $THREADS -gt ${#irq_array[*]} -o $THREADS -gt ${#cpu_array[*]} ] && \
31 err
1 "Thread number $THREADS exceeds: min (${#irq_array[*]},${#cpu_array[*]})"
33 # (example of setting default params in your script)
34 if [ -z "$DEST_IP" ]; then
35 [ -z "$IP6" ] && DEST_IP
="198.18.0.42" || DEST_IP
="FD00::1"
37 [ -z "$DST_MAC" ] && DST_MAC
="90:e2:ba:ff:ff:ff"
38 if [ -n "$DEST_IP" ]; then
39 validate_addr
${IP6} $DEST_IP
40 read -r DST_MIN DST_MAX
<<< $
(parse_addr
${IP6} $DEST_IP)
42 if [ -n "$DST_PORT" ]; then
43 read -r UDP_DST_MIN UDP_DST_MAX
<<< $
(parse_ports
$DST_PORT)
44 validate_ports
$UDP_DST_MIN $UDP_DST_MAX
47 # General cleanup everything since last run
50 # Threads are specified with parameter -t value in $THREADS
51 for ((i
= 0; i
< $THREADS; i
++)); do
52 # The device name is extended with @name, using thread number to
53 # make then unique, but any name will do.
54 # Set the queue's irq affinity to this $thread (processor)
55 # if '-f' is designated, offset cpu id
56 thread
=${cpu_array[$((i+F_THREAD))]}
58 echo $thread > /proc
/irq
/${irq_array[$i]}/smp_affinity_list
59 info
"irq ${irq_array[$i]} is set affinity to `cat /proc/irq/${irq_array[$i]}/smp_affinity_list`"
61 # Add remove all other devices and add_device $dev to thread
62 pg_thread
$thread "rem_device_all"
63 pg_thread
$thread "add_device" $dev
65 # select queue and bind the queue and $dev in 1:1 relationship
67 info
"queue number is $queue_num"
68 pg_set
$dev "queue_map_min $queue_num"
69 pg_set
$dev "queue_map_max $queue_num"
71 # Notice config queue to map to cpu (mirrors smp_processor_id())
72 # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
73 pg_set
$dev "flag QUEUE_MAP_CPU"
76 pg_set
$dev "count $COUNT"
77 pg_set
$dev "clone_skb $CLONE_SKB"
78 pg_set
$dev "pkt_size $PKT_SIZE"
79 pg_set
$dev "delay $DELAY"
81 # Flag example disabling timestamping
82 pg_set
$dev "flag NO_TIMESTAMP"
85 pg_set
$dev "dst_mac $DST_MAC"
86 pg_set
$dev "dst${IP6}_min $DST_MIN"
87 pg_set
$dev "dst${IP6}_max $DST_MAX"
89 if [ -n "$DST_PORT" ]; then
90 # Single destination port or random port range
91 pg_set
$dev "flag UDPDST_RND"
92 pg_set
$dev "udp_dst_min $UDP_DST_MIN"
93 pg_set
$dev "udp_dst_max $UDP_DST_MAX"
96 # Setup random UDP port src range
97 pg_set
$dev "flag UDPSRC_RND"
98 pg_set
$dev "udp_src_min $UDP_SRC_MIN"
99 pg_set
$dev "udp_src_max $UDP_SRC_MAX"
103 echo "Running... ctrl^C to stop" >&2
108 for ((i
= 0; i
< $THREADS; i
++)); do
109 thread
=${cpu_array[$((i+F_THREAD))]}
112 cat /proc
/net
/pktgen
/$dev |
grep -A2 "Result:"