Index: /trunk/src/VBox/HostDrivers/Support/linux/Makefile
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/linux/Makefile	(revision 30960)
+++ /trunk/src/VBox/HostDrivers/Support/linux/Makefile	(revision 30961)
@@ -123,4 +123,5 @@
 	common/string/strprintf.o \
 	common/string/strtonum.o \
+	common/time/time.o \
 	r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
 	generic/RTAssertShouldPanic-generic.o \
Index: /trunk/src/VBox/HostDrivers/Support/linux/files_vboxdrv
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/linux/files_vboxdrv	(revision 30960)
+++ /trunk/src/VBox/HostDrivers/Support/linux/files_vboxdrv	(revision 30961)
@@ -111,4 +111,5 @@
     ${PATH_ROOT}/src/VBox/Runtime/common/string/strprintf.cpp=>common/string/strprintf.c \
     ${PATH_ROOT}/src/VBox/Runtime/common/string/strtonum.cpp=>common/string/strtonum.c \
+    ${PATH_ROOT}/src/VBox/Runtime/common/time/time.cpp=>common/time/time.c \
     ${PATH_ROOT}/src/VBox/Runtime/include/internal/assert.h=>include/internal/assert.h \
     ${PATH_ROOT}/src/VBox/Runtime/include/internal/initterm.h=>include/internal/initterm.h \
@@ -119,4 +120,5 @@
     ${PATH_ROOT}/src/VBox/Runtime/include/internal/string.h=>include/internal/string.h \
     ${PATH_ROOT}/src/VBox/Runtime/include/internal/thread.h=>include/internal/thread.h \
+    ${PATH_ROOT}/src/VBox/Runtime/include/internal/time.h=>include/internal/time.h \
     ${PATH_ROOT}/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp=>generic/RTAssertShouldPanic-generic.c \
     ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp=>generic/RTLogWriteStdErr-stub-generic.c \
Index: /trunk/src/VBox/Runtime/common/log/log.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 30960)
+++ /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 30961)
@@ -2340,9 +2340,5 @@
                 if (pLogger->fFlags & RTLOGFLAGS_PREFIX_TS)
                 {
-#if defined(IN_RING3) || defined(IN_RC)
-                    uint64_t u64 = RTTimeNanoTS();
-#else
-                    uint64_t u64 = ~0;
-#endif
+                    uint64_t     u64    = RTTimeNanoTS();
                     int          iBase  = 16;
                     unsigned int fFlags = RTSTR_F_ZEROPAD;
@@ -2407,5 +2403,5 @@
                 if (pLogger->fFlags & RTLOGFLAGS_PREFIX_TIME)
                 {
-#ifdef IN_RING3
+#if defined(IN_RING3) || defined(IN_RING0)
                     RTTIMESPEC TimeSpec;
                     RTTIME Time;
Index: /trunk/src/VBox/Runtime/common/time/time.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/time/time.cpp	(revision 30960)
+++ /trunk/src/VBox/Runtime/common/time/time.cpp	(revision 30961)
@@ -257,4 +257,11 @@
 RTDECL(PRTTIME) RTTimeExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec)
 {
+    int64_t         i64Div;
+    int32_t         i32Div;
+    int32_t         i32Rem;
+    unsigned        iYear;
+    const uint16_t *paiDayOfYear;
+    int             iMonth;
+
     AssertMsg(VALID_PTR(pTime), ("%p\n", pTime));
     AssertMsg(VALID_PTR(pTimeSpec), ("%p\n", pTime));
@@ -263,7 +270,7 @@
      * The simple stuff first.
      */
-    pTime->fFlags        = RTTIME_FLAGS_TYPE_UTC;
-    int64_t i64Div = pTimeSpec->i64NanosecondsRelativeToUnixEpoch;
-    int32_t i32Rem = (int32_t)(i64Div % 1000000000);
+    pTime->fFlags = RTTIME_FLAGS_TYPE_UTC;
+    i64Div = pTimeSpec->i64NanosecondsRelativeToUnixEpoch;
+    i32Rem = (int32_t)(i64Div % 1000000000);
     i64Div /= 1000000000;
     if (i32Rem < 0)
@@ -285,5 +292,5 @@
 
     /* minute */
-    int32_t i32Div = (int32_t)i64Div;   /* 60,000,000,000 > 33bit, so 31bit suffices. */
+    i32Div = (int32_t)i64Div;   /* 60,000,000,000 > 33bit, so 31bit suffices. */
     i32Rem = i32Div % 60;
     i32Div /= 60;
@@ -314,5 +321,5 @@
      * generate a table and perform a simple two way search from the modulus 365 derived.
      */
-    unsigned iYear = OFF_YEAR_IDX_EPOCH + i32Div / 365;
+    iYear = OFF_YEAR_IDX_EPOCH + i32Div / 365;
     while (g_aoffYear[iYear + 1] <= i32Div)
         iYear++;
@@ -327,5 +334,4 @@
      * ensure that the index is matching or too small.
      */
-    const uint16_t *paiDayOfYear;
     if (rtTimeIsLeapYear(pTime->i32Year))
     {
@@ -338,5 +344,5 @@
         paiDayOfYear = &g_aiDayOfYear[0];
     }
-    int iMonth = i32Div / 32;
+    iMonth = i32Div / 32;
     i32Div++;
     while (paiDayOfYear[iMonth + 1] <= i32Div)
@@ -370,4 +376,8 @@
 RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime)
 {
+    int32_t     i32Days;
+    uint32_t    u32Secs;
+    int64_t     i64Nanos;
+
     /*
      * Validate input.
@@ -386,13 +396,13 @@
      * Do the conversion to nanoseconds.
      */
-    int32_t i32Days  = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]
-                     + pTime->u16YearDay - 1;
+    i32Days  = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]
+             + pTime->u16YearDay - 1;
     AssertMsgReturn(i32Days <= RTTIME_MAX_DAY && i32Days >= RTTIME_MIN_DAY, ("%RI32\n", i32Days), NULL);
 
