licenses: Add license headers
[ovsnfv.git] / fuel-plugin-ovsnfv / deployment_scripts / puppet / modules / ovsdpdk / files / tune_params.sh
1 #!/usr/bin/env  bash
2
3 # Copyright (c) 2016 Open Platform for NFV Project, Inc. and its contributors
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License");
6 #    you may not use this file except in compliance with the License.
7 #    You may obtain a copy of the License at
8 #
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS,
13 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #    See the License for the specific language governing permissions and
15 #    limitations under the License.
16
17 # It adapts /etc/default/ovs-dpdk file
18 # generated mainly from devstack/libs/ovs-dpdk
19 # it will modify / tune variables, which are not configured directly
20
21 source /etc/default/ovs-dpdk
22
23 if [ $OVS_SOCKET_MEM == "auto" ] ; then
24     for d in /sys/devices/system/node/node? ; do
25         if [ $OVS_SOCKET_MEM == "auto" ]; then
26                 OVS_SOCKET_MEM=2048
27         else
28                 OVS_SOCKET_MEM=$OVS_SOCKET_MEM,2048
29         fi
30     done
31 fi
32
33 sudo sed "s#OVS_SOCKET_MEM=.*#OVS_SOCKET_MEM=$OVS_SOCKET_MEM#" -i /etc/default/ovs-dpdk
34
35 # Creates an array of pci addres to interface names delimeted by # e.g. <pci_address>#<interface name>
36 PAIRS=( `ls -al /sys/class/net/* | grep pci | rev | awk '{print $1;}' | cut -d '/' -f 1,3 | rev |  sed s'/\//#/'` )
37 # Populates OVS_BRIDGE_MAPPINGS if $PHYSICAL_NETWORK and $OVS_PHYSICAL_BRIDGE are used instead.
38 if [[ "$OVS_DATAPATH_TYPE" != "" ]] && [[ "$OVS_BRIDGE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$OVS_PHYSICAL_BRIDGE" != "" ]]; then
39     OVS_BRIDGE_MAPPINGS=$PHYSICAL_NETWORK:$OVS_PHYSICAL_BRIDGE
40 fi
41
42 if [[ -z "$OVS_DPDK_PORT_MAPPINGS" ]]; then
43     OVS_BRIDGES=${OVS_BRIDGE_MAPPINGS//,/ }
44     ARRAY=( $OVS_BRIDGES )
45     for net in "${ARRAY[@]}"; do
46         bridge="${net##*:}"
47         nic=${bridge/br-/}
48         if [[ -z "$OVS_DPDK_PORT_MAPPINGS" ]]; then
49             OVS_DPDK_PORT_MAPPINGS=$nic:$bridge
50         else
51             OVS_DPDK_PORT_MAPPINGS=$OVS_DPDK_PORT_MAPPINGS,$nic:$bridge
52         fi
53     done
54 fi
55
56 MAPPINGS=${OVS_DPDK_PORT_MAPPINGS//,/ }
57
58 ARRAY=( $MAPPINGS )
59 NICS=""
60 for net in "${ARRAY[@]}"; do
61     nic="${net%%:*}"
62     bridge="${net##*:}"
63     printf "%s in %s\n" "$KEY" "$VALUE"
64     for pair in "${PAIRS[@]}"; do
65         if [[ $nic == `echo $pair | cut -f 2 -d "#"` ]]; then
66             if [[ $NICS == "" ]]; then
67                 NICS=$pair
68             else
69                 NICS=$NICS,$pair
70             fi
71         fi
72     done
73 done
74 sudo sed "s/OVS_PCI_MAPPINGS=.*/OVS_PCI_MAPPINGS=$NICS/" -i /etc/default/ovs-dpdk
75 sudo sed "s/OVS_BRIDGE_MAPPINGS=.*/OVS_BRIDGE_MAPPINGS=$OVS_BRIDGE_MAPPINGS/" -i /etc/default/ovs-dpdk
76 sudo sed "s/OVS_DPDK_PORT_MAPPINGS=.*/OVS_DPDK_PORT_MAPPINGS=$OVS_DPDK_PORT_MAPPINGS/" -i /etc/default/ovs-dpdk
77
78 OVS_PMD_CORE_MASK=$(echo $OVS_PMD_CORE_MASK | sed 's/^0x//')
79
80 if [ $OVS_PMD_CORE_MASK -eq 4 ]; then
81     #default value, check for siblings in case of hyperthreading enabled
82     SIBLINGS=""
83     RESULT=0
84     FILE="/sys/devices/system/cpu/cpu3/topology/thread_siblings_list"
85     if [ -e $FILE ]; then
86         SIBLINGS=`cat $FILE`
87     else
88         echo "warning: don't know how to check siblings"
89         SIBLINGS=3
90     fi
91
92     for SIBLING in $(echo $SIBLINGS | sed -n 1'p' | tr ',' '\n'); do
93         SIBLING_CORE=`echo "obase=10;$((1<<($SIBLING-1)))" | bc`
94         RESULT=$(($RESULT | $SIBLING_CORE))
95     done
96
97     OVS_PMD_CORE_MASK=`printf "%x" $RESULT`
98 fi
99
100 sudo sed "s#OVS_PMD_CORE_MASK=.*#OVS_PMD_CORE_MASK=$OVS_PMD_CORE_MASK#" -i /etc/default/ovs-dpdk