guo-sj
guo-sj

Reputation: 73

How to create a multiqueue tap device in Linux?

I've tried with the following command to create a tap device tap0 for my virtual machine vm1:

$ tunctl -t tap0 -u root
$ brctl addif br0 tap0
$ ifconfig tap0 up

When check its channels I got the following error:

$ ethtool -l tap0
Cannot get device channel parameters
: Operation not supported

I thought maybe the method I create tap0 is incorrect but I don't know the correct way.

Any help is appreciated.

Upvotes: 0

Views: 1569

Answers (2)

Sergey K.
Sergey K.

Reputation: 41

I use the following command to setup multiqueue tun0 device.

sudo ip tuntap add dev tap0 mode tap group netdev multi_queue

Then I ran the QEMU VM with the following settings for networking.

NETWORK=" -netdev tap,ifname=${TAP:-tap0},id=n1,script=no,downscript=no,queues=4 -device virtio-net-pci,mac=AA:BB:CC:DD:CA:B1,netdev=n1,mq=on,vectors=10"

Important options are virtio-net-pci and mq=on,vectors=10. Information about the vectors parameter https://www.linux-kvm.org/page/Multiqueue

Also, in order to prevent QEMU from trying to manage tap0, I disable scripts script=no,downscript=no

My results

root@ubuntu:/shared# ethtool -l ens5
Channel parameters for ens5:
Pre-set maximums:
RX:             n/a
TX:             n/a
Other:          n/a
Combined:       4
Current hardware settings:
RX:             n/a
TX:             n/a
Other:          n/a
Combined:       2

Distribution of interrupts between two cores (I run vm with two cores)

root@ubuntu:/shared# cat /proc/interrupts |grep virtio.-input
 28:   20079840          0   PCI-MSI 81921-edge      virtio1-input.0
 30:          1   20235243   PCI-MSI 81923-edge      virtio1-input.1
 32:          0          0   PCI-MSI 81925-edge      virtio1-input.2
 34:          0          0   PCI-MSI 81927-edge      virtio1-input.3

Upvotes: 1

guo-sj
guo-sj

Reputation: 73

About the question, I still don't know how to achieve it. But I found another way to create multiqueue tap devices for VM with qemu-kvm. Here is my script:

#!/bin/bash

qemu-kvm -name vm1 -smp cpus=8 -m 8192 \
        -drive file=/opt/kvm/vm1.qcow2,if=virtio \
        -netdev tap,id=dev0,script=no,downscript=no,ifname=tap0,vhost=on,queues=8 \
        -device virtio-net-pci,netdev=dev0,mac=52:54:00:56:78:90,mq=on,vectors=18 \
        -daemonize

if [ $? -eq 0 ];then
        sleep 5
        brctl addif br1 tap0
        ifconfig tap0 up
fi

The script creates a tap device tap0 with 8 queues, adds tap0 to bridge br0, and sets tap0 up.

You can use ethtool -l [ifname] in your VM, here is my output:

$ ethtool -l eth0
Pre-set maximums:
RX:             0
TX:             0
Other:          0
Combined:       8
Current hardware settings:
RX:             0
TX:             0
Other:          0
Combined:       8         # current has 8 queues enabled

Done.

Upvotes: 1

Related Questions