From 9175668e8e05514a71b280a43e0db751100c05ed Mon Sep 17 00:00:00 2001 From: "zhangchen.kidd" Date: Tue, 29 Jul 2025 15:30:29 +0800 Subject: [PATCH] runtime: qemu: introduce setup iothread function Make the original virtio-scsi iothread and the new independent iothread to a dedicated method for handing the related logics. Signed-off-by: zhangchen.kidd --- src/runtime/virtcontainers/qemu.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 7e7f747fd1..7e20128d53 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -143,6 +143,8 @@ const ( qemuStopSandboxTimeoutSecs = 15 qomPathPrefix = "/machine/peripheral/" + + indepIOThreadsPrefix = "indep_iothread" ) // agnostic list of kernel parameters @@ -513,6 +515,26 @@ func (q *qemu) setupFileBackedMem(knobs *govmmQemu.Knobs, memory *govmmQemu.Memo memory.Path = target } +func (q *qemu) setupIoThread(ioThread *govmmQemu.IOThread) []govmmQemu.IOThread { + + var tmp_threads []govmmQemu.IOThread + + // Add virtio-scsi IOThreads for QEMU + if ioThread != nil { + tmp_threads = append(tmp_threads, *ioThread) + } + + // Add Independent IOThreads for QEMU + if q.config.IndepIOThreads > 0 { + for i := uint32(0); i < q.config.IndepIOThreads; i++ { + id := fmt.Sprintf("%s_%d", indepIOThreadsPrefix, i) + tmp_threads = append(tmp_threads, govmmQemu.IOThread{ID: id}) + } + } + + return tmp_threads +} + func (q *qemu) setConfig(config *HypervisorConfig) error { q.config = *config @@ -803,9 +825,9 @@ func (q *qemu) CreateVM(ctx context.Context, id string, network Network, hypervi return err } - if ioThread != nil { - qemuConfig.IOThreads = []govmmQemu.IOThread{*ioThread} - } + // Setup iothread for devices. + qemuConfig.IOThreads = q.setupIoThread(ioThread) + // Add RNG device to hypervisor // Skip for s390x (as CPACF is used) or when Confidential Guest is enabled if machine.Type != QemuCCWVirtio && !q.config.ConfidentialGuest {