From patchwork Fri Dec 23 08:41:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Yu C" X-Patchwork-Id: 9487257 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 4D2F5601D2 for ; Fri, 23 Dec 2016 08:33:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4280727B2F for ; Fri, 23 Dec 2016 08:33:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3712427BE5; Fri, 23 Dec 2016 08:33:29 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D14B27B2F for ; Fri, 23 Dec 2016 08:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752549AbcLWIcr (ORCPT ); Fri, 23 Dec 2016 03:32:47 -0500 Received: from mga14.intel.com ([192.55.52.115]:33220 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751882AbcLWIcq (ORCPT ); Fri, 23 Dec 2016 03:32:46 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 23 Dec 2016 00:32:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,392,1477983600"; d="scan'208";a="1103355758" Received: from yu-desktop-1.sh.intel.com ([10.239.160.134]) by fmsmga002.fm.intel.com with ESMTP; 23 Dec 2016 00:32:40 -0800 From: Chen Yu To: kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Len Brown , Chen Yu , Paolo Bonzini , "Radim Krcmar" , Marcelo Tosatti , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Wanpeng Li Subject: [PATCH][RFC] VM: x86: Return ealier if clocksource has not changed Date: Fri, 23 Dec 2016 16:41:53 +0800 Message-Id: <1482482513-24151-1-git-send-email-yu.c.chen@intel.com> X-Mailer: git-send-email 2.7.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the notifier of pvclock_gtod_notify() get invoked frequently due to the periodic update_wall_time(). This might slow down the system a little bit as there might be redundant execution code path and unnecessary lock contention in update_pvclock_gtod(), which was found when I was doing suspend/resume speed testings. As pvclock_gtod_notify() should be invoked only when clocksource has changed, according to Commit 16e8d74d2da9 ("KVM: x86: notifier for clocksource changes") , either we can add a new notifier for clocksource switch, or we can simply bypass the following code in pvclock_gtod_notify() earlier if there is no clocksource switch. Cc: Paolo Bonzini Cc: "Radim Krcmar" Cc: Marcelo Tosatti Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Wanpeng Li Signed-off-by: Chen Yu --- arch/x86/kvm/x86.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 445c51b..54aa32d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5961,13 +5961,14 @@ static int pvclock_gtod_notify(struct notifier_block *nb, unsigned long unused, struct pvclock_gtod_data *gtod = &pvclock_gtod_data; struct timekeeper *tk = priv; + if (likely(gtod->clock.vclock_mode == VCLOCK_TSC)) + return 0; update_pvclock_gtod(tk); /* disable master clock if host does not trust, or does not * use, TSC clocksource */ - if (gtod->clock.vclock_mode != VCLOCK_TSC && - atomic_read(&kvm_guest_has_master_clock) != 0) + if (atomic_read(&kvm_guest_has_master_clock) != 0) queue_work(system_long_wq, &pvclock_gtod_work); return 0;