Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 #
0003 # Multiqueue: Using pktgen threads for sending on multiple CPUs
0004 #  * adding devices to kernel threads which are in the same NUMA node
0005 #  * bound devices queue's irq affinity to the threads, 1:1 mapping
0006 #  * notice the naming scheme for keeping device names unique
0007 #  * nameing scheme: dev@thread_number
0008 #  * flow variation via random UDP source port
0009 #
0010 basedir=`dirname $0`
0011 source ${basedir}/functions.sh
0012 root_check_run_with_sudo "$@"
0013 #
0014 # Required param: -i dev in $DEV
0015 source ${basedir}/parameters.sh
0016 
0017 # Base Config
0018 [ -z "$COUNT" ]     && COUNT="20000000"   # Zero means indefinitely
0019 [ -z "$CLONE_SKB" ] && CLONE_SKB="0"
0020 
0021 # Flow variation random source port between min and max
0022 UDP_SRC_MIN=9
0023 UDP_SRC_MAX=109
0024 
0025 node=`get_iface_node $DEV`
0026 irq_array=(`get_iface_irqs $DEV`)
0027 cpu_array=(`get_node_cpus $node`)
0028 
0029 [ $THREADS -gt ${#irq_array[*]} -o $THREADS -gt ${#cpu_array[*]}  ] && \
0030         err 1 "Thread number $THREADS exceeds: min (${#irq_array[*]},${#cpu_array[*]})"
0031 
0032 # (example of setting default params in your script)
0033 if [ -z "$DEST_IP" ]; then
0034     [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
0035 fi
0036 [ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
0037 if [ -n "$DEST_IP" ]; then
0038     validate_addr${IP6} $DEST_IP
0039     read -r DST_MIN DST_MAX <<< $(parse_addr${IP6} $DEST_IP)
0040 fi
0041 if [ -n "$DST_PORT" ]; then
0042     read -r UDP_DST_MIN UDP_DST_MAX <<< $(parse_ports $DST_PORT)
0043     validate_ports $UDP_DST_MIN $UDP_DST_MAX
0044 fi
0045 
0046 # General cleanup everything since last run
0047 [ -z "$APPEND" ] && pg_ctrl "reset"
0048 
0049 # Threads are specified with parameter -t value in $THREADS
0050 for ((i = 0; i < $THREADS; i++)); do
0051     # The device name is extended with @name, using thread number to
0052     # make then unique, but any name will do.
0053     # Set the queue's irq affinity to this $thread (processor)
0054     # if '-f' is designated, offset cpu id
0055     thread=${cpu_array[$((i+F_THREAD))]}
0056     dev=${DEV}@${thread}
0057     echo $thread > /proc/irq/${irq_array[$i]}/smp_affinity_list
0058     info "irq ${irq_array[$i]} is set affinity to `cat /proc/irq/${irq_array[$i]}/smp_affinity_list`"
0059 
0060     # Add remove all other devices and add_device $dev to thread
0061     [ -z "$APPEND" ] && pg_thread $thread "rem_device_all"
0062     pg_thread $thread "add_device" $dev
0063 
0064     # select queue and bind the queue and $dev in 1:1 relationship
0065     queue_num=$i
0066     info "queue number is $queue_num"
0067     pg_set $dev "queue_map_min $queue_num"
0068     pg_set $dev "queue_map_max $queue_num"
0069 
0070     # Notice config queue to map to cpu (mirrors smp_processor_id())
0071     # It is beneficial to map IRQ /proc/irq/*/smp_affinity 1:1 to CPU number
0072     pg_set $dev "flag QUEUE_MAP_CPU"
0073 
0074     # Base config of dev
0075     pg_set $dev "count $COUNT"
0076     pg_set $dev "clone_skb $CLONE_SKB"
0077     pg_set $dev "pkt_size $PKT_SIZE"
0078     pg_set $dev "delay $DELAY"
0079 
0080     # Flag example disabling timestamping
0081     pg_set $dev "flag NO_TIMESTAMP"
0082 
0083     # Destination
0084     pg_set $dev "dst_mac $DST_MAC"
0085     pg_set $dev "dst${IP6}_min $DST_MIN"
0086     pg_set $dev "dst${IP6}_max $DST_MAX"
0087 
0088     if [ -n "$DST_PORT" ]; then
0089         # Single destination port or random port range
0090         pg_set $dev "flag UDPDST_RND"
0091         pg_set $dev "udp_dst_min $UDP_DST_MIN"
0092         pg_set $dev "udp_dst_max $UDP_DST_MAX"
0093     fi
0094 
0095     [ ! -z "$UDP_CSUM" ] && pg_set $dev "flag UDPCSUM"
0096 
0097     # Setup random UDP port src range
0098     pg_set $dev "flag UDPSRC_RND"
0099     pg_set $dev "udp_src_min $UDP_SRC_MIN"
0100     pg_set $dev "udp_src_max $UDP_SRC_MAX"
0101 done
0102 
0103 # Run if user hits control-c
0104 function print_result() {
0105     # Print results
0106     for ((i = 0; i < $THREADS; i++)); do
0107         thread=${cpu_array[$((i+F_THREAD))]}
0108         dev=${DEV}@${thread}
0109         echo "Device: $dev"
0110         cat /proc/net/pktgen/$dev | grep -A2 "Result:"
0111     done
0112 }
0113 # trap keyboard interrupt (Ctrl-C)
0114 trap true SIGINT
0115 
0116 # start_run
0117 if [ -z "$APPEND" ]; then
0118     echo "Running... ctrl^C to stop" >&2
0119     pg_ctrl "start"
0120     echo "Done" >&2
0121 
0122     print_result
0123 else
0124     echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
0125 fi