New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virtio: add virtio framework in NuttX #9297
Conversation
I am very interested in this PR, but do not let my review hold this up since I likely wont have time to give it a detailed review for a few days. |
I'd like to keep my old drivers for my study. So, I propose adding a config option to select which driver to use. |
38dba38
to
b3d2a32
Compare
#9406 has been merged, rebase to last. |
@masayuki2009 here is some my thought:
|
Hmm, as long as I tried this PR |
@wengzhe will take a look. Could you share your perf number on qemu-armv8a:netnsh_smp? |
|
ee53de9
to
8e88378
Compare
@masayuki2009 Thanks, we figure out the reason and update the patch, new test results are also updated, could you take a look? |
@CV-Bowen |
@masayuki2009 Sorry, I'm not familiar with kernal mode, I see there is no iperf command after starting the rv-virt:knetnsh64 (Follow the README.txt). NuttShell (NSH) NuttX-12.1.0
nsh>
nsh>
nsh>
nsh> ?
help usage: help [-v] [<cmd>]
. break df free kill nslookup set uname
[ cat dmesg get ls printf sleep umount
? cd echo help mkdir ps source unset
alias cp env hexdump mkrd put test uptime
unalias cmp exec ifconfig mount pwd time usleep
arp dirname exit ifdown mv rm true wget
basename dd false ifup nfsmount rmdir truncate xd
nsh> |
In the CONFIG_BUILD_KERNEL mode, iperf command is built as a separate ELF file so the command can not be seen in the help.
|
a90ae82
to
73ba318
Compare
@masayuki2009 I use the wrong virtio mmio intterupt number in S-mode in nuttx/boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c, this leads some problems in |
@CV-Bowen With this PR,
With the latest master,
|
Bandwidth data from us are normally collected from my PC: Host: Ubuntu 22.04.1 x86_64 with Core i7 12700
Note:
|
c37a50e
to
1578f29
Compare
@masayuki2009 I found the root cause of The driver MUST only use 32 bit wide and aligned reads and writes to access the control registers described
in table 4.1. For the device-specific configuration space, the driver MUST use 8 bit wide accesses for 8 bit
wide fields, 16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide and aligned accesses for
32 and 64 bit wide fields. Follow Linux does, I change the virtio mmio read/write config to aligned copy and add macro virtio_read_config_member() and virtio_write_config_member() to directly read/write the config member. Could you have a look? |
@CV-Bowen |
@masayuki2009 The iperf performance is related to the compiler version. GCC 12.3wangbowen@ubuntu:/data/project/code/apache$ ~/Software/qemu/qemu-7.2.4/build/qemu-system-aarch64 -cpu cortex-a53 -nographic \
> -machine virt,virtualization=on,gic-version=3 \
> -chardev stdio,id=con,mux=on -serial chardev:con \
> -global virtio-mmio.force-legacy=false \
> -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=udp:127.0.0.1:15001-10.0.2.15:5001 \
> -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \
> -mon chardev=con,mode=readline -kernel ./arm64_netnsh_master_gcc12.3
telnetd [4:100]
NuttShell (NSH) NuttX-12.2.1
nsh>
nsh>
nsh> iperf -s -i 1
IP: 10.0.2.15
mode=tcp-server sip=10.0.2.15:5001,dip=0.0.0.0:5001, interval=1, time=0
accept: 10.0.2.2:58472
Interval Transfer Bandwidth
0.00- 1.01 sec 43075840 Bytes 341.19 Mbits/sec
1.01- 2.02 sec 43239360 Bytes 342.49 Mbits/sec
2.02- 3.03 sec 43391200 Bytes 343.69 Mbits/sec
3.03- 4.04 sec 43297760 Bytes 342.95 Mbits/sec
4.04- 5.05 sec 43309440 Bytes 343.05 Mbits/sec
closed by the peer: 10.0.2.2:58472
iperf exit
nsh> QEMU: Terminated This PR wangbowen@ubuntu:/data/project/code/apache$ ~/Software/qemu/qemu-7.2.4/build/qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -chardev stdio,id=con,mux=on -serial chardev:con -global virtio-mmio.force-legacy=false -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=udp:127.0.0.1:15001-10.0.2.15:5001 -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 -mon chardev=con,mode=readline -kernel ./arm64_netnsh_gcc12.3
telnetd [4:100]
NuttShell (NSH) NuttX-12.2.1
nsh> iperf -s -i 1
IP: 10.0.2.15
mode=tcp-server sip=10.0.2.15:5001,dip=0.0.0.0:5001, interval=1, time=0
accept: 10.0.2.2:59352
Interval Transfer Bandwidth
0.00- 1.01 sec 53257880 Bytes 421.84 Mbits/sec
1.01- 2.02 sec 53728000 Bytes 425.57 Mbits/sec
2.02- 3.03 sec 53996640 Bytes 427.70 Mbits/sec
3.03- 4.04 sec 53929480 Bytes 427.16 Mbits/sec
4.04- 5.05 sec 52216900 Bytes 413.60 Mbits/sec
closed by the peer: 10.0.2.2:59352
iperf exit
nsh> QEMU: Terminated
wangbowen@ubuntu:/data/project/code/apache$ aarch64-none-elf-gcc --version
aarch64-none-elf-gcc (Arm GNU Toolchain 12.3.Rel1 (Build arm-12.35)) 12.3.1 20230626
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
wangbowen@ubuntu:/data/project/code/apache$ GCC 12.2wangbowen@ubuntu:/data/project/code/apache$ ~/Software/qemu/qemu-7.2.4/build/qemu-system-aarch64 -cpu cortex-a53 -nographic \
> -machine virt,virtualization=on,gic-version=3 \
> -chardev stdio,id=con,mux=on -serial chardev:con \
> -global virtio-mmio.force-legacy=false \
> -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=udp:127.0.0.1:15001-10.0.2.15:5001 \
> -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \
> -mon chardev=con,mode=readline -kernel ./arm64_netnsh_master_gcc12.2
telnetd [4:100]
NuttShell (NSH) NuttX-12.2.1
nsh>
nsh> iperf -s -i 1
IP: 10.0.2.15
mode=tcp-server sip=10.0.2.15:5001,dip=0.0.0.0:5001, interval=1, time=0
accept: 10.0.2.2:43158
Interval Transfer Bandwidth
0.00- 1.01 sec 40880000 Bytes 323.80 Mbits/sec
1.01- 2.02 sec 40693120 Bytes 322.32 Mbits/sec
2.02- 3.03 sec 40517920 Bytes 320.93 Mbits/sec
3.03- 4.04 sec 40482880 Bytes 320.66 Mbits/sec
4.04- 5.05 sec 41136960 Bytes 325.84 Mbits/sec
closed by the peer: 10.0.2.2:43158
iperf exit
nsh> QEMU: Terminated This PR wangbowen@ubuntu:/data/project/code/apache$ ~/Software/qemu/qemu-7.2.4/build/qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -chardev stdio,id=con,mux=on -serial chardev:con -global virtio-mmio.force-legacy=false -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=udp:127.0.0.1:15001-10.0.2.15:5001 -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 -mon chardev=con,mode=readline -kernel ./arm64_netnsh_gcc12.2
telnetd [4:100]
NuttShell (NSH) NuttX-12.2.1
nsh> iperf -s -i 1
IP: 10.0.2.15
mode=tcp-server sip=10.0.2.15:5001,dip=0.0.0.0:5001, interval=1, time=0
accept: 10.0.2.2:55610
Interval Transfer Bandwidth
0.00- 1.01 sec 52955660 Bytes 419.45 Mbits/sec
1.01- 2.02 sec 52149740 Bytes 413.07 Mbits/sec
2.02- 3.03 sec 51813940 Bytes 410.41 Mbits/sec
3.03- 4.04 sec 51881100 Bytes 410.94 Mbits/sec
4.04- 5.05 sec 52049000 Bytes 412.27 Mbits/sec
closed by the peer: 10.0.2.2:55610
iperf exit
nsh> QEMU: Terminated
wangbowen@ubuntu:/data/project/code/apache$ aarch64-none-elf-
aarch64-none-elf-addr2line aarch64-none-elf-gcc aarch64-none-elf-gcov-tool aarch64-none-elf-nm
aarch64-none-elf-ar aarch64-none-elf-gcc-11.2.1 aarch64-none-elf-gdb aarch64-none-elf-objcopy
aarch64-none-elf-as aarch64-none-elf-gcc-12.2.1 aarch64-none-elf-gdb-add-index aarch64-none-elf-objdump
aarch64-none-elf-c++ aarch64-none-elf-gcc-ar aarch64-none-elf-gfortran aarch64-none-elf-ranlib
aarch64-none-elf-c++filt aarch64-none-elf-gcc-nm aarch64-none-elf-gprof aarch64-none-elf-readelf
aarch64-none-elf-cpp aarch64-none-elf-gcc-ranlib aarch64-none-elf-ld aarch64-none-elf-size
aarch64-none-elf-elfedit aarch64-none-elf-gcov aarch64-none-elf-ld.bfd aarch64-none-elf-strings
aarch64-none-elf-g++ aarch64-none-elf-gcov-dump aarch64-none-elf-lto-dump aarch64-none-elf-strip
wangbowen@ubuntu:/data/project/code/apache$ aarch64-none-elf-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-none-elf-gcc
COLLECT_LTO_WRAPPER=/home/wangbowen/Software/aarch64-gcc/bin/../libexec/gcc/aarch64-none-elf/12.2.1/lto-wrapper
Target: aarch64-none-elf
Configured with: /data/jenkins/workspace/GNU-toolchain/arm-12/src/gcc/configure --target=aarch64-none-elf --prefix=/data/jenkins/workspace/GNU-toolchain/arm-12/build-aarch64-none-elf/install --with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-12/build-aarch64-none-elf/host-tools --with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-12/build-aarch64-none-elf/host-tools --with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-12/build-aarch64-none-elf/host-tools --with-isl=/data/jenkins/workspace/GNU-toolchain/arm-12/build-aarch64-none-elf/host-tools --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=release --enable-languages=c,c++,fortran --with-newlib --with-gnu-as --with-gnu-ld --with-sysroot=/data/jenkins/workspace/GNU-toolchain/arm-12/build-aarch64-none-elf/install/aarch64-none-elf --with-pkgversion='Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)' --with-bugurl=https://bugs.linaro.org/
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 12.2.1 20221205 (Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24))
wangbowen@ubuntu:/data/project/code/apache$ GCC 11.2wangbowen@ubuntu:/data/project/code/apache$ ~/Software/qemu/qemu-7.2.4/build/qemu-system-aarch64 -cpu cortex-a53 -nographic \
> -machine virt,virtualization=on,gic-version=3 \
> -chardev stdio,id=con,mux=on -serial chardev:con \
> -global virtio-mmio.force-legacy=false \
> -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=udp:127.0.0.1:15001-10.0.2.15:5001 \
> -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \
> -mon chardev=con,mode=readline -kernel ./arm64_netnsh_master_gcc11.2
telnetd [4:100]
NuttShell (NSH) NuttX-12.2.1
nsh>
nsh> iperf -s -i 1
IP: 10.0.2.15
mode=tcp-server sip=10.0.2.15:5001,dip=0.0.0.0:5001, interval=1, time=0
accept: 10.0.2.2:60002
Interval Transfer Bandwidth
0.00- 1.01 sec 37013920 Bytes 293.18 Mbits/sec
1.01- 2.02 sec 38380480 Bytes 304.00 Mbits/sec
2.02- 3.03 sec 38508960 Bytes 305.02 Mbits/sec
3.03- 4.04 sec 38216960 Bytes 302.71 Mbits/sec
4.04- 5.05 sec 38614080 Bytes 305.85 Mbits/sec
closed by the peer: 10.0.2.2:60002
iperf exit
nsh> QEMU: Terminated This PR wangbowen@ubuntu:/data/project/code/apache$ ~/Software/qemu/qemu-7.2.4/build/qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -chardev stdio,id=con,mux=on -serial chardev:con -global virtio-mmio.force-legacy=false -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=udp:127.0.0.1:15001-10.0.2.15:5001 -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 -mon chardev=con,mode=readline -kernel ./arm64_netnsh_gcc11.2
telnetd [4:100]
NuttShell (NSH) NuttX-12.2.1
nsh> iperf -s -i 1
IP: 10.0.2.15
mode=tcp-server sip=10.0.2.15:5001,dip=0.0.0.0:5001, interval=1, time=0
accept: 10.0.2.2:55980
Interval Transfer Bandwidth
0.00- 1.01 sec 46676200 Bytes 369.71 Mbits/sec
1.01- 2.02 sec 46709780 Bytes 369.98 Mbits/sec
2.02- 3.03 sec 46609040 Bytes 369.18 Mbits/sec
3.03- 4.04 sec 46508300 Bytes 368.38 Mbits/sec
4.04- 5.05 sec 47179900 Bytes 373.70 Mbits/sec
closed by the peer: 10.0.2.2:55980
iperf exit
nsh> QEMU: Terminated
wangbowen@ubuntu:/data/project/code/apache$ aarch64-none-elf-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-none-elf-gcc
COLLECT_LTO_WRAPPER=/data/software/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf/bin/../libexec/gcc/aarch64-none-elf/11.2.1/lto-wrapper
Target: aarch64-none-elf
Configured with: /data/jenkins/workspace/GNU-toolchain/arm-11/src/gcc/configure --target=aarch64-none-elf --prefix=/data/jenkins/workspace/GNU-toolchain/arm-11/build-aarch64-none-elf/install// --with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-11/build-aarch64-none-elf/host-tools --with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-11/build-aarch64-none-elf/host-tools --with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-11/build-aarch64-none-elf/host-tools --with-isl=/data/jenkins/workspace/GNU-toolchain/arm-11/build-aarch64-none-elf/host-tools --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=release --enable-languages=c,c++,fortran --with-newlib --with-pkgversion='GNU Toolchain for the Arm Architecture 11.2-2022.02 (arm-11.14)' --with-bugurl=https://bugs.linaro.org/
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20220111 (GNU Toolchain for the Arm Architecture 11.2-2022.02 (arm-11.14))
wangbowen@ubuntu:/data/project/code/apache$ |
@masayuki2009 do you have more comment? |
@xiaoxiang781216 |
@CV-Bowen To compare your changes easily on the github whenever you modify your code and rebase this PR,
|
@masayuki2009 OK, but actually, I only modified the virtio mmio config read/write code, and not did changes to virtio-net or somethins else to improve the iperf performance. |
@masayuki2009 I will update the iperf test data based on gcc 12.2 and qemu 7.2.4 with this PR, but the performance degradation in some configs may be fixed later. |
1. virtio devics/drivers match and probe/remote mechanism; 2. virtio mmio transport layer based on OpenAmp (Compatible with both virtio mmio version 1 and 2); 3. virtio-serial driver based on new virtio framework; 4. virtio-rng driver based on new virtio framework; 5. virtio-net driver based on new virtio framework (IOB Offload implementation); 6. virtio-blk driver based on new virtio framework; 7. Remove the old virtio mmio framework, the old framework only support mmio transport layer, and the new framwork support more transport layer and this commit has implemented all the old virtio drivers; 8. Refresh the the qemu-arm64 and qemu-riscv virtio related configs, and update its README.txt; New virtio-net driver has better performance Compared with previous virtio-mmio-net: | | master/-c | master/-s | this/-c | this/-s | | :--------------------: | :-------: | :-------: | :-----: | :-----: | | qemu-armv8a:netnsh | 539Mbps | 524Mbps | 906Mbps | 715Mbps | | qemu-armv8a:netnsh_smp | 401Mbps | 437Mbps | 583Mbps | 505Mbps | | rv-virt:netnsh | 487Mbps | 512Mbps | 760Mbps | 634Mbps | | rv-virt:netnsh_smp | 387Mbps | 455Mbps | 447Mbps | 502Mbps | | rv-virt:netnsh64 | 602Mbps | 595Mbps | 881Mbps | 769Mbps | | rv-virt:netnsh64_smp | 414Mbps | 515Mbps | 491Mbps | 525Mbps | | rv-virt:knetnsh64 | 515Mbps | 457Mbps | 606Mbps | 540Mbps | | rv-virt:knetnsh64_smp | 308Mbps | 389Mbps | 415Mbps | 474Mbps | Note: Both CONFIG_IOB_NBUFFERS=64, using iperf command, all in Mbits/sec Tested in QEMU 7.2.2 Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com> Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Only rebase to the master. |
@masayuki2009 how about your opinion? Most config run fast than before, only RISCV SMP in kernel mode is a little bit slow. Since QEMU is an emulation, the slow may due to the inefficient RISCV implementation, not reflect the performance on real device. |
@CV-Bowen |
@masayuki2009 OK, I will try QEMU-8.1.2 later today. |
@masayuki2009 I tried the config |
@CV-Bowen |
@masayuki2009 I'm not sure, but I decide to change the metal_read/write operation to nuttx implemented instead openamp libmetal implemented. Nuttx implemented operation not use the atomic operation, and can fix this issue. |
Summary
This PR add the basic virtio framework for NuttX. Implement the virtio-mmio transport layer and four basic virtio-drivers.
And the new virtio-mmio transport layer support both leagcy and new version.
Compared with previous virtio-mmio-net:
Note: Both CONFIG_IOB_NBUFFERS=64, using iperf command, all in Mbits/sec
Tested in QEMU 7.2.2
Impact
The qemu-arm64 and qemu-rv board
Testing
Local test with qmeu-arm64, qemu-rv board