Skip to content

Commit

Permalink
Merge pull request #362 from bergwolf/runtime-port-4
Browse files Browse the repository at this point in the history
Runtime port  -- wave 3
  • Loading branch information
gnawux committed Jun 30, 2020
2 parents c03b796 + 7ae4376 commit 2b619c0
Show file tree
Hide file tree
Showing 40 changed files with 577 additions and 138 deletions.
11 changes: 9 additions & 2 deletions src/runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ DEFSHAREDFS_QEMU_VIRTIOFS := virtio-fs
DEFVIRTIOFSDAEMON := $(VIRTIOFSDBINDIR)/virtiofsd
# Default DAX mapping cache size in MiB
DEFVIRTIOFSCACHESIZE := 1024
DEFVIRTIOFSCACHE := always
DEFVIRTIOFSEXTRAARGS := []
DEFVIRTIOFSCACHE ?= auto
# Format example:
# [\"-o\", \"arg1=xxx,arg2\", \"-o\", \"hello world\", \"--arg3=yyy\"]
#
# see `virtiofsd -h` for possible options.
# Make sure you quote args.
DEFVIRTIOFSEXTRAARGS ?= []
DEFENABLEIOTHREADS := false
DEFENABLEMEMPREALLOC := false
DEFENABLEHUGEPAGES := false
Expand Down Expand Up @@ -398,6 +403,7 @@ USER_VARS += KERNELTYPE_ACRN
USER_VARS += KERNELTYPE_CLH
USER_VARS += FIRMWAREPATH
USER_VARS += MACHINEACCELERATORS
USER_VARS += CPUFEATURES
USER_VARS += DEFMACHINETYPE_CLH
USER_VARS += KERNELPARAMS
USER_VARS += LIBEXECDIR
Expand Down Expand Up @@ -606,6 +612,7 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit
-e "s|@INITRDPATH@|$(INITRDPATH)|g" \
-e "s|@FIRMWAREPATH@|$(FIRMWAREPATH)|g" \
-e "s|@MACHINEACCELERATORS@|$(MACHINEACCELERATORS)|g" \
-e "s|@CPUFEATURES@|$(CPUFEATURES)|g" \
-e "s|@FIRMWAREPATH_CLH@|$(FIRMWAREPATH_CLH)|g" \
-e "s|@DEFMACHINETYPE_CLH@|$(DEFMACHINETYPE_CLH)|g" \
-e "s|@KERNELPARAMS@|$(KERNELPARAMS)|g" \
Expand Down
1 change: 1 addition & 0 deletions src/runtime/arch/amd64-options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
MACHINETYPE := pc
KERNELPARAMS :=
MACHINEACCELERATORS :=
CPUFEATURES := pmu=off

QEMUCMD := qemu-system-x86_64

Expand Down
1 change: 1 addition & 0 deletions src/runtime/arch/arm64-options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
MACHINETYPE := virt
KERNELPARAMS :=
MACHINEACCELERATORS :=
CPUFEATURES := pmu=off

QEMUCMD := qemu-system-aarch64

Expand Down
1 change: 1 addition & 0 deletions src/runtime/arch/ppc64le-options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
MACHINETYPE := pseries
KERNELPARAMS :=
MACHINEACCELERATORS := "cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-large-decr=off,cap-ccf-assist=off"
CPUFEATURES :=
KERNELTYPE := uncompressed #This architecture must use an uncompressed kernel.
QEMUCMD := qemu-system-ppc64
1 change: 1 addition & 0 deletions src/runtime/arch/s390x-options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
MACHINETYPE := s390-ccw-virtio
KERNELPARAMS :=
MACHINEACCELERATORS :=
CPUFEATURES :=

QEMUCMD := qemu-system-s390x
29 changes: 27 additions & 2 deletions src/runtime/cli/config/configuration-clh.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,33 @@ virtio_fs_daemon = "@DEFVIRTIOFSDAEMON@"
# Default size of DAX cache in MiB
virtio_fs_cache_size = @DEFVIRTIOFSCACHESIZE@

