From e0cf9d5c148c70877645acf82f9605938879f390 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Mon, 22 Jul 2019 13:28:30 +0200 Subject: [PATCH 1/2] qmp: add checks for the CPU toplogy Support for function isSocketIDSupported, isThreadIDSupported and isDieIDSupported. The functions check if the cpu driver and the qemu version support the id parameter. Fixes: #102 Signed-off-by: Alice Frosi --- qemu/qmp.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/qemu/qmp.go b/qemu/qmp.go index db75ba7c83..2a645ca24f 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -1158,6 +1158,30 @@ func (q *QMP) ExecutePCIVFIOMediatedDeviceAdd(ctx context.Context, devID, sysfsd return q.executeCommand(ctx, "device_add", args, nil) } +// isSocketIDSupported returns if the cpu driver supports the socket id option +func isSocketIDSupported(driver string) bool { + if driver == "host-s390x-cpu" || driver == "host-powerpc64-cpu" { + return false + } + return true +} + +// isThreadIDSupported returns if the cpu driver supports the thread id option +func isThreadIDSupported(driver string) bool { + if driver == "host-s390x-cpu" || driver == "host-powerpc64-cpu" { + return false + } + return true +} + +// isDieIDSupported returns if the cpu driver and the qemu version support the die id option +func (q *QMP) isDieIDSupported(driver string) bool { + if (q.version.Major > 4 || (q.version.Major == 4 && q.version.Minor >= 1)) && driver == "host-x86_64-cpu" { + return true + } + return false +} + // ExecuteCPUDeviceAdd adds a CPU to a QEMU instance using the device_add command. // driver is the CPU model, cpuID must be a unique ID to identify the CPU, socketID is the socket number within // node/board the CPU belongs to, coreID is the core number within socket the CPU belongs to, threadID is the @@ -1170,15 +1194,15 @@ func (q *QMP) ExecuteCPUDeviceAdd(ctx context.Context, driver, cpuID, socketID, "core-id": coreID, } - if socketID != "" { + if socketID != "" && isSocketIDSupported(driver) { args["socket-id"] = socketID } - if threadID != "" { + if threadID != "" && isThreadIDSupported(driver) { args["thread-id"] = threadID } - if q.version.Major > 4 || (q.version.Major == 4 && q.version.Minor >= 1) { + if q.isDieIDSupported(driver) { if dieID != "" { args["die-id"] = dieID } From 68cdf64fe5070c8e25a938d563fbcced23571398 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Thu, 25 Jul 2019 15:53:33 +0200 Subject: [PATCH 2/2] test: add cpu topology tests Add cpu driver types in TestQMPCPUDeviceAdd Signed-off-by: Alice Frosi --- qemu/qmp_test.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index 7598c8cd03..11b33a0e05 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -1059,29 +1059,32 @@ func TestQMPPCIVFIOMediatedDeviceAdd(t *testing.T) { // Checks that CPU are correctly added using device_add func TestQMPCPUDeviceAdd(t *testing.T) { - connectedCh := make(chan *QMPVersion) - disconnectedCh := make(chan struct{}) - buf := newQMPTestCommandBuffer(t) - buf.AddCommand("device_add", nil, "return", nil) - cfg := QMPConfig{Logger: qmpTestLogger{}} - q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) - checkVersion(t, connectedCh) - driver := "qemu64-x86_64-cpu" + drivers := []string{"host-x86_64-cpu", "host-s390x-cpu", "host-powerpc64-cpu"} cpuID := "cpu-0" socketID := "0" dieID := "0" coreID := "1" threadID := "0" - q.version = &QMPVersion{ + version := &QMPVersion{ Major: 4, Minor: 1, } - err := q.ExecuteCPUDeviceAdd(context.Background(), driver, cpuID, socketID, dieID, coreID, threadID, "") - if err != nil { - t.Fatalf("Unexpected error %v", err) + for _, d := range drivers { + connectedCh := make(chan *QMPVersion) + disconnectedCh := make(chan struct{}) + buf := newQMPTestCommandBuffer(t) + buf.AddCommand("device_add", nil, "return", nil) + cfg := QMPConfig{Logger: qmpTestLogger{}} + q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) + checkVersion(t, connectedCh) + q.version = version + err := q.ExecuteCPUDeviceAdd(context.Background(), d, cpuID, socketID, dieID, coreID, threadID, "") + if err != nil { + t.Fatalf("Unexpected error %v", err) + } + q.Shutdown() + <-disconnectedCh } - q.Shutdown() - <-disconnectedCh } // Checks that hotpluggable CPUs are listed correctly