From: "Jan Beulich" Subject: [PATCH, v2] x86/HVM: assorted RTC emulation adjustments Date: Wed, 22 Aug 2012 16:17:28 +0100 Message-ID: <503514280200007800096FF4@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartECDD8518.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartECDD8518.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - don't call rtc_timer_update() on REG_A writes when the value didn't change (doing the call always was reported to cause wall clock time lagging with the JVM running on Windows) - don't call rtc_timer_update() on REG_B writes at all - only call alarm_timer_update() on REG_B writes when relevant bits change - only call check_update_timer() on REG_B writes when SET changes - instead properly handle AF and PF when the guest is not also setting AIE/PIE respectively (for UF this was already the case, only a comment was slightly inaccurate) - raise the RTC IRQ not only when UIE gets set while UF was already set, but generalize this to cover AIE and PIE as well - properly mask off bit 7 when retrieving the hour values in alarm_timer_update(), and properly use RTC_HOURS_ALARM's bit 7 when converting from 12- to 24-hour value - also handle the two other possible clock bases - use RTC_* names in a couple of places where literal numbers were used so far Note that this only improves the situation described in the thread at http://lists.xen.org/archives/html/xen-devel/2012-08/msg00664.html, there are still problems with the emulation when invoked at a high rate as described there. Signed-off-by: Jan Beulich --- v2: Small adjustment to the pt_update_irq() change, avoiding to call the RTC code for a HPET event (which also may pass 8 [aka RTC_IRQ] as create_periodic_time()'s "irq" argument. --- a/xen/arch/x86/hvm/rtc.c +++ b/xen/arch/x86/hvm/rtc.c @@ -50,11 +50,24 @@ static void rtc_set_time(RTCState *s); static inline int from_bcd(RTCState *s, int a); static inline int convert_hour(RTCState *s, int hour); =20 -static void rtc_periodic_cb(struct vcpu *v, void *opaque) +static void rtc_toggle_irq(RTCState *s) +{ + struct domain *d =3D vrtc_domain(s); + + ASSERT(spin_is_locked(&s->lock)); + s->hw.cmos_data[RTC_REG_C] |=3D RTC_IRQF; + hvm_isa_irq_deassert(d, RTC_IRQ); + hvm_isa_irq_assert(d, RTC_IRQ); +} + +void rtc_periodic_interrupt(void *opaque) { RTCState *s =3D opaque; + spin_lock(&s->lock); - s->hw.cmos_data[RTC_REG_C] |=3D 0xc0; + s->hw.cmos_data[RTC_REG_C] |=3D RTC_PF; + if ( s->hw.cmos_data[RTC_REG_B] & RTC_PIE ) + rtc_toggle_irq(s); spin_unlock(&s->lock); } =20 @@ -68,19 +81,25 @@ static void rtc_timer_update(RTCState *s ASSERT(spin_is_locked(&s->lock)); =20 period_code =3D s->hw.cmos_data[RTC_REG_A] & RTC_RATE_SELECT; - if ( (period_code !=3D 0) && (s->hw.cmos_data[RTC_REG_B] & RTC_PIE) ) + switch ( s->hw.cmos_data[RTC_REG_A] & RTC_DIV_CTL ) { - if ( period_code <=3D 2 ) + case RTC_REF_CLCK_32KHZ: + if ( (period_code !=3D 0) && (period_code <=3D 2) ) period_code +=3D 7; - - period =3D 1 << (period_code - 1); /* period in 32 Khz cycles */ - period =3D DIV_ROUND((period * 1000000000ULL), 32768); /* period = in ns */ - create_periodic_time(v, &s->pt, period, period, RTC_IRQ, - rtc_periodic_cb, s); - } - else - { + /* fall through */ + case RTC_REF_CLCK_1MHZ: + case RTC_REF_CLCK_4MHZ: + if ( period_code !=3D 0 ) + { + period =3D 1 << (period_code - 1); /* period in 32 Khz cycles = */ + period =3D DIV_ROUND(period * 1000000000ULL, 32768); /* in ns = */ + create_periodic_time(v, &s->pt, period, period, RTC_IRQ, = NULL, s); + break; + } + /* fall through */ + default: destroy_periodic_time(&s->pt); + break; } } =20 @@ -102,7 +121,7 @@ static void check_update_timer(RTCState=20 guest_usec =3D get_localtime_us(d) % USEC_PER_SEC; if (guest_usec >=3D (USEC_PER_SEC - 244)) { - /* RTC is in update cycle when enabling UIE */ + /* RTC is in update cycle */ s->hw.cmos_data[RTC_REG_A] |=3D RTC_UIP; next_update_time =3D (USEC_PER_SEC - guest_usec) * NS_PER_USEC= ; expire_time =3D NOW() + next_update_time; @@ -144,7 +163,6 @@ static void rtc_update_timer(void *opaqu static void rtc_update_timer2(void *opaque) { RTCState *s =3D opaque; - struct domain *d =3D vrtc_domain(s); =20 spin_lock(&s->lock); if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) @@ -152,11 +170,7 @@ static void rtc_update_timer2(void *opaq s->hw.cmos_data[RTC_REG_C] |=3D RTC_UF; s->hw.cmos_data[RTC_REG_A] &=3D ~RTC_UIP; if ((s->hw.cmos_data[RTC_REG_B] & RTC_UIE)) - { - s->hw.cmos_data[RTC_REG_C] |=3D RTC_IRQF; - hvm_isa_irq_deassert(d, RTC_IRQ); - hvm_isa_irq_assert(d, RTC_IRQ); - } + rtc_toggle_irq(s); check_update_timer(s); } spin_unlock(&s->lock); @@ -175,21 +189,18 @@ static void alarm_timer_update(RTCState=20 =20 stop_timer(&s->alarm_timer); =20 - if ((s->hw.cmos_data[RTC_REG_B] & RTC_AIE) && - !(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) + if ( !(s->hw.cmos_data[RTC_REG_B] & RTC_SET) ) { s->current_tm =3D gmtime(get_localtime(d)); rtc_copy_date(s); =20 alarm_sec =3D from_bcd(s, s->hw.cmos_data[RTC_SECONDS_ALARM]); alarm_min =3D from_bcd(s, s->hw.cmos_data[RTC_MINUTES_ALARM]); - alarm_hour =3D from_bcd(s, s->hw.cmos_data[RTC_HOURS_ALARM]); - alarm_hour =3D convert_hour(s, alarm_hour); + alarm_hour =3D convert_hour(s, s->hw.cmos_data[RTC_HOURS_ALARM]); =20 cur_sec =3D from_bcd(s, s->hw.cmos_data[RTC_SECONDS]); cur_min =3D from_bcd(s, s->hw.cmos_data[RTC_MINUTES]); - cur_hour =3D from_bcd(s, s->hw.cmos_data[RTC_HOURS]); - cur_hour =3D convert_hour(s, cur_hour); + cur_hour =3D convert_hour(s, s->hw.cmos_data[RTC_HOURS]); =20 next_update_time =3D USEC_PER_SEC - (get_localtime_us(d) % = USEC_PER_SEC); next_update_time =3D next_update_time * NS_PER_USEC + NOW(); @@ -343,7 +354,6 @@ static void alarm_timer_update(RTCState=20 static void rtc_alarm_cb(void *opaque) { RTCState *s =3D opaque; - struct domain *d =3D vrtc_domain(s); =20 spin_lock(&s->lock); if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) @@ -351,11 +361,7 @@ static void rtc_alarm_cb(void *opaque) s->hw.cmos_data[RTC_REG_C] |=3D RTC_AF; /* alarm interrupt */ if (s->hw.cmos_data[RTC_REG_B] & RTC_AIE) - { - s->hw.cmos_data[RTC_REG_C] |=3D RTC_IRQF; - hvm_isa_irq_deassert(d, RTC_IRQ); - hvm_isa_irq_assert(d, RTC_IRQ); - } + rtc_toggle_irq(s); alarm_timer_update(s); } spin_unlock(&s->lock); @@ -365,6 +371,7 @@ static int rtc_ioport_write(void *opaque { RTCState *s =3D opaque; struct domain *d =3D vrtc_domain(s); + uint32_t orig, mask; =20 spin_lock(&s->lock); =20 @@ -382,6 +389,7 @@ static int rtc_ioport_write(void *opaque return 0; } =20 + orig =3D s->hw.cmos_data[s->hw.cmos_index]; switch ( s->hw.cmos_index ) { case RTC_SECONDS_ALARM: @@ -405,9 +413,9 @@ static int rtc_ioport_write(void *opaque break; case RTC_REG_A: /* UIP bit is read only */ - s->hw.cmos_data[RTC_REG_A] =3D (data & ~RTC_UIP) | - (s->hw.cmos_data[RTC_REG_A] & RTC_UIP); - rtc_timer_update(s); + s->hw.cmos_data[RTC_REG_A] =3D (data & ~RTC_UIP) | (orig & = RTC_UIP); + if ( (data ^ orig) & (RTC_RATE_SELECT | RTC_DIV_CTL) ) + rtc_timer_update(s); break; case RTC_REG_B: if ( data & RTC_SET ) @@ -415,7 +423,7 @@ static int rtc_ioport_write(void *opaque /* set mode: reset UIP mode */ s->hw.cmos_data[RTC_REG_A] &=3D ~RTC_UIP; /* adjust cmos before stopping */ - if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) + if (!(orig & RTC_SET)) { s->current_tm =3D gmtime(get_localtime(d)); rtc_copy_date(s); @@ -424,21 +432,26 @@ static int rtc_ioport_write(void *opaque else { /* if disabling set mode, update the time */ - if ( s->hw.cmos_data[RTC_REG_B] & RTC_SET ) + if ( orig & RTC_SET ) rtc_set_time(s); } - /* if the interrupt is already set when the interrupt become - * enabled, raise an interrupt immediately*/ - if ((data & RTC_UIE) && !(s->hw.cmos_data[RTC_REG_B] & RTC_UIE)) - if (s->hw.cmos_data[RTC_REG_C] & RTC_UF) + /* + * If the interrupt is already set when the interrupt becomes + * enabled, raise an interrupt immediately. + * NB: RTC_{A,P,U}IE =3D=3D RTC_{A,P,U}F respectively. + */ + for ( mask =3D RTC_UIE; mask <=3D RTC_PIE; mask <<=3D 1 ) + if ( (data & mask) && !(orig & mask) && + (s->hw.cmos_data[RTC_REG_C] & mask) ) { - hvm_isa_irq_deassert(d, RTC_IRQ); - hvm_isa_irq_assert(d, RTC_IRQ); + rtc_toggle_irq(s); + break; } s->hw.cmos_data[RTC_REG_B] =3D data; - rtc_timer_update(s); - check_update_timer(s); - alarm_timer_update(s); + if ( (data ^ orig) & RTC_SET ) + check_update_timer(s); + if ( (data ^ orig) & (RTC_24H | RTC_DM_BINARY | RTC_SET) ) + alarm_timer_update(s); break; case RTC_REG_C: case RTC_REG_D: @@ -453,7 +466,7 @@ static int rtc_ioport_write(void *opaque =20 static inline int to_bcd(RTCState *s, int a) { - if ( s->hw.cmos_data[RTC_REG_B] & 0x04 ) + if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY ) return a; else return ((a / 10) << 4) | (a % 10); @@ -461,7 +474,7 @@ static inline int to_bcd(RTCState *s, in =20 static inline int from_bcd(RTCState *s, int a) { - if ( s->hw.cmos_data[RTC_REG_B] & 0x04 ) + if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY ) return a; else return ((a >> 4) * 10) + (a & 0x0f); @@ -469,12 +482,14 @@ static inline int from_bcd(RTCState *s,=20 =20 /* Hours in 12 hour mode are in 1-12 range, not 0-11. * So we need convert it before using it*/ -static inline int convert_hour(RTCState *s, int hour) +static inline int convert_hour(RTCState *s, int raw) { + int hour =3D from_bcd(s, raw & 0x7f); + if (!(s->hw.cmos_data[RTC_REG_B] & RTC_24H)) { hour %=3D 12; - if (s->hw.cmos_data[RTC_HOURS] & 0x80) + if (raw & 0x80) hour +=3D 12; } return hour; @@ -493,8 +508,7 @@ static void rtc_set_time(RTCState *s) =20 tm->tm_sec =3D from_bcd(s, s->hw.cmos_data[RTC_SECONDS]); tm->tm_min =3D from_bcd(s, s->hw.cmos_data[RTC_MINUTES]); - tm->tm_hour =3D from_bcd(s, s->hw.cmos_data[RTC_HOURS] & 0x7f); - tm->tm_hour =3D convert_hour(s, tm->tm_hour); + tm->tm_hour =3D convert_hour(s, s->hw.cmos_data[RTC_HOURS]); tm->tm_wday =3D from_bcd(s, s->hw.cmos_data[RTC_DAY_OF_WEEK]); tm->tm_mday =3D from_bcd(s, s->hw.cmos_data[RTC_DAY_OF_MONTH]); tm->tm_mon =3D from_bcd(s, s->hw.cmos_data[RTC_MONTH]) - 1; --- a/xen/arch/x86/hvm/vpt.c +++ b/xen/arch/x86/hvm/vpt.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 #define mode_is(d, name) \ ((d)->arch.hvm_domain.params[HVM_PARAM_TIMER_MODE] =3D=3D HVMPTM_##nam= e) @@ -218,6 +219,7 @@ void pt_update_irq(struct vcpu *v) struct periodic_time *pt, *temp, *earliest_pt =3D NULL; uint64_t max_lag =3D -1ULL; int irq, is_lapic; + void *pt_priv; =20 spin_lock(&v->arch.hvm_vcpu.tm_lock); =20 @@ -251,13 +253,14 @@ void pt_update_irq(struct vcpu *v) earliest_pt->irq_issued =3D 1; irq =3D earliest_pt->irq; is_lapic =3D (earliest_pt->source =3D=3D PTSRC_lapic); + pt_priv =3D earliest_pt->priv; =20 spin_unlock(&v->arch.hvm_vcpu.tm_lock); =20 if ( is_lapic ) - { vlapic_set_irq(vcpu_vlapic(v), irq, 0); - } + else if ( irq =3D=3D RTC_IRQ && pt_priv ) + rtc_periodic_interrupt(pt_priv); else { hvm_isa_irq_deassert(v->domain, irq); --- a/xen/include/asm-x86/hvm/vpt.h +++ b/xen/include/asm-x86/hvm/vpt.h @@ -181,6 +181,7 @@ void rtc_migrate_timers(struct vcpu *v); void rtc_deinit(struct domain *d); void rtc_reset(struct domain *d); void rtc_update_clock(struct domain *d); +void rtc_periodic_interrupt(void *); =20 void pmtimer_init(struct vcpu *v); void pmtimer_deinit(struct domain *d); --=__PartECDD8518.0__= Content-Type: text/plain; name="x86-hvm-rtc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-hvm-rtc.patch" x86/HVM: assorted RTC emulation adjustments=0A=0A- don't call rtc_timer_upd= ate() on REG_A writes when the value didn't=0A change (doing the call = always was reported to cause wall clock time=0A lagging with the JVM = running on Windows)=0A- don't call rtc_timer_update() on REG_B writes at = all=0A- only call alarm_timer_update() on REG_B writes when relevant = bits=0A change=0A- only call check_update_timer() on REG_B writes when = SET changes=0A- instead properly handle AF and PF when the guest is not = also setting=0A AIE/PIE respectively (for UF this was already the case, = only a=0A comment was slightly inaccurate)=0A- raise the RTC IRQ not only = when UIE gets set while UF was already=0A set, but generalize this to = cover AIE and PIE as well=0A- properly mask off bit 7 when retrieving the = hour values in=0A alarm_timer_update(), and properly use RTC_HOURS_ALARM's= bit 7 when=0A converting from 12- to 24-hour value=0A- also handle the = two other possible clock bases=0A- use RTC_* names in a couple of places = where literal numbers were used=0A so far=0A=0ANote that this only = improves the situation described in the thread at=0Ahttp://lists.xen.org/ar= chives/html/xen-devel/2012-08/msg00664.html,=0Athere are still problems = with the emulation when invoked at a high rate=0Aas described there.=0A=0AS= igned-off-by: Jan Beulich =0A---=0Av2: Small adjustment = to the pt_update_irq() change, avoiding to call=0A the RTC code for a = HPET event (which also may pass 8 [aka RTC_IRQ]=0A as create_periodic_ti= me()'s "irq" argument.=0A=0A--- a/xen/arch/x86/hvm/rtc.c=0A+++ b/xen/arch/x= 86/hvm/rtc.c=0A@@ -50,11 +50,24 @@ static void rtc_set_time(RTCState = *s);=0A static inline int from_bcd(RTCState *s, int a);=0A static inline = int convert_hour(RTCState *s, int hour);=0A =0A-static void rtc_periodic_cb= (struct vcpu *v, void *opaque)=0A+static void rtc_toggle_irq(RTCState = *s)=0A+{=0A+ struct domain *d =3D vrtc_domain(s);=0A+=0A+ ASSERT(spin= _is_locked(&s->lock));=0A+ s->hw.cmos_data[RTC_REG_C] |=3D RTC_IRQF;=0A+= hvm_isa_irq_deassert(d, RTC_IRQ);=0A+ hvm_isa_irq_assert(d, = RTC_IRQ);=0A+}=0A+=0A+void rtc_periodic_interrupt(void *opaque)=0A {=0A = RTCState *s =3D opaque;=0A+=0A spin_lock(&s->lock);=0A- s->hw.cmos_= data[RTC_REG_C] |=3D 0xc0;=0A+ s->hw.cmos_data[RTC_REG_C] |=3D = RTC_PF;=0A+ if ( s->hw.cmos_data[RTC_REG_B] & RTC_PIE )=0A+ = rtc_toggle_irq(s);=0A spin_unlock(&s->lock);=0A }=0A =0A@@ -68,19 = +81,25 @@ static void rtc_timer_update(RTCState *s=0A ASSERT(spin_is_lo= cked(&s->lock));=0A =0A period_code =3D s->hw.cmos_data[RTC_REG_A] & = RTC_RATE_SELECT;=0A- if ( (period_code !=3D 0) && (s->hw.cmos_data[RTC_R= EG_B] & RTC_PIE) )=0A+ switch ( s->hw.cmos_data[RTC_REG_A] & RTC_DIV_CTL= )=0A {=0A- if ( period_code <=3D 2 )=0A+ case RTC_REF_CLCK_3= 2KHZ:=0A+ if ( (period_code !=3D 0) && (period_code <=3D 2) )=0A = period_code +=3D 7;=0A-=0A- period =3D 1 << (period_code - = 1); /* period in 32 Khz cycles */=0A- period =3D DIV_ROUND((period = * 1000000000ULL), 32768); /* period in ns */=0A- create_periodic_tim= e(v, &s->pt, period, period, RTC_IRQ,=0A- = rtc_periodic_cb, s);=0A- }=0A- else=0A- {=0A+ /* fall = through */=0A+ case RTC_REF_CLCK_1MHZ:=0A+ case RTC_REF_CLCK_4MHZ:=0A= + if ( period_code !=3D 0 )=0A+ {=0A+ period =3D = 1 << (period_code - 1); /* period in 32 Khz cycles */=0A+ = period =3D DIV_ROUND(period * 1000000000ULL, 32768); /* in ns */=0A+ = create_periodic_time(v, &s->pt, period, period, RTC_IRQ, NULL, = s);=0A+ break;=0A+ }=0A+ /* fall through */=0A+ = default:=0A destroy_periodic_time(&s->pt);=0A+ break;=0A = }=0A }=0A =0A@@ -102,7 +121,7 @@ static void check_update_timer(RTCState = =0A guest_usec =3D get_localtime_us(d) % USEC_PER_SEC;=0A = if (guest_usec >=3D (USEC_PER_SEC - 244))=0A {=0A- /* = RTC is in update cycle when enabling UIE */=0A+ /* RTC is in = update cycle */=0A s->hw.cmos_data[RTC_REG_A] |=3D RTC_UIP;=0A = next_update_time =3D (USEC_PER_SEC - guest_usec) * NS_PER_USEC;= =0A expire_time =3D NOW() + next_update_time;=0A@@ -144,7 = +163,6 @@ static void rtc_update_timer(void *opaqu=0A static void = rtc_update_timer2(void *opaque)=0A {=0A RTCState *s =3D opaque;=0A- = struct domain *d =3D vrtc_domain(s);=0A =0A spin_lock(&s->lock);=0A = if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET))=0A@@ -152,11 +170,7 @@ = static void rtc_update_timer2(void *opaq=0A s->hw.cmos_data[RTC_REG= _C] |=3D RTC_UF;=0A s->hw.cmos_data[RTC_REG_A] &=3D ~RTC_UIP;=0A = if ((s->hw.cmos_data[RTC_REG_B] & RTC_UIE))=0A- {=0A- = s->hw.cmos_data[RTC_REG_C] |=3D RTC_IRQF;=0A- hvm_isa_irq_dea= ssert(d, RTC_IRQ);=0A- hvm_isa_irq_assert(d, RTC_IRQ);=0A- = }=0A+ rtc_toggle_irq(s);=0A check_update_timer(s);=0A = }=0A spin_unlock(&s->lock);=0A@@ -175,21 +189,18 @@ static void = alarm_timer_update(RTCState =0A =0A stop_timer(&s->alarm_timer);=0A = =0A- if ((s->hw.cmos_data[RTC_REG_B] & RTC_AIE) &&=0A- = !(s->hw.cmos_data[RTC_REG_B] & RTC_SET))=0A+ if ( !(s->hw.cmos_data[RTC_= REG_B] & RTC_SET) )=0A {=0A s->current_tm =3D gmtime(get_localt= ime(d));=0A rtc_copy_date(s);=0A =0A alarm_sec =3D = from_bcd(s, s->hw.cmos_data[RTC_SECONDS_ALARM]);=0A alarm_min =3D = from_bcd(s, s->hw.cmos_data[RTC_MINUTES_ALARM]);=0A- alarm_hour =3D = from_bcd(s, s->hw.cmos_data[RTC_HOURS_ALARM]);=0A- alarm_hour =3D = convert_hour(s, alarm_hour);=0A+ alarm_hour =3D convert_hour(s, = s->hw.cmos_data[RTC_HOURS_ALARM]);=0A =0A cur_sec =3D from_bcd(s, = s->hw.cmos_data[RTC_SECONDS]);=0A cur_min =3D from_bcd(s, = s->hw.cmos_data[RTC_MINUTES]);=0A- cur_hour =3D from_bcd(s, = s->hw.cmos_data[RTC_HOURS]);=0A- cur_hour =3D convert_hour(s, = cur_hour);=0A+ cur_hour =3D convert_hour(s, s->hw.cmos_data[RTC_HOUR= S]);=0A =0A next_update_time =3D USEC_PER_SEC - (get_localtime_us(d= ) % USEC_PER_SEC);=0A next_update_time =3D next_update_time * = NS_PER_USEC + NOW();=0A@@ -343,7 +354,6 @@ static void alarm_timer_update(R= TCState =0A static void rtc_alarm_cb(void *opaque)=0A {=0A RTCState *s = =3D opaque;=0A- struct domain *d =3D vrtc_domain(s);=0A =0A = spin_lock(&s->lock);=0A if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET))=0A= @@ -351,11 +361,7 @@ static void rtc_alarm_cb(void *opaque)=0A = s->hw.cmos_data[RTC_REG_C] |=3D RTC_AF;=0A /* alarm interrupt = */=0A if (s->hw.cmos_data[RTC_REG_B] & RTC_AIE)=0A- {=0A- = s->hw.cmos_data[RTC_REG_C] |=3D RTC_IRQF;=0A- = hvm_isa_irq_deassert(d, RTC_IRQ);=0A- hvm_isa_irq_assert(d, = RTC_IRQ);=0A- }=0A+ rtc_toggle_irq(s);=0A = alarm_timer_update(s);=0A }=0A spin_unlock(&s->lock);=0A@@ -365,6 = +371,7 @@ static int rtc_ioport_write(void *opaque=0A {=0A RTCState *s = =3D opaque;=0A struct domain *d =3D vrtc_domain(s);=0A+ uint32_t = orig, mask;=0A =0A spin_lock(&s->lock);=0A =0A@@ -382,6 +389,7 @@ = static int rtc_ioport_write(void *opaque=0A return 0;=0A }=0A = =0A+ orig =3D s->hw.cmos_data[s->hw.cmos_index];=0A switch ( = s->hw.cmos_index )=0A {=0A case RTC_SECONDS_ALARM:=0A@@ -405,9 = +413,9 @@ static int rtc_ioport_write(void *opaque=0A break;=0A = case RTC_REG_A:=0A /* UIP bit is read only */=0A- = s->hw.cmos_data[RTC_REG_A] =3D (data & ~RTC_UIP) |=0A- = (s->hw.cmos_data[RTC_REG_A] & RTC_UIP);=0A- rtc_timer_update(s);=0A+= s->hw.cmos_data[RTC_REG_A] =3D (data & ~RTC_UIP) | (orig & = RTC_UIP);=0A+ if ( (data ^ orig) & (RTC_RATE_SELECT | RTC_DIV_CTL) = )=0A+ rtc_timer_update(s);=0A break;=0A case = RTC_REG_B:=0A if ( data & RTC_SET )=0A@@ -415,7 +423,7 @@ static = int rtc_ioport_write(void *opaque=0A /* set mode: reset UIP = mode */=0A s->hw.cmos_data[RTC_REG_A] &=3D ~RTC_UIP;=0A = /* adjust cmos before stopping */=0A- if (!(s->hw.cmos_data= [RTC_REG_B] & RTC_SET))=0A+ if (!(orig & RTC_SET))=0A = {=0A s->current_tm =3D gmtime(get_localtime(d));=0A = rtc_copy_date(s);=0A@@ -424,21 +432,26 @@ static int rtc_ioport_= write(void *opaque=0A else=0A {=0A /* if = disabling set mode, update the time */=0A- if ( s->hw.cmos_data[= RTC_REG_B] & RTC_SET )=0A+ if ( orig & RTC_SET )=0A = rtc_set_time(s);=0A }=0A- /* if the interrupt is = already set when the interrupt become=0A- * enabled, raise an = interrupt immediately*/=0A- if ((data & RTC_UIE) && !(s->hw.cmos_dat= a[RTC_REG_B] & RTC_UIE))=0A- if (s->hw.cmos_data[RTC_REG_C] & = RTC_UF)=0A+ /*=0A+ * If the interrupt is already set when = the interrupt becomes=0A+ * enabled, raise an interrupt immediately= .=0A+ * NB: RTC_{A,P,U}IE =3D=3D RTC_{A,P,U}F respectively.=0A+ = */=0A+ for ( mask =3D RTC_UIE; mask <=3D RTC_PIE; mask <<=3D 1 = )=0A+ if ( (data & mask) && !(orig & mask) &&=0A+ = (s->hw.cmos_data[RTC_REG_C] & mask) )=0A {=0A- = hvm_isa_irq_deassert(d, RTC_IRQ);=0A- hvm_isa_irq_assert(d,= RTC_IRQ);=0A+ rtc_toggle_irq(s);=0A+ = break;=0A }=0A s->hw.cmos_data[RTC_REG_B] =3D = data;=0A- rtc_timer_update(s);=0A- check_update_timer(s);=0A-= alarm_timer_update(s);=0A+ if ( (data ^ orig) & RTC_SET = )=0A+ check_update_timer(s);=0A+ if ( (data ^ orig) & = (RTC_24H | RTC_DM_BINARY | RTC_SET) )=0A+ alarm_timer_update(s);= =0A break;=0A case RTC_REG_C:=0A case RTC_REG_D:=0A@@ = -453,7 +466,7 @@ static int rtc_ioport_write(void *opaque=0A =0A static = inline int to_bcd(RTCState *s, int a)=0A {=0A- if ( s->hw.cmos_data[RTC_= REG_B] & 0x04 )=0A+ if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY = )=0A return a;=0A else=0A return ((a / 10) << 4) | (a = % 10);=0A@@ -461,7 +474,7 @@ static inline int to_bcd(RTCState *s, in=0A = =0A static inline int from_bcd(RTCState *s, int a)=0A {=0A- if ( = s->hw.cmos_data[RTC_REG_B] & 0x04 )=0A+ if ( s->hw.cmos_data[RTC_REG_B] = & RTC_DM_BINARY )=0A return a;=0A else=0A return ((a = >> 4) * 10) + (a & 0x0f);=0A@@ -469,12 +482,14 @@ static inline int = from_bcd(RTCState *s, =0A =0A /* Hours in 12 hour mode are in 1-12 range, = not 0-11.=0A * So we need convert it before using it*/=0A-static inline = int convert_hour(RTCState *s, int hour)=0A+static inline int convert_hour(R= TCState *s, int raw)=0A {=0A+ int hour =3D from_bcd(s, raw & 0x7f);=0A+= =0A if (!(s->hw.cmos_data[RTC_REG_B] & RTC_24H))=0A {=0A = hour %=3D 12;=0A- if (s->hw.cmos_data[RTC_HOURS] & 0x80)=0A+ = if (raw & 0x80)=0A hour +=3D 12;=0A }=0A return = hour;=0A@@ -493,8 +508,7 @@ static void rtc_set_time(RTCState *s)=0A = =0A tm->tm_sec =3D from_bcd(s, s->hw.cmos_data[RTC_SECONDS]);=0A = tm->tm_min =3D from_bcd(s, s->hw.cmos_data[RTC_MINUTES]);=0A- tm->tm_hou= r =3D from_bcd(s, s->hw.cmos_data[RTC_HOURS] & 0x7f);=0A- tm->tm_hour = =3D convert_hour(s, tm->tm_hour);=0A+ tm->tm_hour =3D convert_hour(s, = s->hw.cmos_data[RTC_HOURS]);=0A tm->tm_wday =3D from_bcd(s, s->hw.cmos_= data[RTC_DAY_OF_WEEK]);=0A tm->tm_mday =3D from_bcd(s, s->hw.cmos_data[= RTC_DAY_OF_MONTH]);=0A tm->tm_mon =3D from_bcd(s, s->hw.cmos_data[RTC_M= ONTH]) - 1;=0A--- a/xen/arch/x86/hvm/vpt.c=0A+++ b/xen/arch/x86/hvm/vpt.c= =0A@@ -22,6 +22,7 @@=0A #include =0A #include = =0A #include =0A+#include =0A =0A #define = mode_is(d, name) \=0A ((d)->arch.hvm_domain.params[HVM_PARAM_TIMER_MODE= ] =3D=3D HVMPTM_##name)=0A@@ -218,6 +219,7 @@ void pt_update_irq(struct = vcpu *v)=0A struct periodic_time *pt, *temp, *earliest_pt =3D NULL;=0A = uint64_t max_lag =3D -1ULL;=0A int irq, is_lapic;=0A+ void = *pt_priv;=0A =0A spin_lock(&v->arch.hvm_vcpu.tm_lock);=0A =0A@@ = -251,13 +253,14 @@ void pt_update_irq(struct vcpu *v)=0A earliest_pt->i= rq_issued =3D 1;=0A irq =3D earliest_pt->irq;=0A is_lapic =3D = (earliest_pt->source =3D=3D PTSRC_lapic);=0A+ pt_priv =3D earliest_pt->p= riv;=0A =0A spin_unlock(&v->arch.hvm_vcpu.tm_lock);=0A =0A if ( = is_lapic )=0A- {=0A vlapic_set_irq(vcpu_vlapic(v), irq, 0);=0A- = }=0A+ else if ( irq =3D=3D RTC_IRQ && pt_priv )=0A+ rtc_period= ic_interrupt(pt_priv);=0A else=0A {=0A hvm_isa_irq_deassert= (v->domain, irq);=0A--- a/xen/include/asm-x86/hvm/vpt.h=0A+++ b/xen/include= /asm-x86/hvm/vpt.h=0A@@ -181,6 +181,7 @@ void rtc_migrate_timers(struct = vcpu *v);=0A void rtc_deinit(struct domain *d);=0A void rtc_reset(struct = domain *d);=0A void rtc_update_clock(struct domain *d);=0A+void rtc_periodi= c_interrupt(void *);=0A =0A void pmtimer_init(struct vcpu *v);=0A void = pmtimer_deinit(struct domain *d);=0A --=__PartECDD8518.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartECDD8518.0__=--