mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
qemu: Add function to hotplug CPUs
ExecuteCPUDeviceAdd hot-adds a CPU to a running VM Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
24b14059b3
commit
8c428ed722
15
qmp.go
15
qmp.go
@ -736,3 +736,18 @@ func (q *QMP) ExecutePCIVFIODeviceAdd(ctx context.Context, devID, bdf, addr, bus
|
|||||||
}
|
}
|
||||||
return q.executeCommand(ctx, "device_add", args, nil)
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// thread number within core the CPU belongs to.
|
||||||
|
func (q *QMP) ExecuteCPUDeviceAdd(ctx context.Context, driver, cpuID, socketID, coreID, threadID string) error {
|
||||||
|
args := map[string]interface{}{
|
||||||
|
"driver": driver,
|
||||||
|
"id": cpuID,
|
||||||
|
"socket-id": socketID,
|
||||||
|
"core-id": coreID,
|
||||||
|
"thread-id": threadID,
|
||||||
|
}
|
||||||
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
|
}
|
||||||
|
22
qmp_test.go
22
qmp_test.go
@ -810,3 +810,25 @@ func TestQMPPCIDeviceAdd(t *testing.T) {
|
|||||||
q.Shutdown()
|
q.Shutdown()
|
||||||
<-disconnectedCh
|
<-disconnectedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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"
|
||||||
|
cpuID := "cpu-0"
|
||||||
|
socketID := "0"
|
||||||
|
coreID := "1"
|
||||||
|
threadID := "0"
|
||||||
|
err := q.ExecuteCPUDeviceAdd(context.Background(), driver, cpuID, socketID, coreID, threadID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error %v", err)
|
||||||
|
}
|
||||||
|
q.Shutdown()
|
||||||
|
<-disconnectedCh
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user