From: Anthony PERARD <anthony.perard@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v3 3/3] x86/vlapic: Apply change to TDCR right away to the timer
Date: Tue, 8 Aug 2017 14:33:00 +0100 [thread overview]
Message-ID: <20170808133300.2277-4-anthony.perard@citrix.com> (raw)
In-Reply-To: <20170808133300.2277-1-anthony.perard@citrix.com>
The description in the Intel SDM of how the divide configuration
register is used: "The APIC timer frequency will be the processor's bus
clock or core crystal clock frequency divided by the value specified in
the divide configuration register."
Observation of baremetal shown that when the TDCR is change, the TMCCT
does not change or make a big jump in value, but the rate at which it
count down change.
The patch update the emulation to APIC timer to so that a change to the
divide configuration would be reflected in the value of the counter and
when the next interrupt is triggered.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Changes in V3:
- do the calculation when the divisor is change only if delta is !0.
---
xen/arch/x86/hvm/vlapic.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c
index 7a5fbb40cd..4bfc53eab7 100644
--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -672,12 +672,13 @@ static void vlapic_tdt_pt_cb(struct vcpu *v, void *data)
/*
* This function is used when a register related to the APIC timer is updated.
* It expects the new value for the register TMICT to be set *before*
- * being called.
+ * being called, and the previous value of the divisor (calculated from TDCR)
+ * to be passed as argument.
* It expect the new value of LVTT to be set *after* being called, with this
* new values passed as parameter (only APIC_TIMER_MODE_MASK bits matter).
*/
static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,
- bool tmict_updated)
+ bool tmict_updated, uint32_t old_divisor)
{
uint64_t period, delta = 0;
bool is_oneshot, is_periodic;
@@ -686,7 +687,7 @@ static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,
is_oneshot = (lvtt & APIC_TIMER_MODE_MASK) == APIC_TIMER_MODE_ONESHOT;
period = (uint64_t)vlapic_get_reg(vlapic, APIC_TMICT)
- * APIC_BUS_CYCLE_NS * vlapic->hw.timer_divisor;
+ * APIC_BUS_CYCLE_NS * old_divisor;
/* Calculate the next time the timer should trigger an interrupt. */
if ( tmict_updated )
@@ -705,6 +706,13 @@ static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,
if ( delta && (is_oneshot || is_periodic) )
{
+ if ( vlapic->hw.timer_divisor != old_divisor )
+ {
+ period = (uint64_t)vlapic_get_reg(vlapic, APIC_TMICT)
+ * APIC_BUS_CYCLE_NS * vlapic->hw.timer_divisor;
+ delta = delta * vlapic->hw.timer_divisor / old_divisor;
+ }
+
TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
TRC_PAR_LONG(is_periodic ? period : 0),
vlapic->pt.irq);
@@ -810,7 +818,7 @@ static void vlapic_reg_write(struct vcpu *v,
}
vlapic->pt.irq = val & APIC_VECTOR_MASK;
- vlapic_update_timer(vlapic, val, false);
+ vlapic_update_timer(vlapic, val, false, vlapic->hw.timer_divisor);
/* fallthrough */
case APIC_LVTTHMR: /* LVT Thermal Monitor */
@@ -839,15 +847,23 @@ static void vlapic_reg_write(struct vcpu *v,
vlapic_set_reg(vlapic, APIC_TMICT, val);
- vlapic_update_timer(vlapic, vlapic_get_reg(vlapic, APIC_LVTT), true);
+ vlapic_update_timer(vlapic, vlapic_get_reg(vlapic, APIC_LVTT), true,
+ vlapic->hw.timer_divisor);
break;
case APIC_TDCR:
+ {
+ uint32_t current_divisor = vlapic->hw.timer_divisor;
+
vlapic_set_tdcr(vlapic, val & 0xb);
+
+ vlapic_update_timer(vlapic, vlapic_get_reg(vlapic, APIC_LVTT), false,
+ current_divisor);
HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER, "timer divisor is %#x",
vlapic->hw.timer_divisor);
break;
}
+ }
}
static int vlapic_write(struct vcpu *v, unsigned long address,
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-08-08 13:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 13:32 [PATCH v3 0/3] Rework vlapic timer to behave more like real-hardware Anthony PERARD
2017-08-08 13:32 ` [PATCH v3 1/3] x86/vlapic: Introduce vlapic_update_timer Anthony PERARD
2017-08-08 13:32 ` [PATCH v3 2/3] x86/vlapic: Keep timer running when switching between one-shot and periodic mode Anthony PERARD
2017-08-08 13:33 ` Anthony PERARD [this message]
2017-08-25 14:40 ` [PATCH v3 0/3] Rework vlapic timer to behave more like real-hardware Jan Beulich
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=20170808133300.2277-4-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xenproject.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).