integ/virt/libvirt/libvirt/hooks/qemu

71 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# This script logs to user.log
#
# The script is called with the following parameters
# e.g. /etc/libvirt/hooks/qemu <guest_name> <operation>
#
# Save the instance's XML. The guest qemu hook scrips are given the full XML description
# on their stdin.
XML_DATA=$(/bin/cat)
GUEST_NAME=$1
shift
OPERATION=$*
logger -p info -t ${0} "hook qemu file guest ${GUEST_NAME} with operation ${OPERATION}"
# CPU Low latency setup:
#
# A cpu is set to low latency when:
# 1) host is set to subfunction=lowlatency in platform.conf and
# 2) domain has dedicated pinning
#
# example of <cputune> section when domain has dedicated pinning:
# <cputune>
# <vcpupin vcpu='0' cpuset='5'/>
# <vcpupin vcpu='1' cpuset='6'/>
# <vcpupin vcpu='2' cpuset='7'/>
# <emulatorpin cpuset='5'/>
# </cputune>
#
# example of <cputune> section when domain has shared pinning:
# <cputune>
# <shares>4096</shares>
# <vcpupin vcpu='0' cpuset='5-21'/>
# <vcpupin vcpu='1' cpuset='5-21'/>
# <vcpupin vcpu='2' cpuset='5-21'/>
# <vcpupin vcpu='3' cpuset='5-21'/>
# <emulatorpin cpuset='5-21'/>
# </cputune>
if [ "${OPERATION}" == "prepare begin -" ] || [ "${OPERATION}" == "stopped end -" ]; then
# verify this host is set as lowlatency
lowlat=$(cat /etc/platform/platform.conf 2>/dev/null | grep -E 'subfunction.*lowlatency')
if [ -n "${lowlat}" ]; then
# grab the <cputune> settings and remove single quotes
CPUTUNE=$(echo ${XML_DATA} | grep -oP '(?<=<cputune).*?(?=</cputune>)' | sed "s/'//g")
# grab all cpuset pinned to a unique CPU. Treat them as dedicated
CPUSET=($(echo ${CPUTUNE} | grep -oP '(?<=cpuset=)[^/]+(?=.+emulator)' | grep -vP '[^0-9]'))
if [ ${#CPUSET[@]} -ne 0 ]; then
# convert to a comma separated list
CPUS=$(IFS=, ; echo "${CPUSET[*]}")
if [ "${OPERATION}" == "prepare begin -" ]; then
/usr/bin/set-cpu-wakeup-latency.sh "low" "${CPUS}"
else
/usr/bin/set-cpu-wakeup-latency.sh "high" "${CPUS}"
fi
fi
fi
fi
exit 0