# cloud-hypervisor prefers virtiofs caching (dax) for performance reasons
virtio_fs_cache = "always"
# Extra args for virtiofsd daemon
#
# Format example:
# ["-o", "arg1=xxx,arg2", "-o", "hello world", "--arg3=yyy"]
#
# see `virtiofsd -h` for possible options.
virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@

# Cache mode:
#
# - none
# Metadata, data, and pathname lookup are not cached in guest. They are
# always fetched from host and any changes are immediately pushed to host.
#
# - auto
# Metadata and pathname lookup cache expires after a configured amount of
# time (default is 1 second). Data is cached while the file is open (close
# to open consistency).
#
# - always
# Metadata, data, and pathname lookup are cached in guest and never expire.
virtio_fs_cache = "@DEFVIRTIOFSCACHE@"

# Block storage driver to be used for the hypervisor in case the container
# rootfs is backed by a block device. This is virtio-scsi, virtio-blk
# or nvdimm.
block_device_driver = "virtio-blk"

# This option changes the default hypervisor and kernel parameters
# to enable debug output where available. This extra output is added
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/cli/config/configuration-qemu-virtiofs.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ firmware = "@FIRMWAREPATH@"
# For example, `machine_accelerators = "nosmm,nosmbus,nosata,nopit,static-prt,nofw"`
machine_accelerators="@MACHINEACCELERATORS@"

# CPU features
# comma-separated list of cpu features to pass to the cpu
# For example, `cpu_features = "pmu=off,vmx=off"
cpu_features="@CPUFEATURES@"

# Default number of vCPUs per SB/VM:
# unspecified or 0 --> will be set to @DEFVCPUS@
# < 0 --> will be set to the actual number of physical cores
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/cli/config/configuration-qemu.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ firmware = "@FIRMWAREPATH@"
# For example, `machine_accelerators = "nosmm,nosmbus,nosata,nopit,static-prt,nofw"`
machine_accelerators="@MACHINEACCELERATORS@"

# CPU features
# comma-separated list of cpu features to pass to the cpu
# For example, `cpu_features = "pmu=off,vmx=off"
cpu_features="@CPUFEATURES@"

# Default number of vCPUs per SB/VM:
# unspecified or 0 --> will be set to @DEFVCPUS@
# < 0 --> will be set to the actual number of physical cores
Expand Down
4 changes: 0 additions & 4 deletions src/runtime/cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"os"
runtim "runtime"
"strings"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -223,9 +222,6 @@ func getHostInfo() (HostInfo, error) {
}

hostVMContainerCapable := true
if runtim.GOARCH == "ppc64le" {
hostVMContainerCapable = false
}

details := vmContainerCapableDetails{
cpuInfoFile: procCPUInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/cli/kata-env_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "testing"
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
expectedVendor := ""
expectedModel := "POWER8"
expectedVMContainerCapable := false
expectedVMContainerCapable := true
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel, expectedVMContainerCapable)
}

Expand Down
1 change: 1 addition & 0 deletions src/runtime/pkg/katautils/config-settings.go.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var defaultKernelPath = "/usr/share/kata-containers/vmlinuz.container"
var defaultInitrdPath = "/usr/share/kata-containers/kata-containers-initrd.img"
var defaultFirmwarePath = ""
var defaultMachineAccelerators = ""
var defaultCPUFeatures = ""
var defaultShimPath = "/usr/libexec/kata-containers/kata-shim"
var systemdUnitName = "kata-containers.target"

