All of lore.kernel.org
 help / color / mirror / Atom feed
From: Don Slutz <dslutz@verizon.com>
To: Tim Deegan <tim@xen.org>, Jan Beulich <JBeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>, Don Slutz <dslutz@verizon.com>,
	xen-devel@lists.xen.org
Subject: Re: [PATCH v3 11/11] hvm/hpet: handle 1st period special
Date: Thu, 01 May 2014 16:19:02 -0400	[thread overview]
Message-ID: <5362AC36.70609@terremark.com> (raw)
In-Reply-To: <20140501103111.GA77240@deinos.phlegethon.org>

On 05/01/14 06:31, Tim Deegan wrote:
> At 13:32 +0100 on 25 Apr (1398429157), Jan Beulich wrote:
>>>>> On 17.04.14 at 19:43, <dslutz@verizon.com> wrote:
>>> v3:
>>>    Better commit message.
>>>    More setting of first_mc64 & first_enabled when needed.
>>>    Switch to bool_t.
>>>
>>>   xen/arch/x86/hvm/hpet.c       | 83 ++++++++++++++++++++++++++++++++++++-------
>>>   xen/include/asm-x86/hvm/vpt.h |  2 ++
>>>   2 files changed, 73 insertions(+), 12 deletions(-)
>> I still can't help myself thinking that this must be achievable with less
>> special casing - I just can't imagine that hardware also has this huge
>> an amount of special case logic just for the first period.
> +1.  I didn't follow the explanation on v1 very clearly, so perhaps
> you can correct my understanding, but I _think_ the issue you're
> describing is:
>
>   when we read the comparator, we try to wind it forward from its
>   current value towards the main counter value, by adding as many
>   periods as will fit.

Yes.

>   If the guest sets the comparator >1 period away, we'll incorrectly
>   warp the comparator to some foolish value as soon as we read it.

Yes. The "foolish value" falls within the bounds of a period.

> So, you're adding mechanism to detect the first interrupt after a
> comparator set (or when the main counter is being started, or on hpet
> load -- both of those rely on 'first_enabled' being essentialy
> harmless if set when it's _not_ the first interrupt, which suggests
> that maybe that's not the best name for the flag).

It is not harmless if it is set when _not_ in the first interval (before
first interrupt).  Since it is used by hpet_save during migration,
the correct values need to be saved.   I do not care about the
name.

You are missing the case when the guest sets the main counter.



> Couldn't it be fixed more simply by detecting comparator values in the
> past in hpet_get_comparator()?

This statement only works using 64-bit arithmetic for the main counter never
                                          63
changing by more then 2     .   (Which is a boundary case that should not
happen in my life time.)


Without patch #11 (this patch) and without patch #8 (Use signed divide...)
and adding:


commit 8c450bed530b13c3f3d18b9dafb3d1b1d69ac1f2
Author: Don Slutz <dslutz@verizon.com>
Date:   Thu May 1 14:02:47 2014 -0400

     hvm/hpet: Detect comparator values in the past

     Signed-off-by: Don Slutz <dslutz@verizon.com>

diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c
index 4e4da20..d93dd69 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;
+            }
          }
      }



Which I think was what you mean.

It looks to be "ok" (ignoring the boundary case).  So should
I send it as v4?

    -Don Slutz


> Tim.

  reply	other threads:[~2014-05-01 20:19 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 ` [PATCH v3 08/11] hvm/hpet: Use signed divide in hpet_get_comparator Don Slutz
2014-04-23 15:45   ` 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 [this message]
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=5362AC36.70609@terremark.com \
    --to=dslutz@verizon.com \
    --cc=JBeulich@suse.com \
    --cc=keir@xen.org \
    --cc=tim@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.