mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-09 11:58:16 +00:00
Merge pull request #103 from alicefr/cpu_topology
qmp: add checks for the CPU toplogy
This commit is contained in:
commit
e0505242c0
30
qemu/qmp.go
30
qemu/qmp.go
@ -1158,6 +1158,30 @@ func (q *QMP) ExecutePCIVFIOMediatedDeviceAdd(ctx context.Context, devID, sysfsd
|
|||||||
return q.executeCommand(ctx, "device_add", args, nil)
|
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.
|
// 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
|
// 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
|
// 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,
|
"core-id": coreID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if socketID != "" {
|
if socketID != "" && isSocketIDSupported(driver) {
|
||||||
args["socket-id"] = socketID
|
args["socket-id"] = socketID
|
||||||
}
|
}
|
||||||
|
|
||||||
if threadID != "" {
|
if threadID != "" && isThreadIDSupported(driver) {
|
||||||
args["thread-id"] = threadID
|
args["thread-id"] = threadID
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.version.Major > 4 || (q.version.Major == 4 && q.version.Minor >= 1) {
|
if q.isDieIDSupported(driver) {
|
||||||
if dieID != "" {
|
if dieID != "" {
|
||||||
args["die-id"] = dieID
|
args["die-id"] = dieID
|
||||||
}
|
}
|
||||||
|
@ -1059,6 +1059,17 @@ func TestQMPPCIVFIOMediatedDeviceAdd(t *testing.T) {
|
|||||||
|
|
||||||
// Checks that CPU are correctly added using device_add
|
// Checks that CPU are correctly added using device_add
|
||||||
func TestQMPCPUDeviceAdd(t *testing.T) {
|
func TestQMPCPUDeviceAdd(t *testing.T) {
|
||||||
|
drivers := []string{"host-x86_64-cpu", "host-s390x-cpu", "host-powerpc64-cpu"}
|
||||||
|
cpuID := "cpu-0"
|
||||||
|
socketID := "0"
|
||||||
|
dieID := "0"
|
||||||
|
coreID := "1"
|
||||||
|
threadID := "0"
|
||||||
|
version := &QMPVersion{
|
||||||
|
Major: 4,
|
||||||
|
Minor: 1,
|
||||||
|
}
|
||||||
|
for _, d := range drivers {
|
||||||
connectedCh := make(chan *QMPVersion)
|
connectedCh := make(chan *QMPVersion)
|
||||||
disconnectedCh := make(chan struct{})
|
disconnectedCh := make(chan struct{})
|
||||||
buf := newQMPTestCommandBuffer(t)
|
buf := newQMPTestCommandBuffer(t)
|
||||||
@ -1066,22 +1077,14 @@ func TestQMPCPUDeviceAdd(t *testing.T) {
|
|||||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
checkVersion(t, connectedCh)
|
checkVersion(t, connectedCh)
|
||||||
driver := "qemu64-x86_64-cpu"
|
q.version = version
|
||||||
cpuID := "cpu-0"
|
err := q.ExecuteCPUDeviceAdd(context.Background(), d, cpuID, socketID, dieID, coreID, threadID, "")
|
||||||
socketID := "0"
|
|
||||||
dieID := "0"
|
|
||||||
coreID := "1"
|
|
||||||
threadID := "0"
|
|
||||||
q.version = &QMPVersion{
|
|
||||||
Major: 4,
|
|
||||||
Minor: 1,
|
|
||||||
}
|
|
||||||
err := q.ExecuteCPUDeviceAdd(context.Background(), driver, cpuID, socketID, dieID, coreID, threadID, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
q.Shutdown()
|
q.Shutdown()
|
||||||
<-disconnectedCh
|
<-disconnectedCh
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that hotpluggable CPUs are listed correctly
|
// Checks that hotpluggable CPUs are listed correctly
|
||||||
|
Loading…
Reference in New Issue
Block a user