From ddee41d5538f0fa422f6b83ffb18058c30c6a8eb Mon Sep 17 00:00:00 2001 From: Manohar Castelino Date: Wed, 13 Sep 2017 07:48:15 -0700 Subject: [PATCH] QEMU: Enable realtime options Enable realtime options in QEMU. Also add support to control memory locking. Turning realtime on with memory locking disabled allows memory to be swapped out, potentially increasing density of VMs. Signed-off-by: Manohar Castelino --- qemu.go | 16 ++++++++++++++++ qemu_test.go | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/qemu.go b/qemu.go index e6ace3f945..21868ac232 100644 --- a/qemu.go +++ b/qemu.go @@ -744,6 +744,13 @@ type Knobs struct { // MemPrealloc will allocate all the RAM upfront MemPrealloc bool + + // Mlock will control locking of memory + // Only active when Realtime is set to true + Mlock bool + + // Realtime will enable realtime QEMU + Realtime bool } // Config is the qemu configuration structure. @@ -1005,6 +1012,15 @@ func (config *Config) appendKnobs() { config.qemuParams = append(config.qemuParams, deviceMemParam) } } + + if config.Knobs.Realtime == true { + config.qemuParams = append(config.qemuParams, "-realtime") + if config.Knobs.Mlock == true { + config.qemuParams = append(config.qemuParams, "mlock=on") + } else { + config.qemuParams = append(config.qemuParams, "mlock=off") + } + } } // LaunchQemu can be used to launch a new qemu instance. diff --git a/qemu_test.go b/qemu_test.go index ae9d31d9a4..317d2a0488 100644 --- a/qemu_test.go +++ b/qemu_test.go @@ -223,7 +223,7 @@ func TestAppendEmptyDevice(t *testing.T) { testAppend(device, "", t) } -var knobsString = "-no-user-config -nodefaults -nographic -daemonize" +var knobsString = "-no-user-config -nodefaults -nographic -daemonize -realtime mlock=on" func TestAppendKnobsAllTrue(t *testing.T) { knobs := Knobs{ @@ -232,6 +232,8 @@ func TestAppendKnobsAllTrue(t *testing.T) { NoGraphic: true, Daemonize: true, MemPrealloc: true, + Realtime: true, + Mlock: true, } testAppend(knobs, knobsString, t) @@ -243,6 +245,8 @@ func TestAppendKnobsAllFalse(t *testing.T) { NoDefaults: false, NoGraphic: false, MemPrealloc: false, + Realtime: false, + Mlock: false, } testAppend(knobs, "", t)