diff --git a/qemu.go b/qemu.go index e6ace3f94..21868ac23 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 ae9d31d9a..317d2a048 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)