Skip to content

Commit

Permalink
Enable multiqueues on virtio-net interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Milan Lenco <[email protected]>
  • Loading branch information
milan-zededa committed Oct 31, 2024
1 parent d1b23a6 commit 1a7334b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ const qemuNetTemplate = `
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
{{- if and (eq .Driver "virtio-net-pci") (gt .Queues 1) }}
queues = "{{.Queues}}"
{{- end}}
[device "net{{.NetID}}"]
driver = "{{.Driver}}"
Expand All @@ -375,6 +378,10 @@ const qemuNetTemplate = `
{{- if and (eq .Driver "virtio-net-pci") (ne .MTU 0) }}
host_mtu = "{{.MTU}}"
{{- end}}
{{- if and (eq .Driver "virtio-net-pci") (gt .Queues 1) }}
mq = "on"
vectors = "{{.Vectors}}"
{{- end}}
`

const qemuPciPassthruTemplate = `
Expand Down Expand Up @@ -990,6 +997,7 @@ func (ctx KvmContext) CreateDomConfig(domainName string,
Driver string
Mac, Bridge, Vif string
MTU uint16
Queues, Vectors int
}{PCIId: diskContext.PCIId, NetID: 0}
t, _ = template.New("qemuNet").Parse(qemuNetTemplate)
for _, net := range config.VifList {
Expand All @@ -1002,6 +1010,14 @@ func (ctx KvmContext) CreateDomConfig(domainName string,
netContext.Driver = "virtio-net-pci"
}
netContext.MTU = net.MTU
// Configure one RX and one TX queue for every vCPU.
netContext.Queues = config.VCpus
// Formula for the number of MSI-X vectors:
// - one vector for every RX queue
// - one vector for every TX queue
// - one for configuration purposes
// - one for possible VQ (vector quantization) control
netContext.Vectors = 2*netContext.Queues + 2
if err := t.Execute(file, netContext); err != nil {
return logError("can't write to config file %s (%v)", file.Name(), err)
}
Expand Down

0 comments on commit 1a7334b

Please sign in to comment.