Index: /trunk/src/VBox/VMM/IOM.cpp
===================================================================
--- /trunk/src/VBox/VMM/IOM.cpp	(revision 29435)
+++ /trunk/src/VBox/VMM/IOM.cpp	(revision 29436)
@@ -466,17 +466,11 @@
         if (RTAvloGCPhysInsert(&pVM->iom.s.pTreesR3->MMIOStatTree, &pStats->Core))
         {
-            /* register the statistics counters. */
-            rc = STAMR3RegisterF(pVM, &pStats->ReadR3,      STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, pszDesc, "/IOM/MMIO/%RGp-Read-R3", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->WriteR3,     STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, pszDesc, "/IOM/MMIO/%RGp-Write-R3", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->ReadRZ,      STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, pszDesc, "/IOM/MMIO/%RGp-Read-RZ", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->WriteRZ,     STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, pszDesc, "/IOM/MMIO/%RGp-Write-RZ", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->ReadRZToR3,  STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, pszDesc, "/IOM/MMIO/%RGp-Read-RZtoR3", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->WriteRZToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, pszDesc, "/IOM/MMIO/%RGp-Write-RZtoR3", GCPhys); AssertRC(rc);
-
-            /* Profiling */
-            rc = STAMR3RegisterF(pVM, &pStats->ProfReadR3,  STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp-Read-R3/Prof", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->ProfWriteR3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp-Write-R3/Prof", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->ProfReadRZ,  STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp-Read-RZ/Prof", GCPhys); AssertRC(rc);
-            rc = STAMR3RegisterF(pVM, &pStats->ProfWriteRZ, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp-Write-RZ/Prof", GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->Accesses,    STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,     pszDesc, "/IOM/MMIO/%RGp",              GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->ProfReadR3,  STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp/Read-R3",      GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->ProfWriteR3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp/Write-R3",     GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->ProfReadRZ,  STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp/Read-RZ",      GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->ProfWriteRZ, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, pszDesc, "/IOM/MMIO/%RGp/Write-RZ",     GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->ReadRZToR3,  STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,     pszDesc, "/IOM/MMIO/%RGp/Read-RZtoR3",  GCPhys); AssertRC(rc);
+            rc = STAMR3RegisterF(pVM, &pStats->WriteRZToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,     pszDesc, "/IOM/MMIO/%RGp/Write-RZtoR3", GCPhys); AssertRC(rc);
 
             return pStats;
Index: /trunk/src/VBox/VMM/IOMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/IOMInternal.h	(revision 29435)
+++ /trunk/src/VBox/VMM/IOMInternal.h	(revision 29436)
@@ -103,29 +103,23 @@
     AVLOGCPHYSNODECORE          Core;
 
-    /** Number of reads to this address from R3. */
-    STAMCOUNTER                 ReadR3;
+    /** Number of accesses (subtract ReadRZToR3 and WriteRZToR3 to get the right
+     *  number). */
+    STAMCOUNTER                 Accesses;
+
     /** Profiling read handler overhead in R3. */
-    STAMPROFILEADV              ProfReadR3;
-
-    /** Number of writes to this address from R3. */
-    STAMCOUNTER                 WriteR3;
+    STAMPROFILE                 ProfReadR3;
     /** Profiling write handler overhead in R3. */
-    STAMPROFILEADV              ProfWriteR3;
-
-    /** Number of reads to this address from R0/RC. */
-    STAMCOUNTER                 ReadRZ;
-    /** Profiling read handler overhead in R0/RC. */
-    STAMPROFILEADV              ProfReadRZ;
+    STAMPROFILE                 ProfWriteR3;
+    /** Counting and profiling reads in R0/RC. */
+    STAMPROFILE                 ProfReadRZ;
+    /** Counting and profiling writes in R0/RC. */
+    STAMPROFILE                 ProfWriteRZ;
+
     /** Number of reads to this address from R0/RC which was serviced in R3. */
     STAMCOUNTER                 ReadRZToR3;
-
-    /** Number of writes to this address from R0/RC. */
-    STAMCOUNTER                 WriteRZ;
-    /** Profiling write handler overhead in R0/RC. */
-    STAMPROFILEADV              ProfWriteRZ;
     /** Number of writes to this address from R0/RC which was serviced in R3. */
     STAMCOUNTER                 WriteRZToR3;
 } IOMMMIOSTATS;
-AssertCompileMemberAlignment(IOMMMIOSTATS, ReadR3, 8);
+AssertCompileMemberAlignment(IOMMMIOSTATS, Accesses, 8);
 /** Pointer to I/O port statistics. */
 typedef IOMMMIOSTATS *PIOMMMIOSTATS;
Index: /trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp	(revision 29435)
+++ /trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp	(revision 29436)
@@ -82,11 +82,12 @@
 #endif
 
+    STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
     int rc;
     if (RT_LIKELY(pRange->CTX_SUFF(pfnWriteCallback)))
-        rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhysFault, (void *)pvData, cb); /* @todo fix const!! */
+        rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhysFault, (void *)pvData, cb); /** @todo fix const!! */
     else
         rc = VINF_SUCCESS;
-    if (rc != VINF_IOM_HC_MMIO_WRITE)
-        STAM_COUNTER_INC(&pStats->CTX_SUFF_Z(Write));
+    STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
+    STAM_COUNTER_INC(&pStats->Accesses);
     return rc;
 }
@@ -103,4 +104,5 @@
 #endif
 
