Skip to contentSkip to conversation

kvm-unittests: add pci PORT IO and MMIO speed tests

PATCH Applied Michael S. Tsirkin 2 participants 8 messages Apr 3, 2013 – May 12, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 3bb9e3d..867eb19 100644
@@ -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
#2 lore raw

PATCH 2/5 kvm-unittest: libcflat: add offsetof

In reply to Michael S. Tsirkin

implement offsetof using gcc builtin.

---
 lib/libcflat.h | 2 ++
 1 file changed, 2 insertions(+)
lib/libcflat.h +2 -0
index 0c62e4c..e005d3a 100644
@@ -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
#4 lore raw

PATCH 4/5 lib: add pci bus scan support

In reply to Michael S. Tsirkin

Add 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
index 1f0f1ba..455032b 100644
@@ -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
new file mode 100644
index 0000000..0f69ef0
@@ -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
#5 lore raw

PATCH 5/5 vmexit: add pci io and memory speed tests

In reply to Michael S. Tsirkin

These 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
index e395a70..f87b8c7 100755
@@ -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
#6 lore raw
In reply to Michael S. Tsirkin
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.h
Signature · 1 line
MST

--
Gleb.

Applied
#7 lore raw
In reply to Michael S. Tsirkin
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?

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.h
Signature · 1 line
MST

--
Gleb.