Index: /trunk/src/VBox/Devices/PC/DevPit-i8254.cpp
===================================================================
--- /trunk/src/VBox/Devices/PC/DevPit-i8254.cpp	(revision 20048)
+++ /trunk/src/VBox/Devices/PC/DevPit-i8254.cpp	(revision 20049)
@@ -162,5 +162,5 @@
 #ifdef IN_RING3
 PDMBOTHCBDECL(int) pitIOPortSpeakerWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
-static void pit_irq_timer_update(PITChannelState *s, uint64_t current_time);
+static void pit_irq_timer_update(PITChannelState *s, uint64_t current_time, uint64_t now);
 #endif
 __END_DECLS
@@ -287,6 +287,7 @@
         if (s->gate < val) {
             /* restart counting on rising edge */
+            Log(("pit_set_gate: restarting mode %d\n", s->mode));
             s->count_load_time = TMTimerGet(pTimer);
-            pit_irq_timer_update(s, s->count_load_time);
+            pit_irq_timer_update(s, s->count_load_time, s->count_load_time);
         }
         break;
@@ -295,6 +296,7 @@
         if (s->gate < val) {
             /* restart counting on rising edge */
+            Log(("pit_set_gate: restarting mode %d\n", s->mode));
             s->count_load_time = s->u64ReloadTS = TMTimerGet(pTimer);
-            pit_irq_timer_update(s, s->count_load_time);
+            pit_irq_timer_update(s, s->count_load_time, s->count_load_time);
         }
         /* XXX: disable/enable counting */
@@ -311,5 +313,5 @@
     s->count_load_time = s->u64ReloadTS = TMTimerGet(pTimer);
     s->count = val;
-    pit_irq_timer_update(s, s->count_load_time);
+    pit_irq_timer_update(s, s->count_load_time, s->count_load_time);
 
     /* log the new rate (ch 0 only). */
@@ -318,4 +320,7 @@
         LogRel(("PIT: mode=%d count=%#x (%u) - %d.%02d Hz (ch=0)\n",
                 s->mode, s->count, s->count, PIT_FREQ / s->count, (PIT_FREQ * 100 / s->count) % 100));
+    else
+        Log(("PIT: mode=%d count=%#x (%u) - %d.%02d Hz (ch=0)\n",
+             s->mode, s->count, s->count, PIT_FREQ / s->count, (PIT_FREQ * 100 / s->count) % 100));
 }
 
@@ -377,5 +382,5 @@
     }
     /* convert to timer units */
-    LogFlow(("PIT: next_time=%14RI64 %20RI64 mode=%#x count=%#06x\n", next_time,
+    LogFlow(("PIT: next_time=%'14RU64 %'20RU64 mode=%#x count=%#06x\n", next_time,
              ASMMultU64ByU32DivByU32(next_time, TMTimerGetFreq(pTimer), PIT_FREQ), s->mode, s->count));
     next_time = s->count_load_time + ASMMultU64ByU32DivByU32(next_time, TMTimerGetFreq(pTimer), PIT_FREQ);
@@ -387,7 +392,6 @@
 }
 
-static void pit_irq_timer_update(PITChannelState *s, uint64_t current_time)
-{
-    uint64_t now;
+static void pit_irq_timer_update(PITChannelState *s, uint64_t current_time, uint64_t now)
+{
     int64_t expire_time;
     int irq_level;
@@ -405,6 +409,4 @@
     if (irq_level)
         PDMDevHlpISASetIrq(pDevIns, s->irq, 0);
-    now = TMTimerGet(pTimer);
-    Log3(("pit_irq_timer_update: %lldns late\n", now - s->u64NextTS));
     if (irq_level)
     {
@@ -415,4 +417,5 @@
     if (expire_time != -1)
     {
+        Log3(("pit_irq_timer_update: next=%'RU64 now=%'RU64\n", expire_time, now));
         s->u64NextTS = expire_time;
         TMTimerSet(s->CTX_SUFF(pTimer), s->u64NextTS);
@@ -812,5 +815,6 @@
     PITChannelState *s = &pThis->channels[0];
     STAM_PROFILE_ADV_START(&s->CTX_SUFF(pPit)->StatPITHandler, a);
-    pit_irq_timer_update(s, s->next_transition_time);
+    Log(("pitTimer\n"));
+    pit_irq_timer_update(s, s->next_transition_time, TMTimerGet(pTimer));
     STAM_PROFILE_ADV_STOP(&s->CTX_SUFF(pPit)->StatPITHandler, a);
 }
