From 204e40297ca5c675e13e74152d6e1ce330e3def3 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Thu, 29 Mar 2018 00:15:40 -0700 Subject: [PATCH] cli: Add configuration option for io-threads. Add option to configure if IO needs to be in a separate IO thread. Add tests to verify option is correctly parsed. The default value is set to false for now. This should be considered to be enabled by default in the future. Fixes #132 Signed-off-by: Archana Shinde --- Makefile | 4 ++++ cli/config.go | 3 +++ cli/config/configuration.toml.in | 6 ++++++ cli/config_test.go | 13 +++++++++++-- cli/kata-env_test.go | 5 ++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 91f9421549..2f190c4a30 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,7 @@ DEFNETWORKMODEL := macvtap DEFDISABLEBLOCK := false DEFBLOCKSTORAGEDRIVER := virtio-scsi +DEFENABLEIOTHREADS := false DEFENABLEMEMPREALLOC := false DEFENABLEHUGEPAGES := false DEFENABLESWAP := false @@ -172,6 +173,7 @@ USER_VARS += DEFBRIDGES USER_VARS += DEFNETWORKMODEL USER_VARS += DEFDISABLEBLOCK USER_VARS += DEFBLOCKSTORAGEDRIVER +USER_VARS += DEFENABLEIOTHREADS USER_VARS += DEFENABLEMEMPREALLOC USER_VARS += DEFENABLEHUGEPAGES USER_VARS += DEFENABLESWAP @@ -263,6 +265,7 @@ const defaultBridgesCount uint32 = $(DEFBRIDGES) const defaultInterNetworkingModel = "$(DEFNETWORKMODEL)" const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK) const defaultBlockDeviceDriver = "$(DEFBLOCKSTORAGEDRIVER)" +const defaultEnableIOThreads bool = $(DEFENABLEIOTHREADS) const defaultEnableMemPrealloc bool = $(DEFENABLEMEMPREALLOC) const defaultEnableHugePages bool = $(DEFENABLEHUGEPAGES) const defaultEnableSwap bool = $(DEFENABLESWAP) @@ -346,6 +349,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION -e "s|@DEFNETWORKMODEL@|$(DEFNETWORKMODEL)|g" \ -e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \ -e "s|@DEFBLOCKSTORAGEDRIVER@|$(DEFBLOCKSTORAGEDRIVER)|g" \ + -e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \ -e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \ -e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \ -e "s|@DEFENABLEMSWAP@|$(DEFENABLESWAP)|g" \ diff --git a/cli/config.go b/cli/config.go index e22f857e8c..98629e152e 100644 --- a/cli/config.go +++ b/cli/config.go @@ -92,6 +92,7 @@ type hypervisor struct { Swap bool `toml:"enable_swap"` Debug bool `toml:"enable_debug"` DisableNestingChecks bool `toml:"disable_nesting_checks"` + EnableIOThreads bool `toml:"enable_iothreads"` } type proxy struct { @@ -321,6 +322,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { Debug: h.Debug, DisableNestingChecks: h.DisableNestingChecks, BlockDeviceDriver: blockDriver, + EnableIOThreads: h.EnableIOThreads, }, nil } @@ -423,6 +425,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat Debug: defaultEnableDebug, DisableNestingChecks: defaultDisableNestingChecks, BlockDeviceDriver: defaultBlockDeviceDriver, + EnableIOThreads: defaultEnableIOThreads, } err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel) diff --git a/cli/config/configuration.toml.in b/cli/config/configuration.toml.in index e3416adaa9..307d841f35 100644 --- a/cli/config/configuration.toml.in +++ b/cli/config/configuration.toml.in @@ -70,6 +70,12 @@ disable_block_device_use = @DEFDISABLEBLOCK@ # virtio-blk. block_device_driver = "@DEFBLOCKSTORAGEDRIVER@" +# Enable iothreads (data-plane) to be used. This causes IO to be +# handled in a separate IO thread. This is currently only implemented +# for SCSI. +# +enable_iothreads = @DEFENABLEIOTHREADS@ + # Enable pre allocation of VM RAM, default false # Enabling this will result in lower container density # as all of the memory will be allocated and locked diff --git a/cli/config_test.go b/cli/config_test.go index 54f358179b..6b3f7c5818 100644 --- a/cli/config_test.go +++ b/cli/config_test.go @@ -41,7 +41,7 @@ type testRuntimeConfig struct { LogPath string } -func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool, blockDeviceDriver string) string { +func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool, blockDeviceDriver string, enableIOThreads bool) string { return ` # Runtime configuration file @@ -55,6 +55,7 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath default_vcpus = ` + strconv.FormatUint(uint64(defaultVCPUCount), 10) + ` default_memory = ` + strconv.FormatUint(uint64(defaultMemSize), 10) + ` disable_block_device_use = ` + strconv.FormatBool(disableBlock) + ` + enable_iothreads = ` + strconv.FormatBool(enableIOThreads) + ` [proxy.kata] path = "` + proxyPath + `" @@ -101,8 +102,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf machineType := "machineType" disableBlockDevice := true blockDeviceDriver := "virtio-scsi" + enableIOThreads := true - runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath, disableBlockDevice, blockDeviceDriver) + runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath, disableBlockDevice, blockDeviceDriver, enableIOThreads) configPath := path.Join(dir, "runtime.toml") err = createConfig(configPath, runtimeConfigFileData) @@ -140,6 +142,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf BlockDeviceDriver: defaultBlockDeviceDriver, DefaultBridges: defaultBridgesCount, Mlock: !defaultEnableSwap, + EnableIOThreads: enableIOThreads, } agentConfig := vc.KataAgentConfig{} @@ -569,6 +572,7 @@ func TestNewQemuHypervisorConfig(t *testing.T) { imagePath := path.Join(dir, "image") machineType := "machineType" disableBlock := true + enableIOThreads := true hypervisor := hypervisor{ Path: hypervisorPath, @@ -576,6 +580,7 @@ func TestNewQemuHypervisorConfig(t *testing.T) { Image: imagePath, MachineType: machineType, DisableBlockDeviceUse: disableBlock, + EnableIOThreads: enableIOThreads, } files := []string{hypervisorPath, kernelPath, imagePath} @@ -617,6 +622,10 @@ func TestNewQemuHypervisorConfig(t *testing.T) { t.Errorf("Expected value for disable block usage %v, got %v", disableBlock, config.DisableBlockDeviceUse) } + if config.EnableIOThreads != enableIOThreads { + t.Errorf("Expected value for enable IOThreads %v, got %v", enableIOThreads, config.EnableIOThreads) + } + } func TestNewShimConfig(t *testing.T) { diff --git a/cli/kata-env_test.go b/cli/kata-env_test.go index 9393cb863c..ee21c0e3d0 100644 --- a/cli/kata-env_test.go +++ b/cli/kata-env_test.go @@ -69,6 +69,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC proxyPath := filepath.Join(prefixDir, "proxy") disableBlock := true blockStorageDriver := "virtio-scsi" + enableIOThreads := true // override defaultProxyPath = proxyPath @@ -112,7 +113,9 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC testProxyURL, logPath, disableBlock, - blockStorageDriver) + blockStorageDriver, + enableIOThreads, + ) configFile = path.Join(prefixDir, "runtime.toml") err = createConfig(configFile, runtimeConfig)