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 11/11] hvm/hpet: handle 1st period special
Date: Thu, 17 Apr 2014 13:43:05 -0400 [thread overview]
Message-ID: <1397756585-27091-12-git-send-email-dslutz@verizon.com> (raw)
In-Reply-To: <1397756585-27091-1-git-send-email-dslutz@verizon.com>
The software-developers-hpet-spec-1-0a.pdf says that the 1st
interrupt is based on the setting of comparator. After that it will
be on each period. Add code that checks for this special case.
Add a callback routine when this special case is active that
will disable the special case on the 1st interrupt.
The code lines:
elapsed = mc + period - comparator;
comparator += (elapsed / period) * period;
are what matter here.
Using some numbers to help show the issue:
mc = 67752
period = 62500
comparator : 380252
elapsed : -250000
elapsed/period : -4
comparator_delta : -250000
new comparator : 130252
So this code needs to be skipped on the 1st period.
The change "hvm/hpet: In hpet_save, call hpet_get_comparator." that
previously was "technically not required", is now required. Because
hpet_load now handles 1st period differently, the hpet_save needs to
provide the data as the software-developers-hpet-spec-1-0a.pdf
implies.
Signed-off-by: Don Slutz <dslutz@verizon.com>
---
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(-)
diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c
index 50047f5..eddc6a0 100644
--- a/xen/arch/x86/hvm/hpet.c
+++ b/xen/arch/x86/hvm/hpet.c
@@ -96,10 +96,18 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn,
{
/* update comparator by number of periods elapsed since last update */
int64_t period = h->hpet.period[tn];
+ uint64_t mc = hpet_read_maincounter(h, guest_time);
+
+ if ( h->hpet.first_enabled[tn] )
+ {
+ if ( mc >= h->hpet.first_mc64[tn] && mc < comparator )
+ period = 0; /* skip update */
+ else
+ h->hpet.first_enabled[tn] = 0;
+ }
if (period)
{
- elapsed = hpet_read_maincounter(h, guest_time) +
- period - comparator;
+ elapsed = mc + period - comparator;
comparator += (elapsed / period) * period;
h->hpet.comparator64[tn] = comparator;
}
@@ -208,12 +216,18 @@ static void hpet_stop_timer(HPETState *h, unsigned int tn,
* 1/(2^10) second, namely, 0.9765625 milliseconds */
#define HPET_TINY_TIME_SPAN ((h->stime_freq >> 10) / STIME_PER_HPET_TICK)
+static void hpet_time_fired(struct vcpu *v, void *priv)
+{
+ bool_t *first_enabled_p = (bool_t *)priv;
+
+ *first_enabled_p = 0;
+}
+
static void hpet_set_timer(HPETState *h, unsigned int tn,
uint64_t guest_time)
{
uint64_t tn_cmp, cur_tick, diff;
unsigned int irq;
- unsigned int oneshot;
ASSERT(tn < HPET_TIMER_NUM);
ASSERT(spin_is_locked(&h->lock));
@@ -262,15 +276,34 @@ static void hpet_set_timer(HPETState *h, unsigned int tn,
* have elapsed between the time the comparator was written and the timer
* being enabled (now).
*/
- oneshot = !timer_is_periodic(h, tn);
- TRACE_2_LONG_4D(TRC_HVM_EMUL_HPET_START_TIMER, tn, irq,
- TRC_PAR_LONG(hpet_tick_to_ns(h, diff)),
- TRC_PAR_LONG(oneshot ? 0LL :
- hpet_tick_to_ns(h, h->hpet.period[tn])));
- create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
- hpet_tick_to_ns(h, diff),
- oneshot ? 0 : hpet_tick_to_ns(h, h->hpet.period[tn]),
- irq, NULL, NULL);
+
+ if ( !timer_is_periodic(h, tn) )
+ {
+ TRACE_2_LONG_4D(TRC_HVM_EMUL_HPET_START_TIMER, tn, irq,
+ TRC_PAR_LONG(hpet_tick_to_ns(h, diff)),
+ TRC_PAR_LONG(0LL));
+ create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
+ hpet_tick_to_ns(h, diff),
+ 0, irq, NULL, NULL);
+ }
+ else
+ {
+ TRACE_2_LONG_4D(TRC_HVM_EMUL_HPET_START_TIMER, tn, irq,
+ TRC_PAR_LONG(hpet_tick_to_ns(h, diff)),
+ TRC_PAR_LONG(
+ hpet_tick_to_ns(h, h->hpet.period[tn])));
+ if ( h->hpet.first_enabled[tn] )
+ create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
+ hpet_tick_to_ns(h, diff),
+ hpet_tick_to_ns(h, h->hpet.period[tn]),
+ irq, hpet_time_fired,
+ &h->hpet.first_enabled[tn]);
+ else
+ create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
+ hpet_tick_to_ns(h, diff),
+ hpet_tick_to_ns(h, h->hpet.period[tn]),
+ irq, NULL, NULL);
+ }
}
static inline uint64_t hpet_fixup_reg(
@@ -343,6 +376,15 @@ static int hpet_write(
case HPET_COUNTER:
h->hpet.mc64 = new_val;
+ for ( i = 0; i < HPET_TIMER_NUM; i++ )
+ if ( timer_enabled(h, i) )
+ {
+ if ( timer_is_periodic(h, i) && h->hpet.period[i] )
+ {
+ h->hpet.first_mc64[i] = new_val;
+ h->hpet.first_enabled[i] = 1;
+ }
+ }
if ( hpet_enabled(h) )
{
gdprintk(XENLOG_WARNING,
@@ -416,6 +458,8 @@ static int hpet_write(
if ( new_val > max_period )
new_val = max_period;
h->hpet.period[tn] = new_val;
+ h->hpet.first_mc64[tn] = hpet_read_maincounter(h, guest_time);
+ h->hpet.first_enabled[tn] = 1;
}
else
{
@@ -435,6 +479,11 @@ static int hpet_write(
if ( timer_is_32bit(h, tn) )
new_val = (uint32_t)new_val;
h->hpet.timers[tn].cmp = new_val;
+ if ( timer_is_periodic(h, tn) && h->hpet.period[tn] )
+ {
+ h->hpet.first_mc64[tn] = hpet_read_maincounter(h, guest_time);
+ h->hpet.first_enabled[tn] = 1;
+ }
}
if ( hpet_enabled(h) && timer_enabled(h, tn) )
set_restart_timer(tn);
@@ -583,6 +632,9 @@ static int hpet_load(struct domain *d, hvm_domain_context_t *h)
if ( timer_is_32bit(hp, i) )
cmp = (uint32_t)cmp;
hp->hpet.timers[i].cmp = cmp;
+ /* Init hidden regs also */
+ hp->hpet.first_mc64[i] = 0;
+ hp->hpet.first_enabled[i] = 0;
}
#undef C
@@ -595,7 +647,14 @@ static int hpet_load(struct domain *d, hvm_domain_context_t *h)
if ( hpet_enabled(hp) )
for ( i = 0; i < HPET_TIMER_NUM; i++ )
if ( timer_enabled(hp, i) )
+ {
+ if ( timer_is_periodic(hp, i) && hp->hpet.period[i] )
+ {
+ hp->hpet.first_mc64[i] = hp->hpet.mc64;
+ hp->hpet.first_enabled[i] = 1;
+ }
hpet_set_timer(hp, i, guest_time);
+ }
spin_unlock(&hp->lock);
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 41159d8..71c383d 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -87,6 +87,8 @@ struct hpet_registers {
/* Hidden register state */
uint64_t period[HPET_TIMER_NUM]; /* Last value written to comparator */
uint64_t comparator64[HPET_TIMER_NUM]; /* 64 bit running comparator */
+ uint64_t first_mc64[HPET_TIMER_NUM]; /* 1st interval main counter */
+ bool_t first_enabled[HPET_TIMER_NUM]; /* In 1st interval */
};
typedef struct HPETState {
--
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 ` [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 ` Don Slutz [this message]
2014-04-25 12:32 ` [PATCH v3 11/11] hvm/hpet: handle 1st period special 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-12-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).