From: Don Slutz <dslutz@verizon.com>
To: xen-devel@lists.xen.org
Cc: Keir Fraser <keir@xen.org>, Don Slutz <dslutz@verizon.com>,
Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v3 08/11] hvm/hpet: Use signed divide in hpet_get_comparator.
Date: Thu, 17 Apr 2014 13:43:02 -0400 [thread overview]
Message-ID: <1397756585-27091-9-git-send-email-dslutz@verizon.com> (raw)
In-Reply-To: <1397756585-27091-1-git-send-email-dslutz@verizon.com>
This is done so that when comparator is less then or equal to one
period it does not change.
The code lines:
elapsed = hpet_read_maincounter(h, guest_time) +
period - 1 - comparator;
comparator += (elapsed / period) * period;
are what matter here. For almost all cases where
"hpet_read_maincounter() + period - 1" is greater then
"comparator", a signed divide will produce the same answer as an
unsigned divide. One of the problem areas is when
"hpet_read_maincounter() + period - 1" needs more then 64 bits to
represent it. It includes cases where hpet_read_maincounter() has
wrapped (I.E. needs more then 64 bits to correctly represent it),
but "comparator" has not wrapped. However "elapsed" is correctly
greater then zero as long as the mathematical result only takes 63
bits to represent it.
It is safe to declare period as a signed integer because the code
already limits it to 63 bits.
Using some numbers to help show the issue:
hpet_read_maincounter(h, guest_time) = 67752
period = 62500
comparator = 130252 == 67752 + 62500
what unsigned signed
comparator : 130252 130252
elapsed : 18446744073709551615 -1
elapsed/period : 295147905179352 0
comparator_delta : 18446744073709500000 0
new comparator : 78636 130252
Signed-off-by: Don Slutz <dslutz@verizon.com>
---
xen/arch/x86/hvm/hpet.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c
index 7964df2..e24bc46 100644
--- a/xen/arch/x86/hvm/hpet.c
+++ b/xen/arch/x86/hvm/hpet.c
@@ -89,13 +89,13 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn,
uint64_t guest_time)
{
uint64_t comparator;
- uint64_t elapsed;
+ int64_t elapsed;
comparator = h->hpet.comparator64[tn];
if ( timer_is_periodic(h, tn) )
{
/* update comparator by number of periods elapsed since last update */
- uint64_t period = h->hpet.period[tn];
+ int64_t period = h->hpet.period[tn];
if (period)
{
elapsed = hpet_read_maincounter(h, guest_time) +
--
1.8.4
next prev parent reply other threads:[~2014-04-17 17:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-17 17:42 [PATCH v3 00/11] Prevent one cause of "MP-BIOS bug: 8254 timer"... message from linux Don Slutz
2014-04-17 17:42 ` [optional PATCH v3 01/11] hvm/hpet: Add manual unit test code Don Slutz
2014-04-23 14:41 ` Jan Beulich
2014-04-25 21:26 ` Don Slutz
2014-04-17 17:42 ` [PATCH v3 02/11] hvm/hpet: Only call guest_time_hpet(h) one time per action Don Slutz
2014-04-23 15:07 ` Jan Beulich
2014-04-23 15:42 ` Don Slutz
2014-04-23 15:54 ` Jan Beulich
2014-04-17 17:42 ` [PATCH v3 03/11] hvm/hpet: Only set comparator or period not both Don Slutz
2014-04-23 15:10 ` Jan Beulich
2014-04-17 17:42 ` [PATCH v3 04/11] hvm/hpet: Correctly limit period to a maximum Don Slutz
2014-04-23 15:11 ` Jan Beulich
2014-04-17 17:42 ` [PATCH v3 05/11] hvm/hpet: In hpet_save, correctly compute mc64 Don Slutz
2014-04-23 15:12 ` Jan Beulich
2014-04-17 17:43 ` [PATCH v3 06/11] hvm/hpet: In hpet_save, call hpet_get_comparator Don Slutz
2014-04-23 15:21 ` Jan Beulich
2014-04-25 21:42 ` Don Slutz
2014-04-17 17:43 ` [PATCH v3 07/11] hvm/hpet: Init comparator64 like comparator Don Slutz
2014-04-23 15:23 ` Jan Beulich
2014-04-25 22:00 ` Don Slutz
2014-04-17 17:43 ` Don Slutz [this message]
2014-04-23 15:45 ` [PATCH v3 08/11] hvm/hpet: Use signed divide in hpet_get_comparator Jan Beulich
2014-04-26 1:52 ` Slutz, Donald Christopher
2014-04-17 17:43 ` [PATCH v3 09/11] hvm/hpet: comparator can only change when master clock is enabled Don Slutz
2014-04-25 12:23 ` Jan Beulich
2014-04-17 17:43 ` [PATCH v3 10/11] hvm/hpet: Prevent master clock equal to comparator while enabled Don Slutz
2014-04-25 12:25 ` Jan Beulich
2014-04-26 1:50 ` Slutz, Donald Christopher
2014-04-17 17:43 ` [PATCH v3 11/11] hvm/hpet: handle 1st period special Don Slutz
2014-04-25 12:32 ` Jan Beulich
2014-04-26 14:10 ` Slutz, Donald Christopher
2014-05-01 10:31 ` Tim Deegan
2014-05-01 20:19 ` Don Slutz
2014-05-02 13:19 ` Tim Deegan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1397756585-27091-9-git-send-email-dslutz@verizon.com \
--to=dslutz@verizon.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).