From: Don Slutz Subject: [PATCH v4 10/10] hvm/hpet: Detect comparator values in the past Date: Fri, 2 May 2014 16:18:08 -0400 Message-ID: <1399061888-25756-11-git-send-email-dslutz@verizon.com> References: <1399061888-25756-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: <1399061888-25756-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: Tim Deegan , Keir Fraser , Don Slutz , Jan Beulich List-Id: xen-devel@lists.xenproject.org This statement only works using 64-bit arithmetic for the main 63 counter never changing by more then 2 . (Which is a boundary case that should not happen in my life time.) Signed-off-by: Don Slutz Acked-by: Tim Deegan --- xen/arch/x86/hvm/hpet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index 2a99fed..167994e 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -98,10 +98,12 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn, uint64_t period = h->hpet.period[tn]; if (period) { - elapsed = hpet_read_maincounter(h, guest_time) + - period - comparator; - comparator += (elapsed / period) * period; - h->hpet.comparator64[tn] = comparator; + elapsed = hpet_read_maincounter(h, guest_time) - comparator; + if ( (int64_t)elapsed >= 0 ) + { + comparator += ((elapsed + period) / period) * period; + h->hpet.comparator64[tn] = comparator; + } } } -- 1.8.4