Skip to contentSkip to conversation

x86/HVM: RTC periodic timer emulation adjustments

PATCH Superseded Jan Beulich 2 participants 3 messages Aug 31, 2012 – Sep 3, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86/HVM: RTC periodic timer emulation adjustments

- 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 when RTC_PIE didn't change

---
v3: Break out just this change from the previously submitted much
larger patch. The rest of that one is now planned to go in only after 4.2.

xen/arch/x86/hvm/rtc.c +7 -4
@@ -365,6 +365,7 @@ static int rtc_ioport_write(void *opaque
 {
     RTCState *s = opaque;
     struct domain *d = vrtc_domain(s);
+    uint32_t orig;
 
     spin_lock(&s->lock);
 
@@ -382,6 +383,7 @@ static int rtc_ioport_write(void *opaque
         return 0;
     }
 
+    orig = s->hw.cmos_data[s->hw.cmos_index];
     switch ( s->hw.cmos_index )
     {
     case RTC_SECONDS_ALARM:
@@ -405,9 +407,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] = (data & ~RTC_UIP) |
-            (s->hw.cmos_data[RTC_REG_A] & RTC_UIP);
-        rtc_timer_update(s);
+        s->hw.cmos_data[RTC_REG_A] = (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 )
@@ -436,7 +438,8 @@ static int rtc_ioport_write(void *opaque
                 hvm_isa_irq_assert(d, RTC_IRQ);
             }
         s->hw.cmos_data[RTC_REG_B] = data;
-        rtc_timer_update(s);
+        if ( (data ^ orig) & RTC_PIE )
+            rtc_timer_update(s);
         check_update_timer(s);
         alarm_timer_update(s);
         break;

x86/HVM: RTC periodic timer emulation adjustments

- 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 when RTC_PIE didn't change

---
v3: Break out just this change from the previously submitted much
larger patch. The rest of that one is now planned to go in only after 4.2.

xen/arch/x86/hvm/rtc.c +7 -4
@@ -365,6 +365,7 @@ static int rtc_ioport_write(void *opaque
 {
     RTCState *s = opaque;
     struct domain *d = vrtc_domain(s);
+    uint32_t orig;
 
     spin_lock(&s->lock);
 
@@ -382,6 +383,7 @@ static int rtc_ioport_write(void *opaque
         return 0;
     }
 
+    orig = s->hw.cmos_data[s->hw.cmos_index];
     switch ( s->hw.cmos_index )
     {
     case RTC_SECONDS_ALARM:
@@ -405,9 +407,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] = (data & ~RTC_UIP) |
-            (s->hw.cmos_data[RTC_REG_A] & RTC_UIP);
-        rtc_timer_update(s);
+        s->hw.cmos_data[RTC_REG_A] = (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 )
@@ -436,7 +438,8 @@ static int rtc_ioport_write(void *opaque
                 hvm_isa_irq_assert(d, RTC_IRQ);
             }
         s->hw.cmos_data[RTC_REG_B] = data;
-        rtc_timer_update(s);
+        if ( (data ^ orig) & RTC_PIE )
+            rtc_timer_update(s);
         check_update_timer(s);
         alarm_timer_update(s);
         break;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v3 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

- 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 when RTC_PIE didn't change

One comment below in-line.

Quoted 24 lines

---
v3: Break out just this change from the previously submitted much
larger patch. The rest of that one is now planned to go in only after 4.2.

xen/arch/x86/hvm/rtc.c +2 -0
@@ -365,6 +365,7 @@ static int rtc_ioport_write(void *opaque
 {
     RTCState *s = opaque;
     struct domain *d = vrtc_domain(s);
+    uint32_t orig;
 
     spin_lock(&s->lock);
 
@@ -382,6 +383,7 @@ static int rtc_ioport_write(void *opaque
         return 0;
     }
 
+    orig = s->hw.cmos_data[s->hw.cmos_index];
     switch ( s->hw.cmos_index )
     {
     case RTC_SECONDS_ALARM:

xen/arch/x86/hvm/rtc.c static int rtc_ioport_write(void *opaque · line 411

Quoted 8 lines
xen/arch/x86/hvm/rtc.c +2 -3
@@ -405,9 +407,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] = (data & ~RTC_UIP) |
-            (s->hw.cmos_data[RTC_REG_A] & RTC_UIP);
-        rtc_timer_update(s);
+        s->hw.cmos_data[RTC_REG_A] = (data & ~RTC_UIP) | (orig & RTC_UIP);
+        if ( (data ^ orig) & (RTC_RATE_SELECT | RTC_DIV_CTL) )

Please change to 'if ( (data ^ orig) & ~RTC_UIP )'. It is shorter and matches the style of the immediately preceding line.

Once you make this change:

-- Keir

Quoted 21 lines
xen/arch/x86/hvm/rtc.c +3 -1
+            rtc_timer_update(s);
         break;
     case RTC_REG_B:
         if ( data & RTC_SET )
@@ -436,7 +438,8 @@ static int rtc_ioport_write(void *opaque
                 hvm_isa_irq_assert(d, RTC_IRQ);
             }
         s->hw.cmos_data[RTC_REG_B] = data;
-        rtc_timer_update(s);
+        if ( (data ^ orig) & RTC_PIE )
+            rtc_timer_update(s);
         check_update_timer(s);
         alarm_timer_update(s);
         break;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Keir Fraser

xen/arch/x86/hvm/rtc.c static int rtc_ioport_write(void *opaque · line 411

Quoted 9 lines · Jan Beulich
xen/arch/x86/hvm/rtc.c +2 -3
@@ -405,9 +407,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] = (data & ~RTC_UIP) |
-            (s->hw.cmos_data[RTC_REG_A] & RTC_UIP);
-        rtc_timer_update(s);
+        s->hw.cmos_data[RTC_REG_A] = (data & ~RTC_UIP) | (orig & RTC_UIP);
+        if ( (data ^ orig) & (RTC_RATE_SELECT | RTC_DIV_CTL) )

Please change to 'if ( (data ^ orig) & ~RTC_UIP )'. It is shorter and matches the style of the immediately preceding line.

Quoted 2 lines

Once you make this change:

I made the change before committing, albeit I disagree - what we care about here are explicitly the two fields that the original version named. Their mask just accidentally happens to be the complement of RTC_UIP. Whereas in the lines above we specifically care about that one flag...

Jan