fuel plugin: Initial version
[ovsnfv.git] / fuel-plugin-ovsnfv / deployment_scripts / puppet / modules / ovsdpdk / files / tune_params.sh
1 #!/usr/bin/env  bash
2
3 # It adapts /etc/default/ovs-dpdk file
4 # generated mainly from devstack/libs/ovs-dpdk
5 # it will modify / tune variables, which are not configured directly
6
7 source /etc/default/ovs-dpdk
8
9 if [ $OVS_SOCKET_MEM == "auto" ] ; then
10     for d in /sys/devices/system/node/node? ; do
11         if [ $OVS_SOCKET_MEM == "auto" ]; then
12                 OVS_SOCKET_MEM=2048
13         else
14                 OVS_SOCKET_MEM=$OVS_SOCKET_MEM,2048
15         fi
16     done
17 fi
18
19 sudo sed "s#OVS_SOCKET_MEM=.*#OVS_SOCKET_MEM=$OVS_SOCKET_MEM#" -i /etc/default/ovs-dpdk
20
21 # Creates an array of pci addres to interface names delimeted by # e.g. <pci_address>#<interface name>
22 PAIRS=( `ls -al /sys/class/net/* | grep pci | rev | awk '{print $1;}' | cut -d '/' -f 1,3 | rev |  sed s'/\//#/'` )
23 # Populates OVS_BRIDGE_MAPPINGS if $PHYSICAL_NETWORK and $OVS_PHYSICAL_BRIDGE are used instead.
24 if [[ "$OVS_DATAPATH_TYPE" != "" ]] && [[ "$OVS_BRIDGE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$OVS_PHYSICAL_BRIDGE" != "" ]]; then
25     OVS_BRIDGE_MAPPINGS=$PHYSICAL_NETWORK:$OVS_PHYSICAL_BRIDGE
26 fi
27
28 if [[ -z "$OVS_DPDK_PORT_MAPPINGS" ]]; then
29     OVS_BRIDGES=${OVS_BRIDGE_MAPPINGS//,/ }
30     ARRAY=( $OVS_BRIDGES )
31     for net in "${ARRAY[@]}"; do
32         bridge="${net##*:}"
33         nic=${bridge/br-/}
34         if [[ -z "$OVS_DPDK_PORT_MAPPINGS" ]]; then
35             OVS_DPDK_PORT_MAPPINGS=$nic:$bridge
36         else
37             OVS_DPDK_PORT_MAPPINGS=$OVS_DPDK_PORT_MAPPINGS,$nic:$bridge
38         fi
39     done
40 fi
41
42 MAPPINGS=${OVS_DPDK_PORT_MAPPINGS//,/ }
43
44 ARRAY=( $MAPPINGS )
45 NICS=""
46 for net in "${ARRAY[@]}"; do
47     nic="${net%%:*}"
48     bridge="${net##*:}"
49     printf "%s in %s\n" "$KEY" "$VALUE"
50     for pair in "${PAIRS[@]}"; do
51         if [[ $nic == `echo $pair | cut -f 2 -d "#"` ]]; then
52             if [[ $NICS == "" ]]; then
53                 NICS=$pair
54             else
55                 NICS=$NICS,$pair
56             fi
57         fi
58     done
59 done
60 sudo sed "s/OVS_PCI_MAPPINGS=.*/OVS_PCI_MAPPINGS=$NICS/" -i /etc/default/ovs-dpdk
61 sudo sed "s/OVS_BRIDGE_MAPPINGS=.*/OVS_BRIDGE_MAPPINGS=$OVS_BRIDGE_MAPPINGS/" -i /etc/default/ovs-dpdk
62 sudo sed "s/OVS_DPDK_PORT_MAPPINGS=.*/OVS_DPDK_PORT_MAPPINGS=$OVS_DPDK_PORT_MAPPINGS/" -i /etc/default/ovs-dpdk
63
64 OVS_PMD_CORE_MASK=$(echo $OVS_PMD_CORE_MASK | sed 's/^0x//')
65
66 if [ $OVS_PMD_CORE_MASK -eq 4 ]; then
67     #default value, check for siblings in case of hyperthreading enabled
68     SIBLINGS=""
69     RESULT=0
70     FILE="/sys/devices/system/cpu/cpu3/topology/thread_siblings_list"
71     if [ -e $FILE ]; then
72         SIBLINGS=`cat $FILE`
73     else
74         echo "warning: don't know how to check siblings"
75         SIBLINGS=3
76     fi
77
78     for SIBLING in $(echo $SIBLINGS | sed -n 1'p' | tr ',' '\n'); do
79         SIBLING_CORE=`echo "obase=10;$((1<<($SIBLING-1)))" | bc`
80         RESULT=$(($RESULT | $SIBLING_CORE))
81     done
82
83     OVS_PMD_CORE_MASK=`printf "%x" $RESULT`
84 fi
85
86 sudo sed "s#OVS_PMD_CORE_MASK=.*#OVS_PMD_CORE_MASK=$OVS_PMD_CORE_MASK#" -i /etc/default/ovs-dpdk