Blame SOURCES/kvm-setup

1bdc94
#!/bin/bash
4a2fec
4a2fec
kvm_setup_powerpc () {
1bdc94
    isPowerNV=no
1bdc94
    isPOWER8=no
1bdc94
1bdc94
    grep -q '^platform[[:space:]]*:[[:space:]]*PowerNV' /proc/cpuinfo && isPowerNV=yes
1bdc94
    grep -q '^cpu[[:space:]]*:[[:space:]]*POWER8' /proc/cpuinfo && isPOWER8=yes
1bdc94
1bdc94
    if [ "$isPowerNV" = "yes" ] ; then
4a2fec
	# PowerNV platform, which is KVM HV capable
4a2fec
4a2fec
	if [ -z "$SUBCORES" ]; then
4a2fec
	    SUBCORES=1
4a2fec
	fi
4a2fec
4a2fec
	# Step 1. Load the KVM HVmodule
4a2fec
	if ! modprobe -b kvm_hv; then
4a2fec
	    return
4a2fec
	fi
4a2fec
4a2fec
	# On POWER8 a host core can only run threads of a single
4a2fec
	# guest, meaning that SMT must be disabled on the host in
4a2fec
	# order to run KVM guests. (Also applieds to POWER7, but we
4a2fec
	# don't support that).
4a2fec
	#
1bdc94
	# Additionally, POWER8 guests can't benefit from transparent
1bdc94
	# hugepages used to back them, and THPs allocated by any app
1bdc94
	# can potentially interfere with HPT allocation (if they
1bdc94
	# become locked, they can fragment the CMA).  So, also disable
1bdc94
	# THPs system wide.
1bdc94
	#
4a2fec
	# POWER9 doesn't have this limitation (though it will for hash
4a2fec
	# guests on radix host when that's implemented).  So, only set
4a2fec
	# up subcores and disable SMT for POWER*.
1bdc94
	if [ "$isPOWER8" = "yes" ] ; then
4a2fec
	    # Step 2. Configure subcore mode
4a2fec
	    /usr/sbin/ppc64_cpu --subcores-per-core=$SUBCORES
4a2fec
4a2fec
	    # Step 3. Disable SMT (multithreading)
4a2fec
	    /usr/sbin/ppc64_cpu --smt=off
1bdc94
1bdc94
	    # Step 4. Disable transparent hugepages (THP)
1bdc94
	    echo never > /sys/kernel/mm/transparent_hugepage/enabled
4a2fec
	fi
4a2fec
    fi
4a2fec
}
4a2fec
4a2fec
case $(uname -m) in
4a2fec
    ppc64|ppc64le)
4a2fec
	kvm_setup_powerpc
4a2fec
	;;
4a2fec
esac
4a2fec
4a2fec
exit 0