From: "Jan Beulich" Subject: Re: [PATCH v3 08/11] hvm/hpet: Use signed divide in hpet_get_comparator. Date: Wed, 23 Apr 2014 16:45:19 +0100 Message-ID: <5357FC2F020000780000BABF@nat28.tlf.novell.com> References: <1397756585-27091-1-git-send-email-dslutz@verizon.com> <1397756585-27091-9-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: <1397756585-27091-9-git-send-email-dslutz@verizon.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Don Slutz Cc: Keir Fraser , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 17.04.14 at 19:43, wrote: > 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 "It includes" implies there are other cases, yet I can't see any. (Also twice s/then/than/ I think.) > wrapped (I.E. needs more then 64 bits to correctly represent it), > but "comparator" has not wrapped. But can this happen in practice? Main counter and comparator shouldn't be very far apart, and hence other than "hpet_read_maincounter() + period - 1", "hpet_read_maincounter() + period - 1 - comparator" shouldn't ever require more than 64 bits to correctly represent it. All you really need to deal with is the case where hpet_read_maincounter() + period == comparator, i.e. the 1 being subtracted makes the expression degenerate. So you could simply make the computation and update dependent upon hpet_read_maincounter() + period > comparator. And then again I don't really see why the subtraction of 1 is needed here in the first place. Jan