+    STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfRead), a);
     int rc;
     if (RT_LIKELY(pRange->CTX_SUFF(pfnReadCallback)))
@@ -137,6 +139,6 @@
         }
     }
-    if (rc != VINF_IOM_HC_MMIO_READ)
-        STAM_COUNTER_INC(&pStats->CTX_SUFF_Z(Read));
+    STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
+    STAM_COUNTER_INC(&pStats->Accesses);
     return rc;
 }
@@ -1089,10 +1091,8 @@
         : !pRange->CTX_SUFF(pfnReadCallback)  && pRange->pfnReadCallbackR3)
     {
-# ifdef VBOX_WITH_STATISTICS
         if (uErrorCode & X86_TRAP_PF_RW)
             STAM_COUNTER_INC(&pStats->CTX_MID_Z(Write,ToR3));
         else
             STAM_COUNTER_INC(&pStats->CTX_MID_Z(Read,ToR3));
-# endif
 
         STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
@@ -1369,5 +1369,7 @@
 # endif
     }
+    STAM_COUNTER_INC(&pStats->Accesses);
 #endif /* VBOX_WITH_STATISTICS */
+
     if (pRange->CTX_SUFF(pfnReadCallback))
     {
@@ -1375,16 +1377,18 @@
          * Perform the read and deal with the result.
          */
-#ifdef VBOX_WITH_STATISTICS
-        STAM_PROFILE_ADV_START(&pStats->CTX_SUFF_Z(ProfRead), a);
-#endif
+        STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfRead), a);
         rc = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys, pu32Value, (unsigned)cbValue);
-#ifdef VBOX_WITH_STATISTICS
-        STAM_PROFILE_ADV_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
-        if (rc != VINF_IOM_HC_MMIO_READ)
-            STAM_COUNTER_INC(&pStats->CTX_SUFF_Z(Read));
-#endif
+        STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
         switch (rc)
         {
             case VINF_SUCCESS:
+                Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
+                iomUnlock(pVM);
+                return rc;
+#ifndef IN_RING3
+            case VINF_IOM_HC_MMIO_READ:
+            case VINF_IOM_HC_MMIO_READ_WRITE:
+                STAM_COUNTER_INC(&pStats->CTX_MID_Z(Read,ToR3));
+#endif
             default:
                 Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
@@ -1431,7 +1435,6 @@
      * Lookup the ring-3 range.
      */
-#ifdef VBOX_WITH_STATISTICS
-    STAM_COUNTER_INC(&pStats->CTX_SUFF_Z(Read));
-#endif
+    STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfRead), a); /** @todo STAM_PROFILE_ADD_ZERO_PERIOD */
+    STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
     /* Unassigned memory; this is actually not supposed to happen. */
     switch (cbValue)
@@ -1492,4 +1495,5 @@
 # endif
     }
+    STAM_COUNTER_INC(&pStats->Accesses);
 #endif /* VBOX_WITH_STATISTICS */
 
@@ -1500,12 +1504,11 @@
     if (pRange->CTX_SUFF(pfnWriteCallback))
     {
-#ifdef VBOX_WITH_STATISTICS
-        STAM_PROFILE_ADV_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
-#endif
+        STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
         rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys, &u32Value, (unsigned)cbValue);
-#ifdef VBOX_WITH_STATISTICS
-        STAM_PROFILE_ADV_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
-        if (rc != VINF_IOM_HC_MMIO_WRITE)
-            STAM_COUNTER_INC(&pStats->CTX_SUFF_Z(Write));
+        STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
+#ifndef IN_RING3
+        if (    rc == VINF_IOM_HC_MMIO_WRITE
+            ||  rc == VINF_IOM_HC_MMIO_READ_WRITE)
+            STAM_COUNTER_INC(&pStats->CTX_MID_Z(Write,ToR3));
 #endif
         Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, rc));
@@ -1525,7 +1528,6 @@
      * No write handler, nothing to do.
      */
-#ifdef VBOX_WITH_STATISTICS
-    STAM_COUNTER_INC(&pStats->CTX_SUFF_Z(Write));
-#endif
+    STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
+    STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
     Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, VINF_SUCCESS));
     iomUnlock(pVM);
@@ -1558,7 +1560,5 @@
 VMMDECL(VBOXSTRICTRC) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer)
 {
-#ifdef VBOX_WITH_STATISTICS
     STAM_COUNTER_INC(&pVM->iom.s.StatInstIns);
-#endif
 
     /*
@@ -1721,7 +1721,5 @@
 VMMDECL(VBOXSTRICTRC) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer)
 {
-#ifdef VBOX_WITH_STATISTICS
     STAM_COUNTER_INC(&pVM->iom.s.StatInstOuts);
-#endif
 
     /*
Index: /trunk/src/VBox/VMM/testcase/tstVMStructRC.cpp
===================================================================
--- /trunk/src/VBox/VMM/testcase/tstVMStructRC.cpp	(revision 29435)
+++ /trunk/src/VBox/VMM/testcase/tstVMStructRC.cpp	(revision 29436)
@@ -183,5 +183,6 @@
 
     GEN_CHECK_SIZE(IOMMMIOSTATS);
-    GEN_CHECK_OFF(IOMMMIOSTATS, ReadR3);
+    GEN_CHECK_OFF(IOMMMIOSTATS, Accesses);
+    GEN_CHECK_OFF(IOMMMIOSTATS, WriteRZToR3);
 
     GEN_CHECK_SIZE(IOMIOPORTRANGER0);
