From nobody Sat Apr 20 13:10:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150251004457926.37004861185642; Fri, 11 Aug 2017 20:54:04 -0700 (PDT) Received: from localhost ([::1]:50621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgNUv-0005lI-D2 for importer@patchew.org; Fri, 11 Aug 2017 23:54:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgNTx-0005Jh-4k for qemu-devel@nongnu.org; Fri, 11 Aug 2017 23:53:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dgNTt-0002nf-7L for qemu-devel@nongnu.org; Fri, 11 Aug 2017 23:53:01 -0400 Received: from mxhk.zte.com.cn ([63.217.80.70]:60921 helo=zte.com.cn) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgNTs-0002mo-K7 for qemu-devel@nongnu.org; Fri, 11 Aug 2017 23:52:57 -0400 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 12 Aug 2017 03:52:31 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v7C3qbe9024334; Sat, 12 Aug 2017 11:52:37 +0800 (GMT-8) (envelope-from peng.hao2@zte.com.cn) Received: from localhost.localdomain ([10.74.120.59]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017081211524348-426771 ; Sat, 12 Aug 2017 11:52:43 +0800 X-scanvirus: By SEG_CYREN AntiVirus Engine X-scanresult: CLEAN X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170812115231 From: Peng Hao To: pbonzini@redhat.com, mst@redhat.com Date: Sat, 12 Aug 2017 20:05:05 +0800 Message-Id: <1502539505-80366-1-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-08-12 11:52:43, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-08-12 11:52:17, Serialize complete at 2017-08-12 11:52:17 X-MAIL: mse01.zte.com.cn v7C3qbe9024334 X-HQIP: 127.0.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 63.217.80.70 Subject: [Qemu-devel] [PATCH] target-i386: reduce rtc 0x70 access vm-exit time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Hao , qemu-devel@nongnu.org, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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.4= 1%) 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 --- 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 *liste= ner, } } =20 +static void kvm_coalesce_io_add(MemoryListener *listener, MemoryRegionSect= ion *section, + hwaddr start, hwaddr size) +{ + KVMState *s =3D kvm_state; + + if (s->coalesced_mmio) { + struct kvm_coalesced_mmio_zone zone; + + zone.addr =3D start; + zone.size =3D size; + zone.pad =3D 1; + (void)kvm_vm_ioctl(s, KVM_REGISTER_COALESCED_MMIO, &zone); + } +} + +static void kvm_coalesce_io_del(MemoryListener *listener, MemoryRegionSect= ion *section, + hwaddr start, hwaddr size) +{ + KVMState *s =3D kvm_state; + + if (s->coalesced_mmio) { + struct kvm_coalesced_mmio_zone zone; + + zone.addr =3D start; + zone.size =3D size; + zone.pad =3D 1; + + (void)kvm_vm_ioctl(s, KVM_UNREGISTER_COALESCED_MMIO, &zone); + } + +} + +static MemoryListener kvm_coalesced_io_listener =3D { + .coalesced_mmio_add =3D kvm_coalesce_io_add, + .coalesced_mmio_del =3D kvm_coalesce_io_del, + .priority =3D 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); =20 s->many_ioeventfds =3D kvm_check_many_ioeventfds(); =20 @@ -1841,8 +1881,12 @@ void kvm_flush_coalesced_mmio_buffer(void) struct kvm_coalesced_mmio *ent; =20 ent =3D &ring->coalesced_mmio[ring->first]; - - cpu_physical_memory_write(ent->phys_addr, ent->data, ent->len); + if (ent->pad =3D=3D 1) { + address_space_rw(&address_space_io, ent->phys_addr, + MEMTXATTRS_NONE, ent->data, ent->len, tru= e); + } else { + cpu_physical_memory_write(ent->phys_addr, ent->data, ent->= len); + } smp_wmb(); ring->first =3D (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; =20 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 **er= rp) =20 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); =20 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 =3D 1 }) +#define MEMTXATTRS_NONE ((MemTxAttrs) { 0 }) =20 #endif --=20 1.8.3.1