grep -s '/mnt/huge' /proc/mounts > /dev/null if [ $? -ne 0 ] ; then mount -t hugetlbfs nodev /mnt/huge fi }
# # Removes hugepage filesystem. # remove_mnt_huge() { grep -s '/mnt/huge' /proc/mounts > /dev/null if [ $? -eq 0 ] ; then umount /mnt/huge fi
if [ -d /mnt/huge ] ; then rm -R /mnt/huge fi }
# Creates hugepages on specific NUMA nodes. # set_numa_pages() { # clear_huge_pages
Pages=$1
echo > .echo_tmp for d in /sys/devices/system/node/node? ; do node=$(basename $d) echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ_IN_KB}/nr_hugepages" >> .echo_tmp done
sh .echo_tmp
rm -f .echo_tmp
create_mnt_huge
LOG_INFO "Reserving hugepages: $Pages, Creating /mnt/huge and mounting as hugetlbfs" }
# # show hugepages infos from /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages and # /proc/meminfo. # show_numa_pages() { LOG_INFO "show hugepages config:"
LOG_WAR "cmdline:" echo "$(cat /proc/cmdline)"
LOG_WAR "hugepages info:" for d in /sys/devices/system/node/node? ; do pagesPath=$d/hugepages/hugepages-${HUGEPGSZ_IN_KB}/nr_hugepages echo $pagesPath "$(cat $pagesPath)" done
LOG_WAR "hugepages in /proc/meminfo:" echo "$(grep -ri huge /proc/meminfo)" }
# # Uses dpdk-devbind.py to move devices to work with igb_uio # bind_devices_to_igb_uio() { if [ -d /sys/module/igb_uio ]; then PCI_PATH=$1 ${RTE_SDK}/usertools/dpdk-devbind.py --force -b igb_uio $PCI_PATH || exit 1 LOG_INFO "bind $PCI_PATH to igb_uio Successfully!" else LOG_ERR "# Please load the 'igb_uio' kernel module before querying or " LOG_ERR "# adjusting device bindings" fi }
# # Uses dpdk-devbind.py to move devices to work with kernel drivers again # unbind_devices() { DRV=$1 PCI_PATH=$2 ${RTE_SDK}/usertools/dpdk-devbind.py -b $DRV $PCI_PATH || LOG_ERR "[Fail] unbind" LOG_INFO "unbind $PCI_PATH, bind to driver $DRV Successfully !" }
for((i=0; i<$dev_cnt; i++)) do eval "eth_name_i=\$if$i"
if [ -z $eth_name_i ] then return 1 fi
if [ $eth_name_i == $dst_eth_name ] then eval "pci_addr_of_this_eth=\$bus$i" eval "driver_of_this_eth=\$driver$i" return 0 fi done return 1 }
# # ret info at driver_of_this_eth # get_eth_original_info_by_pci() { driver_of_this_eth=""
for((i=0; i<$dev_cnt; i++)) do eval "pci_i=\$bus$i"
if [ -z $pci_i ] then return 1 fi
if [ $pci_i == $1 ] then eval "driver_of_this_eth=\$driver$i" return 0 fi done return 1 }
# # bind all given eth to dpdk driver. # zero args will do nothing. # function bind_devices_by_name { for eth in $* do get_eth_original_info_by_name $eth if [ $? -ne 0 ] then echo "can not get pci addr of $eth, bind failed." continue fi echo "bind eth $eth to dpdk driver igb_uio ..." bind_devices_to_igb_uio $pci_addr_of_this_eth done }
# # unbind a eth to it's original driver # function unbind_this_device_by_name { get_eth_original_info_by_name $1 if [ $? -ne 0 ] then echo "can not get pci addr of $eth, bind failed." return 0 fi
# # 1) unbind given eth to their original driver. # 2) if no eth given, unbind all eth binding dpdk driver. # function unbind_devices_by_name { # unbind all given eth for eth in $* do echo "unbind dev for $eth" unbind_this_device_by_name $eth done
# given at least one eth, bind done and ret if [ $# -gt 0 ] then return 0 fi
# given no eth, unbind all dev binding dpdk driver for((i=0; i<$dev_cnt; i++)) do eval "Driver_i=\$Driver$i"
if [ -z $Driver_i ] then return 1 fi
if [ $Driver_i != "igb_uio" ] then continue fi
eval "get_eth_original_info_by_pci \$Slot$i" if [ $? -ne 0 ] then eval "echo can not get driver of \$Slot$i, unbind failed." continue fi
grep -s '/mnt/huge' /proc/mounts > /dev/null if [ $? -ne 0 ] ; then mount -t hugetlbfs nodev /mnt/huge fi }
# # Removes hugepage filesystem. # remove_mnt_huge() { grep -s '/mnt/huge' /proc/mounts > /dev/null if [ $? -eq 0 ] ; then umount /mnt/huge fi
if [ -d /mnt/huge ] ; then rm -R /mnt/huge fi }
# Creates hugepages on specific NUMA nodes. # set_numa_pages() { Pages=$1
echo > .echo_tmp for d in /sys/devices/system/node/node? ; do node=$(basename $d) echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ_IN_KB}/nr_hugepages" >> .echo_tmp done
sh .echo_tmp
rm -f .echo_tmp
create_mnt_huge
LOG_INFO "Reserving hugepages: $Pages, Creating /mnt/huge and mounting as hugetlbfs" }
# # Uses dpdk-devbind.py to move devices to work with igb_uio # bind_devices_to_igb_uio() { if [ -d /sys/module/igb_uio ]; then PCI_PATH=$1 ${RTE_SDK}/usertools/dpdk-devbind.py --force -b igb_uio $PCI_PATH || exit 1 LOG_INFO "bind $PCI_PATH to igb_uio Successfully!" else LOG_ERR "# Please load the 'igb_uio' kernel module before querying or " LOG_ERR "# adjusting device bindings" fi }
# # Uses dpdk-devbind.py to move devices to work with kernel drivers again # unbind_devices() { DRV=$1 PCI_PATH=$2 ${RTE_SDK}/usertools/dpdk-devbind.py -b $DRV $PCI_PATH || LOG_ERR "[Fail] unbind" LOG_INFO "unbind $PCI_PATH, bind to driver $DRV Successfully !" }
get_all_eth_info() { if [ ! -f ./.if_tbl ] then LOG_ERR "ERROR: there is no .if_tbl, pleae do ./dpdk.install" exit fi
# calc original eth info from .if_tbl original_eth_info=$(awk '{print gensub(/=(\S*)/, cnt++ "=\\1;", "g");}' ./.if_tbl) eval $original_eth_info
# get eth dev info from lspci and format the output # as shell script's value assignment. eth_info=$(lspci -Dvmmnnk | awk -v RS="\n\n" '/Eth/{print gensub(/:\s([^\n]*)/, cnt++ "=\"\\1\"", "g");} END{print "dev_cnt=" cnt;}')
# eval the shell script to get the variables. eval $eth_info for ((i=0; i<$dev_cnt; i++)) do # calculate eth interface and linking status # if eth1's Slog is 0000:05:00.0 # it's interface name is /sys/bus/pci/devices/0000:05:00.0/net/[interface] # it's linking status in /sys/bus/pci/devices/0000:05:00.0/net/[interface]/carrier eval "Interface$i=---" eval "Linking$i=-" eval "dev_net_path=/sys/bus/pci/devices/\$Slot$i/net" if [ -e $dev_net_path ] then eval "Interface$i=$(ls $dev_net_path)" eval "read Linking$i</sys/bus/pci/devices/\$Slot$i/net/\$Interface$i/carrier" fi done }
# # ret info at pci_addr_of_this_eth and driver_of_this_eth # get_eth_original_info_by_name() { dst_eth_name=$1 pci_addr_of_this_eth="" driver_of_this_eth=""
for((i=0; i<$dev_cnt; i++)) do eval "eth_name_i=\$if$i"
if [ -z $eth_name_i ] then return 1 fi
if [ $eth_name_i == $dst_eth_name ] then eval "pci_addr_of_this_eth=\$bus$i" eval "driver_of_this_eth=\$driver$i" return 0 fi done return 1 }
# # ret info at driver_of_this_eth # get_eth_original_info_by_pci() { driver_of_this_eth=""
for((i=0; i<$dev_cnt; i++)) do eval "pci_i=\$bus$i"
if [ -z $pci_i ] then return 1 fi
if [ $pci_i == $1 ] then eval "driver_of_this_eth=\$driver$i" return 0 fi done return 1 }
# # bind all given eth to dpdk driver. # zero args will do nothing. # function bind_devices_by_name { for eth in $* do get_eth_original_info_by_name $eth if [ $? -ne 0 ] then echo "can not get pci addr of $eth, bind failed." continue fi echo "bind eth $eth to dpdk driver igb_uio ..." bind_devices_to_igb_uio $pci_addr_of_this_eth done }
# # unbind a eth to it's original driver # function unbind_this_device_by_name { get_eth_original_info_by_name $1 if [ $? -ne 0 ] then echo "can not get pci addr of $eth, bind failed." return 0 fi
# # 1) unbind given eth to their original driver. # 2) if no eth given, unbind all eth binding dpdk driver. # function unbind_devices_by_name { # unbind all given eth for eth in $* do echo "unbind dev for $eth" unbind_this_device_by_name $eth done
# given at least one eth, bind done and ret if [ $# -gt 0 ] then return 0 fi
# given no eth, unbind all dev binding dpdk driver for((i=0; i<$dev_cnt; i++)) do eval "Driver_i=\$Driver$i"
if [ -z $Driver_i ] then return 1 fi
if [ $Driver_i != "igb_uio" ] then continue fi
eval "get_eth_original_info_by_pci \$Slot$i" if [ $? -ne 0 ] then eval "echo can not get driver of \$Slot$i, unbind failed." continue fi
[root@localhost ~]# ./l2fwd -l 0-4 -- -p 0x0f EAL: Detected 8 lcore(s) EAL: Probing VFIO support... EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles ! EAL: PCI device 0000:02:01.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 8086:100e net_e1000_em EAL: PCI device 0000:03:00.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 1af4:1041 net_virtio EAL: PCI device 0000:04:00.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 1af4:1041 net_virtio EAL: PCI device 0000:05:00.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 1af4:1041 net_virtio EAL: PCI device 0000:06:00.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 1af4:1041 net_virtio MAC updating enabled Lcore 0: RX port 0 Lcore 1: RX port 1 Initializing port 0... done: Port 0, MAC address: 12:34:56:78:90:A5
Initializing port 1... done: Port 1, MAC address: 12:34:56:78:90:A7
Checking link statusdone Port 0 Link Up - speed 10000 Mbps - full-duplex Port 1 Link Up - speed 10000 Mbps - full-duplex L2FWD: entering main loop on lcore 1 L2FWD: -- lcoreid=1 portid=1 L2FWD: lcore 2 has nothing to do L2FWD: lcore 4 has nothing to do L2FWD: lcore 3 has nothing to do L2FWD: entering main loop on lcore 0 L2FWD: -- lcoreid=0 portid=0
Port statistics ==================================== Statistics for port 0 ------------------------------ Packets sent: 1101894 Packets received: 907488 Speed PPS sent: 1101894 Speed PPS received: 907488 Packets dropped: 853 Statistics for port 1 ------------------------------ Packets sent: 906641 Packets received: 1102747 Speed PPS sent: 906641 Speed PPS received: 1102747 Packets dropped: 847 Statistics for port 2 ------------------------------ Packets sent: 0 Packets received: 0 Speed PPS sent: 0 Speed PPS received: 0 Packets dropped: 0 Statistics for port 3 ------------------------------ Packets sent: 0 Packets received: 0 Speed PPS sent: 0 Speed PPS received: 0 Packets dropped: 0 Aggregate statistics =============================== Total packets sent: 2008535 Total packets received: 2010235 Total packets dropped: 1700 ==================================================== ^C Signal 2 received, preparing to exit... Closing port 0... Done Closing port 1... Done Bye... [root@localhost ~]#