-    uint32_t u32Secs = pTime->u8Second
-                     + pTime->u8Minute * 60
-                     + pTime->u8Hour   * 3600;
-    int64_t i64Nanos = (uint64_t)pTime->u32Nanosecond
-                     + u32Secs * UINT64_C(1000000000);
+    u32Secs  = pTime->u8Second
+             + pTime->u8Minute * 60
+             + pTime->u8Hour   * 3600;
+    i64Nanos = (uint64_t)pTime->u32Nanosecond
+             + u32Secs * UINT64_C(1000000000);
     AssertMsgReturn(i32Days != RTTIME_MAX_DAY || i64Nanos <= RTTIME_MAX_DAY_NANO, ("%RI64\n", i64Nanos), NULL);
     AssertMsgReturn(i32Days != RTTIME_MIN_DAY || i64Nanos >= RTTIME_MIN_DAY_NANO, ("%RI64\n", i64Nanos), NULL);
@@ -412,8 +422,13 @@
 PRTTIME rtTimeNormalizeInternal(PRTTIME pTime)
 {
+    unsigned    uSecond;
+    unsigned    uMinute;
+    unsigned    uHour;
+    bool        fLeapYear;
+
     /*
      * Fix the YearDay and Month/MonthDay.
      */
-    bool fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
+    fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
     if (!pTime->u16YearDay)
     {
@@ -469,4 +484,6 @@
             do
             {
+                uint16_t u16YearDay;
+
                 /* If you change one, zero the other to make clear what you mean. */
                 AssertBreak(pTime->u8Month <= 12);
@@ -474,8 +491,8 @@
                                                   ? g_acDaysInMonthsLeap[pTime->u8Month - 1]
                                                   : g_acDaysInMonths[pTime->u8Month - 1]));
-                uint16_t u16YearDay = pTime->u8MonthDay - 1
-                                    + (fLeapYear
-                                       ? g_aiDayOfYearLeap[pTime->u8Month - 1]
-                                       : g_aiDayOfYear[pTime->u8Month - 1]);
+                u16YearDay = pTime->u8MonthDay - 1
+                           + (fLeapYear
+                              ? g_aiDayOfYearLeap[pTime->u8Month - 1]
+                              : g_aiDayOfYear[pTime->u8Month - 1]);
                 AssertBreak(u16YearDay == pTime->u16YearDay);
                 fRecalc = false;
@@ -484,4 +501,6 @@
         if (fRecalc)
         {
+            const uint16_t *paiDayOfYear;
+
             /* overflow adjust YearDay */
             while (pTime->u16YearDay > (fLeapYear ? 366 : 365))
@@ -494,7 +513,7 @@
 
             /* calc Month and MonthDay */
-            const uint16_t *paiDayOfYear = fLeapYear
-                                         ? &g_aiDayOfYearLeap[0]
-                                         : &g_aiDayOfYear[0];
+            paiDayOfYear = fLeapYear
+                         ? &g_aiDayOfYearLeap[0]
+                         : &g_aiDayOfYear[0];
             pTime->u8Month = 1;
             while (pTime->u16YearDay > paiDayOfYear[pTime->u8Month])
@@ -509,7 +528,7 @@
      * Use unsigned int values internally to avoid overflows.
      */
-    unsigned uSecond = pTime->u8Second;
-    unsigned uMinute = pTime->u8Minute;
-    unsigned uHour   = pTime->u8Hour;
+    uSecond = pTime->u8Second;
+    uMinute = pTime->u8Minute;
+    uHour   = pTime->u8Hour;
 
     while (pTime->u32Nanosecond >= 1000000000)
@@ -668,12 +687,14 @@
 RTDECL(char *) RTTimeToString(PCRTTIME pTime, char *psz, size_t cb)
 {
+    size_t cch;
+
     /* (Default to UTC if not specified) */
     if (    (pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) == RTTIME_FLAGS_TYPE_LOCAL
         &&  pTime->offUTC)
     {
-        Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);
         int32_t offUTCHour   = pTime->offUTC / 60;
         int32_t offUTCMinute = pTime->offUTC % 60;
-        char chSign;
+        char    chSign;
+        Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);
         if (pTime->offUTC >= 0)
             chSign = '+';
@@ -684,9 +705,9 @@
             offUTCHour = -offUTCHour;
         }
-        size_t cch = RTStrPrintf(psz, cb,
-                                 "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02%02",
-                                 pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
-                                 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond,
-                                 chSign, offUTCHour, offUTCMinute);
+        cch = RTStrPrintf(psz, cb,
+                          "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02%02",
+                          pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
+                          pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond,
+                          chSign, offUTCHour, offUTCMinute);
         if (    cch <= 15
             ||  psz[cch - 5] != chSign)
@@ -695,7 +716,7 @@
     else
     {
-        size_t cch = RTStrPrintf(psz, cb, "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32Z",
-                                 pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
-                                 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond);
+        cch = RTStrPrintf(psz, cb, "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32Z",
+                          pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
+                          pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond);
         if (    cch <= 15
             ||  psz[cch - 1] != 'Z')
Index: /trunk/src/VBox/Runtime/common/time/timesup.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/time/timesup.cpp	(revision 30960)
+++ /trunk/src/VBox/Runtime/common/time/timesup.cpp	(revision 30961)
@@ -82,15 +82,15 @@
 static const PFNTIMENANOTSINTERNAL g_apfnWorkers[] =
 {
-#define RTTIMENANO_WORKER_DETECT        0
+# define RTTIMENANO_WORKER_DETECT        0
     rtTimeNanoTSInternalRediscover,
-#define RTTIMENANO_WORKER_SYNC_CPUID    1
+# define RTTIMENANO_WORKER_SYNC_CPUID    1
     RTTimeNanoTSLegacySync,
-#define RTTIMENANO_WORKER_ASYNC_CPUID   2
+# define RTTIMENANO_WORKER_ASYNC_CPUID   2
     RTTimeNanoTSLegacyAsync,
-#define RTTIMENANO_WORKER_SYNC_LFENCE   3
+# define RTTIMENANO_WORKER_SYNC_LFENCE   3
     RTTimeNanoTSLFenceSync,
-#define RTTIMENANO_WORKER_ASYNC_LFENCE  4
+# define RTTIMENANO_WORKER_ASYNC_LFENCE  4
     RTTimeNanoTSLFenceAsync,
-#define RTTIMENANO_WORKER_FALLBACK      5
+# define RTTIMENANO_WORKER_FALLBACK      5
     rtTimeNanoTSInternalFallback,
 };
@@ -128,9 +128,9 @@
         return rtTimeNanoTSInternalRediscover(pData);
     NOREF(pData);
-#if defined(IN_RING3) /** @todo Add ring-0 RTTimeSystemNanoTS to all hosts. */
+# ifndef IN_RC
     return RTTimeSystemNanoTS();
-#else
+# else
     return 0;
-#endif
+# endif
 }
 
