-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexclusive-pin.sh
executable file
·79 lines (65 loc) · 2.23 KB
/
exclusive-pin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# Title: exclusive-pin.sh
# Description: A helper script for putting dom0 on exclusive CPUs.
# Author: Rok Strnisa <[email protected]>
# Author: Marcus Granado <[email protected]>
# Source: https://github.com/perf101/scripts
# FAIL IF ANY COMMAND FAILS
set -e
# DEFAULTS
# execution mode
mode="eval"
# USAGE
basename=`basename ${0}`
usage_prefix="Usage: ${basename} "
indent=`printf "%${#usage_prefix}s" " "`
persistent=
usage="${usage_prefix}[-h|--help] [-n|--dry-run]
-h
Show usage instructions.
-n, --dry-run
Dry run. Only output the commands that would be executed.
-p, --persistent
Make the modifications persistent across reboots.
"
# OVERRIDE DEFAULTS WITH ARGUMENTS
while [ -n "${1}" ]; do
case ${1} in
-h | --help) echo "${usage}" | less -FX; exit;;
-n | --dry-run) mode="echo";;
-p | --persistent) persistent="yes";;
*) echo "${usage}" | less -FX; exit 1
esac
shift
done
# FAIL IF VARIABLE IS NOT SET
set -u
# OBTAIN THE NUMBER OF DOM0 VCPUS
dom0_vcpus=`ls -d /sys/devices/system/cpu/cpu* | wc -l`
# PIN DOM0 VCPUS TO INITIAL PHYSICAL CPUS
for v in `seq 0 $((dom0_vcpus - 1))`; do
${mode} "xl vcpu-pin 0 ${v} 0-$((dom0_vcpus - 1))"
done
# OBTAIN THE NUMBER OF ALL PHYSICAL CPUS
dom0_uuid=`awk -F\' '/^INSTALLATION_UUID/ {print $2}' /etc/xensource-inventory`
all_pcpus=`xe host-cpu-list --minimal host-uuid=${dom0_uuid} | sed 's/,/ /g' | wc -w`
# OBTAIN DOM ID TO DOM UUID MAPPING
id_uuids=`list_domains | awk '{if ($1 != "id" && $1 != "0") print $1,$3}'`
# FOR EACH ONLINE USER DOMAIN
while read dom uuid; do
# OBTAIN THE NUMBER OF ITS VCPUS
vcpus=`xe vm-param-get uuid=${uuid} param-name=VCPUs-number`
# AND PIN THEM TO NON-DOM0 PHYSICAL CPUS
for v in `seq 0 $((vcpus - 1))`; do
${mode} "xl vcpu-pin ${dom} ${v} ${dom0_vcpus}-$((all_pcpus - 1))"
done
done < <(echo "$id_uuids")
if [ ! -z $persistent ]; then
# PERSIST VCPU PIN SETTINGS OF VMS
vm_uuids=`xe vm-list is-control-domain=false --minimal | sed 's/,/ /g'`
non_dom0_pcpus=`seq ${dom0_vcpus} $((all_vcpus - 1)) |tr '\n' ','|sed 's/,$//'`
for vm_uuid in $vm_uuids; do
${mode} "xe vm-param-set uuid=$vm_uuid VCPUs-params:mask=${non_dom0_pcpus}"
done
fi