From patchwork Fri Apr 12 20:18:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 10899109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2507F1708 for ; Fri, 12 Apr 2019 20:18:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06D8828E17 for ; Fri, 12 Apr 2019 20:18:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF4B528EBA; Fri, 12 Apr 2019 20:18:43 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 9EAA728E17 for ; Fri, 12 Apr 2019 20:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727114AbfDLUSm (ORCPT ); Fri, 12 Apr 2019 16:18:42 -0400 Received: from mga11.intel.com ([192.55.52.93]:64856 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfDLUSl (ORCPT ); Fri, 12 Apr 2019 16:18:41 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2019 13:18:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,342,1549958400"; d="scan'208";a="140107053" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.181]) by fmsmga008.fm.intel.com with ESMTP; 12 Apr 2019 13:18:40 -0700 From: Sean Christopherson To: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Cc: kvm@vger.kernel.org, Sean Christopherson , Liran Alon , Wanpeng Li Subject: [PATCH 6/7] KVM: lapic: Clean up the code for handling of a pre-expired hv_timer Date: Fri, 12 Apr 2019 13:18:33 -0700 Message-Id: <20190412201834.10831-7-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190412201834.10831-1-sean.j.christopherson@intel.com> References: <20190412201834.10831-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Calling apic_timer_expired() is a nop when a timer interrupt is already pending, i.e. there's no need to call apic_timer_expired() when there's a pending interrupt and the hv_timer wants to pend its own interrupt. Separate the two flows to make the code more readable and to avoid an unnecessary function call and read to ktimer->pending. Cc: Wanpeng Li Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 1d649a2af04c..f0be6f148a47 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1703,9 +1703,12 @@ static bool start_hv_timer(struct kvm_lapic *apic) * the window. For periodic timer, leave the hv timer running for * simplicity, and the deadline will be recomputed on the next vmexit. */ - if (!apic_lvtt_period(apic) && (r || atomic_read(&ktimer->pending))) { - if (r) - apic_timer_expired(apic); + if (!apic_lvtt_period(apic) && atomic_read(&ktimer->pending)) + return false; + + /* set_hv_timer() returns '1' when the timer has already expired. */ + if (r) { + apic_timer_expired(apic); return false; }