Index: trunk/src/VBox/HostDrivers/Support/SUPDrv.c
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPDrv.c	(revision 53444)
+++ trunk/src/VBox/HostDrivers/Support/SUPDrv.c	(revision 53458)
@@ -3965,4 +3965,47 @@
 
 /**
+ * Increase the timer freqency on hosts where this is possible (NT).
+ *
+ * The idea is that more interrupts is better for us... Also, it's better than
+ * we increase the timer frequence, because we might end up getting inaccuract
+ * callbacks if someone else does it.
+ *
+ * @param   pDevExt   Sets u32SystemTimerGranularityGrant if increased.
+ */
+static void supdrvGipRequestHigherTimerFrequencyFromSystem(PSUPDRVDEVEXT pDevExt)
+{
+    if (pDevExt->u32SystemTimerGranularityGrant == 0)
+    {
+        uint32_t u32SystemResolution;
+        if (   RT_SUCCESS_NP(RTTimerRequestSystemGranularity(  976563 /* 1024 HZ */, &u32SystemResolution))
+            || RT_SUCCESS_NP(RTTimerRequestSystemGranularity( 1000000 /* 1000 HZ */, &u32SystemResolution))
+            || RT_SUCCESS_NP(RTTimerRequestSystemGranularity( 1953125 /*  512 HZ */, &u32SystemResolution))
+            || RT_SUCCESS_NP(RTTimerRequestSystemGranularity( 2000000 /*  500 HZ */, &u32SystemResolution))
+           )
+        {
+            Assert(RTTimerGetSystemGranularity() <= u32SystemResolution);
+            pDevExt->u32SystemTimerGranularityGrant = u32SystemResolution;
+        }
+    }
+}
+
+
+/**
+ * Undoes supdrvGipRequestHigherTimerFrequencyFromSystem.
+ *
+ * @param   pDevExt     Clears u32SystemTimerGranularityGrant.
+ */
+static void supdrvGipReleaseHigherTimerFrequencyFromSystem(PSUPDRVDEVEXT pDevExt)
+{
+    if (pDevExt->u32SystemTimerGranularityGrant)
+    {
+        int rc2 = RTTimerReleaseSystemGranularity(pDevExt->u32SystemTimerGranularityGrant);
+        AssertRC(rc2);
+        pDevExt->u32SystemTimerGranularityGrant = 0;
+    }
+}
+
+
+/**
  * Maps the GIP into userspace and/or get the physical address of the GIP.
  *
@@ -4028,27 +4071,12 @@
                 PSUPGLOBALINFOPAGE pGipR0 = pDevExt->pGip;
                 uint64_t u64NanoTS;
-                uint32_t u32SystemResolution;
-                unsigned i;
 
                 LogFlow(("SUPR0GipMap: Resumes GIP updating\n"));
 
-                /*
-                 * Try bump up the system timer resolution.
-                 * The more interrupts the better...
-                 */
-                /** @todo On Windows, RTTimerRequestSystemGranularity() always succeeds, so
-                 *        whats the point of the remaining calls? */
-                if (   RT_SUCCESS_NP(RTTimerRequestSystemGranularity(  976563 /* 1024 HZ */, &u32SystemResolution))
-                    || RT_SUCCESS_NP(RTTimerRequestSystemGranularity( 1000000 /* 1000 HZ */, &u32SystemResolution))
-                    || RT_SUCCESS_NP(RTTimerRequestSystemGranularity( 1953125 /*  512 HZ */, &u32SystemResolution))
-                    || RT_SUCCESS_NP(RTTimerRequestSystemGranularity( 2000000 /*  500 HZ */, &u32SystemResolution))
-                   )
-                {
-                    Assert(RTTimerGetSystemGranularity() <= u32SystemResolution);
-                    pDevExt->u32SystemTimerGranularityGrant = u32SystemResolution;
-                }
+                supdrvGipRequestHigherTimerFrequencyFromSystem(pDevExt);
 
                 if (pGipR0->aCPUs[0].u32TransactionId != 2 /* not the first time */)
                 {
+                    unsigned i;
                     for (i = 0; i < pGipR0->cCpus; i++)
                         ASMAtomicUoWriteU32(&pGipR0->aCPUs[i].u32TransactionId,
@@ -4152,11 +4180,5 @@
             rc = RTTimerStop(pDevExt->pGipTimer); AssertRC(rc); rc = VINF_SUCCESS;
 #endif
-
-            if (pDevExt->u32SystemTimerGranularityGrant)
-            {
-                int rc2 = RTTimerReleaseSystemGranularity(pDevExt->u32SystemTimerGranularityGrant);
-                AssertRC(rc2);
-                pDevExt->u32SystemTimerGranularityGrant = 0;
-            }
+            supdrvGipReleaseHigherTimerFrequencyFromSystem(pDevExt);
         }
     }
@@ -6305,4 +6327,5 @@
      * Find a reasonable update interval and initialize the structure.
      */
+    supdrvGipRequestHigherTimerFrequencyFromSystem(pDevExt);
     /** @todo figure out why using a 100Ms interval upsets timekeeping in VMs.
      *        See @bugref{6710}. */
@@ -6390,4 +6413,6 @@
                              */
                             Log(("supdrvGipCreate: %u ns interval.\n", u32Interval));
+                            supdrvGipReleaseHigherTimerFrequencyFromSystem(pDevExt);
+
                             g_pSUPGlobalInfoPage = pGip;
                             if (pGip->u32Mode == SUPGIPMODE_INVARIANT_TSC)
@@ -6416,5 +6441,5 @@
         OSDBGPRINT(("supdrvGipCreate: supdrvTscDeltaInit failed. rc=%Rrc\n", rc));
 
-    supdrvGipDestroy(pDevExt);
+    supdrvGipDestroy(pDevExt); /* Releases timer frequency increase too. */
     return rc;
 }
@@ -6485,9 +6510,5 @@
      * if one actually succeeded and is still pending.
      */
-    if (pDevExt->u32SystemTimerGranularityGrant)
-    {
-        rc = RTTimerReleaseSystemGranularity(pDevExt->u32SystemTimerGranularityGrant); AssertRC(rc);
-        pDevExt->u32SystemTimerGranularityGrant = 0;
-    }
+    supdrvGipReleaseHigherTimerFrequencyFromSystem(pDevExt);
 }
 
