From: Don Slutz Subject: [PATCH v2 08/10] hvm/hpet: Prevent master clock equal to comparator while enabled Date: Tue, 8 Apr 2014 10:24:52 -0400 Message-ID: <1396967094-29484-9-git-send-email-dslutz@verizon.com> References: <1396967094-29484-1-git-send-email-dslutz@verizon.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1396967094-29484-1-git-send-email-dslutz@verizon.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Keir Fraser , Don Slutz , Jan Beulich List-Id: xen-devel@lists.xenproject.org Based on the software-developers-hpet-spec-1-0a.pdf, the comparator for a periodic timer will change to the new value when it matches the master clock. The current code here uses a very standard rounding formula of "((x + y - 1) / y) * y". This is wrong because in this case you need to go to the next comparator value when "x" equals "y". Not when "x + 1" equals "y". In this case "y" is the period and "x" is the master clock. Signed-off-by: Don Slutz --- xen/arch/x86/hvm/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index 11ba2ba..28f5224 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -97,7 +97,7 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn, if (period) { elapsed = hpet_read_maincounter(h, guest_time) + - period - 1 - comparator; + period - comparator; comparator += (elapsed / period) * period; h->hpet.comparator64[tn] = comparator; } -- 1.8.4