From nobody Mon Apr 29 15:25:48 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 1501658144068405.9091003027671; Wed, 2 Aug 2017 00:15:44 -0700 (PDT) Received: from localhost ([::1]:45823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcnsb-0005hb-Uc for importer@patchew.org; Wed, 02 Aug 2017 03:15:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcnrq-0005LF-EC for qemu-devel@nongnu.org; Wed, 02 Aug 2017 03:14:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcnrm-0007HI-EK for qemu-devel@nongnu.org; Wed, 02 Aug 2017 03:14:54 -0400 Received: from out1.zte.com.cn ([202.103.147.172]:55760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcnrl-00079m-QC for qemu-devel@nongnu.org; Wed, 02 Aug 2017 03:14:50 -0400 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 2 Aug 2017 07:12:31 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v727ERGY098168; Wed, 2 Aug 2017 15:14:27 +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 2017080215143166-603360 ; Wed, 2 Aug 2017 15:14:31 +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,20170802151231 From: Peng Hao To: pbonzini@redhat.com Date: Wed, 2 Aug 2017 23:27:34 +0800 Message-Id: <1501687654-10733-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-02 15:14:31, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-08-02 15:14:19, Serialize complete at 2017-08-02 15:14:19 X-MAIL: mse01.zte.com.cn v727ERGY098168 X-HQIP: 127.0.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 202.103.147.172 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=20 rtc as system tick.guest access rtc like this: write register index=20 to 0x70, then write or read data from 0x71. writing 0x70 port is=20 just as index and do nothing else. So writing 0x70 is not necessory=20 to exit to userspace every time and caching rtc register index in kvm=20 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 Reviewed-by: Liu Yi --- accel/kvm/kvm-all.c | 17 +++++++++++++++++ linux-headers/linux/kvm.h | 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_i= rq irq, int gsi) g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi)); } =20 +static void kvm_vrtc_create(KVMState *s) +{ + int ret; + if (kvm_check_extension(s, KVM_CAP_VRTC)) { + return; + } + + ret =3D 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); =20 if (kvm_eventfds_allowed) { s->memory_listener.listener.eventfd_add =3D kvm_mem_ioeventfd_add; diff --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 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 @@ -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_inf= o) - +#define KVM_CREATE_VRTC _IO(KVMIO, 0xba) /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) =20 --=20 1.8.3.1