kvm-unittests: add pci PORT IO and MMIO speed tests
Subsystems (2)
cover kvm-unittests: add pci PORT IO and MMIO speed tests
These patches add ability to measure speed of MMIO versus PIO, in different configurations. As I didn't want to reserve a hardcoded range of memory, I added pci bus scan support instead. Used together with the new pci-testdev backend. When not present, the new tests are skipped.
Example output:
mmio-no-eventfd:pci-mem 8796 mmio-wildcard-eventfd:pci-mem 3609 mmio-datamatch-eventfd:pci-mem 3685 portio-no-eventfd:pci-io 5287 portio-wildcard-eventfd:pci-io 1762 portio-datamatch-eventfd:pci-io 1777
First interesting conclusion is that the overhead of MMIO exit to QEMU as compared to PIO is double that of
MMIO ioeventfd as compared to PIO eventfd. Is this a known fact?
Michael S. Tsirkin (5):
kvm-unittest: add printf %c support
kvm-unittest: libcflat: add offsetof
libcflat.h: define NULL
lib: add pci bus scan support
vmexit: add pci io and memory speed tests
config-x86-common.mak | 1 + lib/libcflat.h | 3 + lib/printf.c | 3 + lib/x86/pci.c | 55 ++++++++++++ lib/x86/pci.h | 16 ++++ x86-run | 13 ++- x86/vmexit.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 302 insertions(+), 15 deletions(-) create mode 100644 lib/x86/pci.c create mode 100644 lib/x86/pci.h
Signature · 1 line
MST
PATCH 1/5 kvm-unittest: add printf %c support
Handy for printing debug strings from hardware.
--- lib/printf.c | 3 +++ 1 file changed, 3 insertions(+)
lib/printf.c +3 -0
@@ -104,6 +104,9 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)case '%' :addchar (&s,'%' );break ; +case 'c' : +addchar (&s,va_arg (va, int)); +break ;case '\0' : --fmt;break ;
Signature · 1 line
MST
PATCH 2/5 kvm-unittest: libcflat: add offsetof
In reply to Michael S. Tsirkinimplement offsetof using gcc builtin.
--- lib/libcflat.h | 2 ++ 1 file changed, 2 insertions(+)
lib/libcflat.h +2 -0
@@ -54,4 +54,6 @@ extern void *memset(void *s, int c, size_t n);extern long atol (const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0])) +#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#endif
Signature · 1 line
MST
PATCH 3/5 libcflat.h: define NULL
In reply to Michael S. Tsirkin--- lib/libcflat.h | 1 + 1 file changed, 1 insertion(+)
lib/libcflat.h +1 -0
@@ -56,4 +56,5 @@ extern long atol(const char *ptr);#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#define NULL ((void *)0UL)#endif
Signature · 1 line
MST
PATCH 4/5 lib: add pci bus scan support
In reply to Michael S. TsirkinAdd API to scan bus for a given device, as well as API to access BAR registers.
--- config-x86-common.mak | 1 + lib/x86/pci.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/x86/pci.h | 16 +++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 lib/x86/pci.c create mode 100644 lib/x86/pci.h
config-x86-common.mak +1 -0
@@ -14,6 +14,7 @@ cflatobjs += lib/x86/apic.o cflatobjs += lib/x86/atomic.o cflatobjs += lib/x86/desc.o cflatobjs += lib/x86/isr.o +cflatobjs += lib/x86/pci.o $(libcflat): LDFLAGS += -nostdlib $(libcflat): CFLAGS += -ffreestanding -I lib
lib/x86/pci.c new file +55 -0
55 lines not on this page · raw message
lib/x86/pci.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef PCI_H +#define PCI_H + +#include <inttypes.h> +#include "libcflat.h" + +typedef uint16_t pcidevaddr_t ; +enum { +PCIDEVADDR_INVALID =0x0 +}; +pcidevaddr_t pci_find_dev (uint16_t vendor_id,uint16_t device_id); +unsigned long pci_bar_addr (pcidevaddr_t dev,int bar_num); +bool pci_bar_is_memory (pcidevaddr_t dev,int bar_num); +bool pci_bar_is_valid (pcidevaddr_t dev,int bar_num); + +#endif
Signature · 1 line
MST
PATCH 5/5 vmexit: add pci io and memory speed tests
In reply to Michael S. TsirkinThese tests measure speed of mmio and port io
exits using the new pci-testdev.
Skipped when running on old qemu.
--- x86-run | 13 +++- x86/vmexit.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 224 insertions(+), 15 deletions(-)
x86-run +11 -2
@@ -17,11 +17,20 @@ else fi fi +if ${qemu} -device '?' 2>&1 | fgrep pci-testdev > /dev/null; +then + pci_testdev="-device pci-testdev" +else + pci_testdev="" +fi + if ${qemu} -device '?' 2>&1 | fgrep "pc-testdev" > /dev/null; then - command="${qemu} -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel" + pc_testdev="-device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4" else - command="${qemu} -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel" + pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out" fi + +command="${qemu} -enable-kvm $pc_testdev -serial stdio $pci_testdev -kernel" exec ${command} "$@"
x86/vmexit.c +213 -13
282 lines not on this page · raw message
Signature · 1 line
MST
Quoted 13 lines · Michael S. Tsirkin
These patches add ability to measure speed of MMIO versus PIO, in different configurations. As I didn't want to reserve a hardcoded range of memory, I added pci bus scan support instead. Used together with the new pci-testdev backend. When not present, the new tests are skipped.
Example output:
mmio-no-eventfd:pci-mem 8796 mmio-wildcard-eventfd:pci-mem 3609 mmio-datamatch-eventfd:pci-mem 3685 portio-no-eventfd:pci-io 5287 portio-wildcard-eventfd:pci-io 1762 portio-datamatch-eventfd:pci-io 1777
Quoted 4 lines
First interesting conclusion is that the overhead of MMIO exit to QEMU as compared to PIO is double that of
MMIO ioeventfd as compared to PIO eventfd. Is this a known fact?
Looks fine to me. Will apply when QEMU part will land in upstream.
Quoted 7 lines
Michael S. Tsirkin (5):
kvm-unittest: add printf %c support
kvm-unittest: libcflat: add offsetof
libcflat.h: define NULL
lib: add pci bus scan support
vmexit: add pci io and memory speed tests
Quoted 13 lines
config-x86-common.mak | 1 + lib/libcflat.h | 3 + lib/printf.c | 3 + lib/x86/pci.c | 55 ++++++++++++ lib/x86/pci.h | 16 ++++ x86-run | 13 ++- x86/vmexit.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 302 insertions(+), 15 deletions(-) create mode 100644 lib/x86/pci.c create mode 100644 lib/x86/pci.hSignature · 1 line
MST
--
Gleb.
Gleb Natapov
AppliedQuoted 13 lines · Michael S. Tsirkin
These patches add ability to measure speed of MMIO versus PIO, in different configurations. As I didn't want to reserve a hardcoded range of memory, I added pci bus scan support instead. Used together with the new pci-testdev backend. When not present, the new tests are skipped.
Example output:
mmio-no-eventfd:pci-mem 8796 mmio-wildcard-eventfd:pci-mem 3609 mmio-datamatch-eventfd:pci-mem 3685 portio-no-eventfd:pci-io 5287 portio-wildcard-eventfd:pci-io 1762 portio-datamatch-eventfd:pci-io 1777
Quoted 4 lines
First interesting conclusion is that the overhead of MMIO exit to QEMU as compared to PIO is double that of
MMIO ioeventfd as compared to PIO eventfd. Is this a known fact?
Applied, thanks.
Quoted 7 lines
Michael S. Tsirkin (5):
kvm-unittest: add printf %c support
kvm-unittest: libcflat: add offsetof
libcflat.h: define NULL
lib: add pci bus scan support
vmexit: add pci io and memory speed tests
Quoted 13 lines
config-x86-common.mak | 1 + lib/libcflat.h | 3 + lib/printf.c | 3 + lib/x86/pci.c | 55 ++++++++++++ lib/x86/pci.h | 16 ++++ x86-run | 13 ++- x86/vmexit.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 302 insertions(+), 15 deletions(-) create mode 100644 lib/x86/pci.c create mode 100644 lib/x86/pci.hSignature · 1 line
MST
--
Gleb.