licenses: Add license headers
[ovsnfv.git] / fuel-plugin-ovsnfv / deployment_scripts / puppet / modules / ovsdpdk / files / set_vcpu_pin.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 # Small script for calculation of cores not suitable for deployment
18 # of VM's and adaptation of nova.conf accordingly
19 # nova.conf path should come as first param
20 # this should be executed when nova is enabled and already configured
21
22 source /etc/default/ovs-dpdk
23
24 OVS_CORE_MASK=$(echo $OVS_CORE_MASK | sed 's/^0x//')
25 OVS_PMD_CORE_MASK=$(echo $OVS_PMD_CORE_MASK | sed 's/^0x//')
26 BAD_CORES=$((`echo $((16#${OVS_CORE_MASK}))` | `echo $((16#${OVS_PMD_CORE_MASK}))`))
27 TOTAL_CORES=`nproc`
28 vcpu_pin_set=""
29
30 for cpu in $(seq 0 `expr $TOTAL_CORES - 1`);do
31     tmp=`echo 2^$cpu | bc`
32     if [ $(($tmp & $BAD_CORES)) -eq 0 ]; then
33         vcpu_pin_set+=$cpu","
34     fi
35 done
36 vcpu_pin_set=${vcpu_pin_set::-1}
37
38 crudini --set $1 DEFAULT vcpu_pin_set $vcpu_pin_set