From patchwork Fri Jan 9 07:01:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 1455 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n096vj5T027532 for ; Thu, 8 Jan 2009 22:57:46 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751347AbZAIHBU (ORCPT ); Fri, 9 Jan 2009 02:01:20 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751492AbZAIHBU (ORCPT ); Fri, 9 Jan 2009 02:01:20 -0500 Received: from mga03.intel.com ([143.182.124.21]:21006 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751347AbZAIHBT (ORCPT ); Fri, 9 Jan 2009 02:01:19 -0500 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 08 Jan 2009 23:01:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.37,238,1231142400"; d="scan'208";a="98112880" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.176]) by azsmga001.ch.intel.com with ESMTP; 08 Jan 2009 23:01:14 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1LLBMl-0004tD-IU; Fri, 09 Jan 2009 15:01:11 +0800 From: Sheng Yang To: Avi Kivity Cc: kvm@vger.kernel.org, Sheng Yang Subject: [PATCH 1/1] KVM: x86: No wrap around for lapic timer Date: Fri, 9 Jan 2009 15:01:11 +0800 Message-Id: <1231484471-18777-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.5.6.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Or would we meet 585 years later? :) Seriously, this wrap around hide implicit error... Reminder by Alexander Graf. Signed-off-by: Sheng Yang --- arch/x86/kvm/lapic.c | 13 ++----------- 1 files changed, 2 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index afac68c..87c1da5 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -524,18 +524,9 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic) if (tmcct == 0) return 0; - if (unlikely(ktime_to_ns(now) <= - ktime_to_ns(apic->timer.last_update))) { - /* Wrap around */ - passed = ktime_add(( { - (ktime_t) { - .tv64 = KTIME_MAX - - (apic->timer.last_update).tv64}; } - ), now); - apic_debug("time elapsed\n"); - } else - passed = ktime_sub(now, apic->timer.last_update); + BUG_ON(ktime_to_ns(now) <= ktime_to_ns(apic->timer.last_update)); + passed = ktime_sub(now, apic->timer.last_update); counter_passed = div64_u64(ktime_to_ns(passed), (APIC_BUS_CYCLE_NS * apic->timer.divide_count));