From patchwork Wed Aug 2 15:27:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Hao X-Patchwork-Id: 9876077 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D8CBC60360 for ; Wed, 2 Aug 2017 07:15:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC60E28774 for ; Wed, 2 Aug 2017 07:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C13CB2877B; Wed, 2 Aug 2017 07:15:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F171928774 for ; Wed, 2 Aug 2017 07:15:30 +0000 (UTC) Received: from localhost ([::1]:45817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcnsO-0005LP-Lj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 02 Aug 2017 03:15:28 -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 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 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 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_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; 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 #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)