76daa3
#! /bin/bash
76daa3
76daa3
kvm_setup_powerpc () {
76daa3
    if grep '^platform[[:space:]]*:[[:space:]]*PowerNV' /proc/cpuinfo > /dev/null; then
76daa3
	# PowerNV platform, which is KVM HV capable
76daa3
76daa3
	if [ -z "$SUBCORES" ]; then
76daa3
	    SUBCORES=1
76daa3
	fi
76daa3
76daa3
	# Step 1. Load the KVM HVmodule
76daa3
	if ! modprobe -b kvm_hv; then
76daa3
	    return
76daa3
	fi
76daa3
76daa3
	# On POWER8 a host core can only run threads of a single
76daa3
	# guest, meaning that SMT must be disabled on the host in
76daa3
	# order to run KVM guests. (Also applieds to POWER7, but we
76daa3
	# don't support that).
76daa3
	#
76daa3
	# POWER9 doesn't have this limitation (though it will for hash
76daa3
	# guests on radix host when that's implemented).  So, only set
76daa3
	# up subcores and disable SMT for POWER*.
76daa3
	if grep '^cpu[[:space:]]*:[[:space:]]*POWER8' /proc/cpuinfo > /dev/null; then
76daa3
	    # Step 2. Configure subcore mode
76daa3
	    /usr/sbin/ppc64_cpu --subcores-per-core=$SUBCORES
76daa3
76daa3
	    # Step 3. Disable SMT (multithreading)
76daa3
	    /usr/sbin/ppc64_cpu --smt=off
76daa3
	fi
76daa3
    fi
76daa3
}
76daa3
76daa3
case $(uname -m) in
76daa3
    ppc64|ppc64le)
76daa3
	kvm_setup_powerpc
76daa3
	;;
76daa3
esac
76daa3
76daa3
exit 0