multiboot: Use DMA instead port-based transfer
PATCH 1/1 multiboot: Use DMA instead port-based transfer
Use DMA transfers in the multiboot loader to copy data.
This significantly lowers QEMU's startup latency by a factor of about 40, for example, going from 30sec to 0.8sec when loading modules of 120MB in size. This change has been used successfully for some time.
--- pc-bios/multiboot.bin | Bin 1024 -> 1536 bytes pc-bios/optionrom/multiboot.S | 10 ++--- pc-bios/optionrom/optionrom.h | 77 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-)
pc-bios/multiboot.bin binary +0 -0
pc-bios/optionrom/multiboot.S +5 -5
@@ -68,10 +68,10 @@ run_multiboot: mov %eax, %es /* Read the bootinfo struct into RAM */ - read_fw_blob(FW_CFG_INITRD) + read_fw_blob_dma(FW_CFG_INITRD) /* FS = bootinfo_struct */ - read_fw FW_CFG_INITRD_ADDR + read_fw_dma_var32 FW_CFG_INITRD_ADDR shr $4, %eax mov %ax, %fs
@@ -188,14 +188,14 @@ prot_mode: movl %eax, %gs /* Read the kernel and modules into RAM */ - read_fw_blob(FW_CFG_KERNEL) + read_fw_blob_dma(FW_CFG_KERNEL) /* Jump off to the kernel */ - read_fw FW_CFG_KERNEL_ENTRY + read_fw_dma_var32 FW_CFG_KERNEL_ENTRY mov %eax, %ecx /* EBX contains a pointer to the bootinfo struct */ - read_fw FW_CFG_INITRD_ADDR + read_fw_dma_var32 FW_CFG_INITRD_ADDR movl %eax, %ebx /* EAX has to contain the magic */
pc-bios/optionrom/optionrom.h +77 -0
89 lines not on this page · raw message
Signature · 1 line
2.33.0
CCing Paolo since kvm-unit-tests use multiboot.
Quoted 8 lines · Adam Lackorzynski
Use DMA transfers in the multiboot loader to copy
data.This significantly lowers QEMU's startup latency by a factor of about 40, for example, going from 30sec to 0.8sec when loading modules of 120MB in size. This change has been used successfully for some time.
Quoted 7 lines
Signed-off-by Marcus Hähnel <[email protected]>Signed-off-by Adam Lackorzynski <[email protected]>---
pc-bios/multiboot.bin | Bin 1024 -> 1536 bytes pc-bios/optionrom/multiboot.S | 10 ++--- pc-bios/optionrom/optionrom.h | 77 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-)
I tested with https://gitlab.com/kvm-unit-tests/kvm-unit-tests running:
export QEMU=/path/to/qemu-system-x86_64 -L path/to/pc-bios/optionrom time ./run_test.sh
Before this patch:
real 3m5.578s
user 2m32.231s
sys 0m50.390s
After this patch:
real 2m55.614s
user 2m20.536s
sys 0m50.046s
It's still a good improvement, considering the fact that the images aren't big.
Just a consideration, for blobs (kernel and initrd) I fully agree to use DMA, but for 32bit variables is it useful?
However, this patch LGTM:
Paolo Bonzini
maintainerQuoted 8 lines · Adam Lackorzynski
Use DMA transfers in the multiboot loader to copy data.
This significantly lowers QEMU's startup latency by a factor of about 40, for example, going from 30sec to 0.8sec when loading modules of 120MB in size. This change has been used successfully for some time.
Quoted 7 lines
Signed-off-by Marcus Hähnel<[email protected]>Signed-off-by Adam Lackorzynski<[email protected]>--- pc-bios/multiboot.bin | Bin 1024 -> 1536 bytes pc-bios/optionrom/multiboot.S | 10 ++--- pc-bios/optionrom/optionrom.h | 77 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-)
This would break migration to QEMU 2.4 and earlier - which is in fact why linuxboot has a completely different option ROM when DMA is in use.
On my system (a relatively recent laptop) I get 15-20 MiB per second, which is slow but not as slow as what you got. Out of curiosity, can you test what you get with the following kernel patch?
arch/x86/kvm/kvm_emulate.h +1 -1
@@ -272,7 +272,7 @@ struct fetch_cache { };struct read_cache { -u8 data[1024 ]; +u8 data[4096 ];unsigned long pos;unsigned long end; };
Paolo
Quoted 9 lines · CEST Paolo Bonzini
On my system (a relatively recent laptop) I get 15-20 MiB per second, which is slow but not as slow as what you got. Out of curiosity, can you test what you get with the following kernel patch?
arch/x86/kvm/kvm_emulate.h +0
-0
arch/x86/kvm/kvm_emulate.h struct fetch_cache { · line 278
Quoted 8 lines
arch/x86/kvm/kvm_emulate.h +1
-1@@ -272,7 +272,7 @@ struct fetch_cache { };struct read_cache { -u8 data[1024 ]; +u8 data[4096 ];unsigned long pos;unsigned long end; };
Hi Paolo,
Thank you very much for the cleaned up and improved patch in the other thread, which solves our issue perfectly! Your work is much appreciated.
Regarding your question above I made some quick benchmark runs. Using a 195kB kernel image and measuring from QEmu start until the first complete line is sent over the serial output I get the following timings, all numbers in seconds:
kvm? | DMA Multiboot | Old Multiboot | -------|---------------|---------------| no-kvm | 0.209 ± 0.01 | 15.283 ± 0.19 | kvm | 0.207 ± 0.01 | 20.771 ± 0.26 | kvm-4k | 0.208 ± 0.01 | 19.878 ± 0.22 |
The tests were run 10 times using perf stat -r10. The table shows the averages and standard deviation. While perf does have some overhead the general issue is independent of that.
Changing the read cache to 4k has a negligible impact compared to running without kvm. The numbers for DMA are roughly two orders of magnitude better in all cases.
Hardware: Lenovo T480, Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Software: Gentoo, Custom Linux 5.14.9 kernel
QEmu master with your DMA multiboot patches applied, v6.1.0-1564-g1a510366d8-dirty configured without any options, only the x86_64 softmmu as target
Commandline: qemu-system-x86_64 -enable-kvm -kernel /path/to/kernel -serial stdio -nographic -monitor none -m 512
General ballpark of results was confirmed on a different T480 with another OS and QEmu version and on a server system. As you can see we get not MiB/s when booting through multiboot without DMA but KiB/s.
- Marcus