Expand Down
26 changes: 21 additions & 5 deletions src/runtime/pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type hypervisor struct {
Image string `toml:"image"`
Firmware string `toml:"firmware"`
MachineAccelerators string `toml:"machine_accelerators"`
CPUFeatures string `toml:"cpu_features"`
KernelParams string `toml:"kernel_params"`
MachineType string `toml:"machine_type"`
BlockDeviceDriver string `toml:"block_device_driver"`
Expand Down Expand Up @@ -244,11 +245,9 @@ func (h hypervisor) firmware() (string, error) {

func (h hypervisor) machineAccelerators() string {
var machineAccelerators string
accelerators := strings.Split(h.MachineAccelerators, ",")
acceleratorsLen := len(accelerators)
for i := 0; i < acceleratorsLen; i++ {
if accelerators[i] != "" {
machineAccelerators += strings.Trim(accelerators[i], "\r\t\n ") + ","
for _, accelerator := range strings.Split(h.MachineAccelerators, ",") {
if accelerator != "" {
machineAccelerators += strings.TrimSpace(accelerator) + ","
}
}

Expand All @@ -257,6 +256,19 @@ func (h hypervisor) machineAccelerators() string {
return machineAccelerators
}

func (h hypervisor) cpuFeatures() string {
var cpuFeatures string
for _, feature := range strings.Split(h.CPUFeatures, ",") {
if feature != "" {
cpuFeatures += strings.TrimSpace(feature) + ","
}
}

cpuFeatures = strings.Trim(cpuFeatures, ",")

return cpuFeatures
}

func (h hypervisor) kernelParams() string {
if h.KernelParams == "" {
return defaultKernelParams
Expand Down Expand Up @@ -624,6 +636,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
}

machineAccelerators := h.machineAccelerators()
cpuFeatures := h.cpuFeatures()
kernelParams := h.kernelParams()
machineType := h.machineType()

Expand Down Expand Up @@ -677,6 +690,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
ImagePath: image,
FirmwarePath: firmware,
MachineAccelerators: machineAccelerators,
CPUFeatures: cpuFeatures,
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
HypervisorMachineType: machineType,
NumVCPUs: h.defaultVCPUs(),
Expand Down Expand Up @@ -865,6 +879,7 @@ func newClhHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
PCIeRootPort: h.PCIeRootPort,
DisableVhostNet: true,
UseVSock: true,
VirtioFSExtraArgs: h.VirtioFSExtraArgs,
}, nil
}

Expand Down Expand Up @@ -1129,6 +1144,7 @@ func GetDefaultHypervisorConfig() vc.HypervisorConfig {
InitrdPath: defaultInitrdPath,
FirmwarePath: defaultFirmwarePath,
MachineAccelerators: defaultMachineAccelerators,
CPUFeatures: defaultCPUFeatures,
HypervisorMachineType: defaultMachineType,
NumVCPUs: defaultVCPUCount,
DefaultMaxVCPUs: defaultMaxVCPUCount,
Expand Down
47 changes: 47 additions & 0 deletions src/runtime/pkg/katautils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,53 @@ func TestDefaultMachineAccelerators(t *testing.T) {
assert.Equal(machineAccelerators, h.machineAccelerators())
}

func TestDefaultCPUFeatures(t *testing.T) {
assert := assert.New(t)
cpuFeatures := "abc,123,rgb"
h := hypervisor{CPUFeatures: cpuFeatures}
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = ""
h.CPUFeatures = cpuFeatures
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc"
h.CPUFeatures = cpuFeatures
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc,123"
h.CPUFeatures = "abc,,123"
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc,123"
h.CPUFeatures = ",,abc,,123,,,"
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc,123"
h.CPUFeatures = "abc,,123,,,"
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc"
h.CPUFeatures = ",,abc,"
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc"
h.CPUFeatures = ", , abc , ,"
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc"
h.CPUFeatures = " abc "
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc,123"
h.CPUFeatures = ", abc , 123 ,"
assert.Equal(cpuFeatures, h.cpuFeatures())

cpuFeatures = "abc,123"
h.CPUFeatures = ",, abc ,,, 123 ,,"
assert.Equal(cpuFeatures, h.cpuFeatures())
}

func TestUpdateRuntimeConfiguration(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 2b619c0

Please sign in to comment.