Blob Blame History Raw
From c4a0aef63df41a79e96c1276ac732ecde8d58d86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= <jskarvad@redhat.com>
Date: Thu, 22 Nov 2018 17:38:12 +0100
Subject: [PATCH] functions: reworked setup_kvm_mod_low_latency to count with
 kernel changes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It updates the KVM modprobe file if its content differs from what's
supported on the current system. It may look a bit over-engineered, but
it's done this way to lower the possibility of race condition.

Resolves: rhbz#1649408

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
---
 profiles/functions | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/profiles/functions b/profiles/functions
index 919409c..aab608a 100644
--- a/profiles/functions
+++ b/profiles/functions
@@ -503,26 +503,29 @@ eee_set_normal_fsb() {
 
 kvm_modprobe_file=/etc/modprobe.d/kvm.rt.tuned.conf
 
-setup_kvm_mod_low_latency()
+teardown_kvm_mod_low_latency()
 {
-	if [ -f $kvm_modprobe_file ]; then
-		return
-	fi
-
-	modinfo -p kvm | grep -q kvmclock_periodic_sync
-	if [ "$?" -eq 0 ]; then
-		echo "options kvm kvmclock_periodic_sync=0" > $kvm_modprobe_file
-	fi
-
-	modinfo -p kvm_intel | grep -q ple_gap
-	if [ "$?" -eq 0 ]; then
-		echo "options kvm_intel ple_gap=0" >> $kvm_modprobe_file
-	fi
+	rm -f $kvm_modprobe_file
 }
 
-teardown_kvm_mod_low_latency()
+setup_kvm_mod_low_latency()
 {
-	rm -f $kvm_modprobe_file
+	local HAS_KPS=""
+	local HAS_PLE_GAP=""
+	local WANTS_KPS=""
+	local WANTS_PLE_GAP=""
+
+	modinfo -p kvm | grep -q kvmclock_periodic_sync && HAS_KPS=1
+	modinfo -p kvm_intel | grep -q ple_gap && HAS_PLE_GAP=1
+	grep -qs kvmclock_periodic_sync "$kvm_modprobe_file" && WANTS_KPS=1
+	grep -qs ple_gap "$kvm_modprobe_file" && WANTS_PLE_GAP=1
+
+	if [ "$HAS_KPS" != "$WANTS_KPS" -o "$HAS_PLE_GAP" != "$WANTS_PLE_GAP" ]; then
+		teardown_kvm_mod_low_latency
+		[ "$HAS_KPS" ] && echo "options kvm kvmclock_periodic_sync=0" > $kvm_modprobe_file
+		[ "$HAS_PLE_GAP" ] && echo "options kvm_intel ple_gap=0" >> $kvm_modprobe_file
+	fi
+	return 0
 }
 
 #
-- 
2.14.5