* [PATCH] target-i386 : reduce rtc 0x70 access vm-exit time
@ 2017-08-02 15:27 Peng Hao
0 siblings, 0 replies; 2+ messages in thread
From: Peng Hao @ 2017-08-02 15:27 UTC (permalink / raw)
To: pbonzini; +Cc: kvm, qemu-devel, Peng Hao
some versions of windows guest access rtc frequently because of
rtc as system tick.guest access rtc like this: write register index
to 0x70, then write or read data from 0x71. writing 0x70 port is
just as index and do nothing else. So writing 0x70 is not necessory
to exit to userspace every time and caching rtc register index in kvm
can reduce VM-EXIT time.
without my patch, get the vm-exit time of accessing rtc 0x70 using
perf tools: (guest OS : windows 7 64bit)
IO Port Access Samples Samples% Time% Min Time Max Time Avg time
0x70:POUT 86 30.99% 74.59% 9us 29us 10.75us ( +- 3.41% )
with my patch
IO Port Access Samples Samples% Time% Min Time Max Time Avg time
0x70:POUT 106 32.02% 29.47% 0us 10us 1.57us ( +- 7.38% )
the patch is a part of optimizing rtc 0x70 port access.another is in
kernel.
Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
Reviewed-by: Liu Yi <liu.yi24@zte.com.cn>
---
accel/kvm/kvm-all.c | 17 +++++++++++++++++
| 3 ++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 46ce479..683274d 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1483,6 +1483,21 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi)
g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi));
}
+static void kvm_vrtc_create(KVMState *s)
+{
+ int ret;
+ if (kvm_check_extension(s, KVM_CAP_VRTC)) {
+ return;
+ }
+
+ ret = kvm_vm_ioctl(s, KVM_CREATE_VRTC);
+
+ if (ret < 0) {
+ fprintf(stderr, "Create kernel vrtc failed: %s\n", strerror(-ret));
+ exit(1);
+ }
+}
+
static void kvm_irqchip_create(MachineState *machine, KVMState *s)
{
int ret;
@@ -1750,6 +1765,8 @@ static int kvm_init(MachineState *ms)
if (machine_kernel_irqchip_allowed(ms)) {
kvm_irqchip_create(ms, s);
}
+
+ kvm_vrtc_create(s);
if (kvm_eventfds_allowed) {
s->memory_listener.listener.eventfd_add = kvm_mem_ioeventfd_add;
--git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 7971a4f..784179a 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -929,6 +929,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_PPC_SMT_POSSIBLE 147
#define KVM_CAP_HYPERV_SYNIC2 148
#define KVM_CAP_HYPERV_VP_INDEX 149
+#define KVM_CAP_VRTC 150
#ifdef KVM_CAP_IRQ_ROUTING
@@ -1258,7 +1259,7 @@ struct kvm_s390_ucas_mapping {
#define KVM_PPC_CONFIGURE_V3_MMU _IOW(KVMIO, 0xaf, struct kvm_ppc_mmuv3_cfg)
/* Available with KVM_CAP_PPC_RADIX_MMU */
#define KVM_PPC_GET_RMMU_INFO _IOW(KVMIO, 0xb0, struct kvm_ppc_rmmu_info)
-
+#define KVM_CREATE_VRTC _IO(KVMIO, 0xba)
/* ioctl for vm fd */
#define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] target-i386: reduce rtc 0x70 access vm-exit time
@ 2017-08-12 12:05 Peng Hao
0 siblings, 0 replies; 2+ messages in thread
From: Peng Hao @ 2017-08-12 12:05 UTC (permalink / raw)
To: pbonzini, mst; +Cc: kvm, qemu-devel, Peng Hao
some versions of windows guest access rtc frequently because of
rtc as system tick.guest access rtc like this: write register index
to 0x70, then write or read data from 0x71. writing 0x70 port is
just as index and do nothing else. So we can use coalesced mmio to
handle this scene to reduce VM-EXIT time.
without my patch, get the vm-exit time of accessing rtc 0x70 using
perf tools: (guest OS : windows 7 64bit)
IO Port Access Samples Samples% Time% Min Time Max Time Avg time
0x70:POUT 86 30.99% 74.59% 9us 29us 10.75us (+- 3.41%)
with my patch
IO Port Access Samples Samples% Time% Min Time Max Time Avg time
0x70:POUT 106 32.02% 29.47% 0us 10us 1.57us (+- 7.38%)
the patch is a part of optimizing rtc 0x70 port access. Another is in
kernel.
Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
accel/kvm/kvm-all.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
hw/timer/mc146818rtc.c | 6 ++++++
include/exec/memattrs.h | 1 +
3 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 46ce479..7aa9fca 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -953,6 +953,44 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener,
}
}
+static void kvm_coalesce_io_add(MemoryListener *listener, MemoryRegionSection *section,
+ hwaddr start, hwaddr size)
+{
+ KVMState *s = kvm_state;
+
+ if (s->coalesced_mmio) {
+ struct kvm_coalesced_mmio_zone zone;
+
+ zone.addr = start;
+ zone.size = size;
+ zone.pad = 1;
+ (void)kvm_vm_ioctl(s, KVM_REGISTER_COALESCED_MMIO, &zone);
+ }
+}
+
+static void kvm_coalesce_io_del(MemoryListener *listener, MemoryRegionSection *section,
+ hwaddr start, hwaddr size)
+{
+ KVMState *s = kvm_state;
+
+ if (s->coalesced_mmio) {
+ struct kvm_coalesced_mmio_zone zone;
+
+ zone.addr = start;
+ zone.size = size;
+ zone.pad = 1;
+
+ (void)kvm_vm_ioctl(s, KVM_UNREGISTER_COALESCED_MMIO, &zone);
+ }
+
+}
+
+static MemoryListener kvm_coalesced_io_listener = {
+ .coalesced_mmio_add = kvm_coalesce_io_add,
+ .coalesced_mmio_del = kvm_coalesce_io_del,
+ .priority = 10,
+};
+
void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml,
AddressSpace *as, int as_id)
{
@@ -1762,6 +1800,8 @@ static int kvm_init(MachineState *ms)
&address_space_memory, 0);
memory_listener_register(&kvm_io_listener,
&address_space_io);
+ memory_listener_register(&kvm_coalesced_io_listener,
+ &address_space_io);
s->many_ioeventfds = kvm_check_many_ioeventfds();
@@ -1841,8 +1881,12 @@ void kvm_flush_coalesced_mmio_buffer(void)
struct kvm_coalesced_mmio *ent;
ent = &ring->coalesced_mmio[ring->first];
-
- cpu_physical_memory_write(ent->phys_addr, ent->data, ent->len);
+ if (ent->pad == 1) {
+ address_space_rw(&address_space_io, ent->phys_addr,
+ MEMTXATTRS_NONE, ent->data, ent->len, true);
+ } else {
+ cpu_physical_memory_write(ent->phys_addr, ent->data, ent->len);
+ }
smp_wmb();
ring->first = (ring->first + 1) % KVM_COALESCED_MMIO_MAX;
}
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 82843ed..c6c2e57 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -68,6 +68,7 @@ typedef struct RTCState {
ISADevice parent_obj;
MemoryRegion io;
+ MemoryRegion io_mm;
uint8_t cmos_data[128];
uint8_t cmos_index;
int32_t base_year;
@@ -985,6 +986,11 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
memory_region_init_io(&s->io, OBJECT(s), &cmos_ops, s, "rtc", 2);
isa_register_ioport(isadev, &s->io, base);
+ memory_region_set_flush_coalesced(&s->io);
+
+ memory_region_init_io(&s->io_mm, OBJECT(s), &cmos_ops, s, "rtc1", 1);
+ isa_register_ioport(isadev, &s->io_mm, base);
+ memory_region_add_coalescing(&s->io_mm, 0, 1);
qdev_set_legacy_instance_id(dev, base, 3);
qemu_register_reset(rtc_reset, s);
diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h
index e601061..a628999 100644
--- a/include/exec/memattrs.h
+++ b/include/exec/memattrs.h
@@ -45,5 +45,6 @@ typedef struct MemTxAttrs {
* from "didn't specify" if necessary).
*/
#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = 1 })
+#define MEMTXATTRS_NONE ((MemTxAttrs) { 0 })
#endif
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-12 3:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-02 15:27 [PATCH] target-i386 : reduce rtc 0x70 access vm-exit time Peng Hao
2017-08-12 12:05 [PATCH] target-i386: " Peng Hao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).