Add guest environment setup scripts 57/4557/4
authorYunhong Jiang <yunhong.jiang@linux.intel.com>
Fri, 4 Dec 2015 19:58:39 +0000 (14:58 -0500)
committerYunhong Jiang <yunhong.jiang@linux.intel.com>
Wed, 6 Jan 2016 03:32:47 +0000 (19:32 -0800)
To achieve good real time and live migration performance, special setup
is needed on guest environment.

Two scripts are used to setup the guest environment. The guest-setup0.sh
setup the environment that should take effect before the tested kernel is
bringup, including install the kernel rpm, the rt-test package and modify
the grub entries. The guest-setup1.sh setup the environment that takes
effect after the tested kernel is up, like some sysfs entry, interrupt
affinity etc.

Change-Id: Icaed71e250b314723d6b1814c9ac33c10d99c6a0
Signed-off-by: David Su <david.w.su@intel.com>
Signed-off-by: Yunhong Jiang <yunhong.jiang@linux.intel.com>
ci/envs/guest-setup0.sh [new file with mode: 0755]
ci/envs/guest-setup1.sh [new file with mode: 0755]

diff --git a/ci/envs/guest-setup0.sh b/ci/envs/guest-setup0.sh
new file mode 100755 (executable)
index 0000000..490bd57
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/bash
+##############################################################################
+## Copyright (c) 2015 Intel Corp.
+##
+## All rights reserved. This program and the accompanying materials
+## are made available under the terms of the Apache License, Version 2.0
+## which accompanies this distribution, and is available at
+## http://www.apache.org/licenses/LICENSE-2.0
+###############################################################################
+
+
+rpmdir=${1:-"/root/workspace/"}
+rpmpat="kernel-4.1*.rpm"
+rpm -ihv ${rpmdir}/rt-tests-0.96-1.el7.centos.x86_64.rpm
+guest_isolcpus=1
+
+# The script's caller should passing the rpm directory that is built out from 
+# build.sh. The default rpmdir is the one used by yardstick scripts.
+install_kernel () {
+    # Install the kernel rpm
+    filenum=`ls -l ${rpmdir}/${rpmpat} |wc -l`
+    if [ $filenum -eq 0 ]
+    then
+       echo "No kernel rpm found in workspace/rpm"
+       exit 1
+    elif [ $filenum -gt 1 ]
+    then
+       echo "Multiple kernel rpm found in workspace/rpm"
+       exit 1
+    else
+       krpm=`find "${rpmdir}" -name "${rpmpat}"`
+       rpm -ihv $krpm
+    fi
+}
+
+config_grub () {
+    key=$1
+    val=$2
+
+    if  grep '[" ]'${key} /etc/default/grub > /dev/null ; then
+        sed -i  's/\([" ]\)'${key}'=[^ "]*/\1'${key}'='${val}'/' /etc/default/grub
+    else
+        sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="\1 '${key}'='${val}'"/' /etc/default/grub
+    fi
+}
+
+# Isolate CPUs from the general scheduler
+config_grub 'isolcpus' ${guest_isolcpus}
+
+# Stop timer ticks on isolated CPUs whenever possible
+config_grub 'nohz_full' ${guest_isolcpus}
+
+# Disable machine check
+config_grub 'mce' 'off'
+
+# Use polling idle loop to improve performance
+config_grub 'idle' 'poll'
+
+## Disable clocksource verification at runtime
+config_grub 'tsc' 'reliable'
+
+grub2-mkconfig -o /boot/grub2/grub.cfg
+install_kernel
diff --git a/ci/envs/guest-setup1.sh b/ci/envs/guest-setup1.sh
new file mode 100755 (executable)
index 0000000..678baa4
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+##############################################################################
+## Copyright (c) 2015 Intel Corp.
+##
+## All rights reserved. This program and the accompanying materials
+## are made available under the terms of the Apache License, Version 2.0
+## which accompanies this distribution, and is available at
+## http://www.apache.org/licenses/LICENSE-2.0
+###############################################################################
+
+set_irq_affinity () {
+    for irq in /proc/irq/* ; do
+       echo 0 > /proc/irq/${1}/smp_affinity_list
+    done
+}
+
+# Disable watchdogs to reduce overhead
+echo 0 > /proc/sys/kernel/watchdog
+echo 0 > /proc/sys/kernel/nmi_watchdog
+
+# Route device interrupts to non-RT CPU
+set_irq_affinity
+
+# Disable RT throttling
+echo -1 > /proc/sys/kernel/sched_rt_period_us
+echo -1 > /proc/sys/kernel/sched_rt_runtime_us