Changeset 70405 in vbox
- Timestamp:
- Jan 1, 2018 5:45:14 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/nt/nt.h
r70347 r70405 677 677 ULONG LangGenerationCount; /**< 0x3a4 */ 678 678 ULONGLONG Reserved4; /**< 0x3a8 */ 679 ULONGLONG volatile InterruptTimeBias; /**< 0x3b0 */ 679 ULONGLONG volatile InterruptTimeBias; /**< 0x3b0 - What QueryUnbiasedInterruptTimePrecise 680 * subtracts from interrupt time. */ 680 681 ULONGLONG volatile QpcBias; /**< 0x3b8 */ 681 682 ULONG volatile ActiveProcessorCount; /**< 0x3c0 */ … … 2813 2814 NTSYSAPI uint64_t NTAPI RtlGetSystemTimePrecise(VOID); 2814 2815 typedef uint64_t (NTAPI * PFNRTLGETSYSTEMTIMEPRECISE)(VOID); 2816 NTSYSAPI uint64_t NTAPI RtlGetInterruptTimePrecise(uint64_t *puPerfTime); 2817 typedef uint64_t (NTAPI * PFNRTLGETINTERRUPTTIMEPRECISE)(uint64_t *); 2818 NTSYSAPI BOOLEAN NTAPI RtlQueryUnbiasedInterruptTime(uint64_t *puInterruptTime); 2819 typedef BOOLEAN (NTAPI * PFNRTLQUERYUNBIASEDINTERRUPTTIME)(uint64_t *); 2815 2820 2816 2821 RT_C_DECLS_END -
trunk/src/VBox/Runtime/r3/win/time-win.cpp
r70402 r70405 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 30 30 *********************************************************************************************************************************/ 31 31 #define LOG_GROUP RTLOGGROUP_TIME 32 #include <iprt/ win/windows.h>32 #include <iprt/nt/nt-and-windows.h> 33 33 34 34 #include <iprt/time.h> … … 53 53 //#endif 54 54 55 56 #ifdef USE_INTERRUPT_TIME57 58 typedef struct _MY_KSYSTEM_TIME59 {60 ULONG LowPart;61 LONG High1Time;62 LONG High2Time;63 } MY_KSYSTEM_TIME;64 65 typedef struct _MY_KUSER_SHARED_DATA66 {67 ULONG TickCountLowDeprecated;68 ULONG TickCountMultiplier;69 volatile MY_KSYSTEM_TIME InterruptTime;70 /* The rest is not relevant. */71 } MY_KUSER_SHARED_DATA, *PMY_KUSER_SHARED_DATA;72 73 #endif /* USE_INTERRUPT_TIME */74 55 75 56 … … 112 93 /* 113 94 * Use interrupt time if we can (not possible on NT 3.1). 95 * Note! We cannot entirely depend on g_enmWinVer here as we're likely to 96 * get called before IPRT is initialized. Ditto g_hModNtDll. 114 97 */ 115 /** @todo use RtlGetInterruptTimePrecise if available (W10+). */ 116 117 static int volatile g_fCanUseUserSharedData = -1; 118 int fCanUseUserSharedData = g_fCanUseUserSharedData; 119 if (fCanUseUserSharedData != -1) 98 static PFNRTLGETINTERRUPTTIMEPRECISE s_pfnRtlGetInterruptTimePrecise = NULL; 99 static int volatile s_iCanUseUserSharedData = -1; 100 int iCanUseUserSharedData = s_iCanUseUserSharedData; 101 if (iCanUseUserSharedData != -1) 120 102 { /* likely */ } 121 103 else … … 123 105 /* We may be called before g_enmWinVer has been initialized. */ 124 106 if (g_enmWinVer != kRTWinOSType_UNKNOWN) 125 fCanUseUserSharedData = g_enmWinVer > kRTWinOSType_NT310;107 iCanUseUserSharedData = g_enmWinVer > kRTWinOSType_NT310; 126 108 else 127 109 { 128 110 DWORD dwVer = GetVersion(); 129 fCanUseUserSharedData = (dwVer & 0xff) != 3 || ((dwVer >> 8) & 0xff) >= 50;111 iCanUseUserSharedData = (dwVer & 0xff) != 3 || ((dwVer >> 8) & 0xff) >= 50; 130 112 } 131 g_fCanUseUserSharedData = fCanUseUserSharedData; 113 if (iCanUseUserSharedData != 0) 114 { 115 FARPROC pfn = GetProcAddress(g_hModNtDll ? g_hModNtDll : GetModuleHandleW(L"ntdll"), "RtlGetInterruptTimePrecise"); 116 if (pfn != NULL) 117 { 118 ASMAtomicWritePtr(&s_pfnRtlGetInterruptTimePrecise, pfn); 119 iCanUseUserSharedData = 42; 120 } 121 } 122 s_iCanUseUserSharedData = iCanUseUserSharedData; 132 123 } 133 124 134 if ( fCanUseUserSharedData != 0)125 if (iCanUseUserSharedData != 0) 135 126 { 136 PMY_KUSER_SHARED_DATA pUserSharedData = (PMY_KUSER_SHARED_DATA)(uintptr_t)0x7ffe0000;137 127 LARGE_INTEGER Time; 138 do128 if (iCanUseUserSharedData == 42) 139 129 { 140 Time.HighPart = pUserSharedData->InterruptTime.High1Time; 141 Time.LowPart = pUserSharedData->InterruptTime.LowPart; 142 } while (pUserSharedData->InterruptTime.High2Time != Time.HighPart); 130 uint64_t iIgnored; 131 Time.QuadPart = s_pfnRtlGetInterruptTimePrecise(&iIgnored); 132 } 133 else 134 { 135 PKUSER_SHARED_DATA pUserSharedData = (PKUSER_SHARED_DATA)MM_SHARED_USER_DATA_VA; 136 do 137 { 138 Time.HighPart = pUserSharedData->InterruptTime.High1Time; 139 Time.LowPart = pUserSharedData->InterruptTime.LowPart; 140 } while (pUserSharedData->InterruptTime.High2Time != Time.HighPart); 141 } 143 142 144 143 return (uint64_t)Time.QuadPart * 100; -
trunk/src/VBox/Runtime/testcase/tstTime-3.cpp
r69111 r70405 29 29 * Header Files * 30 30 *********************************************************************************************************************************/ 31 #ifdef RT_OS_WINDOWS32 # include <iprt/win/windows.h>33 34 #else /* posix */35 # include <sys/time.h>36 #endif37 38 31 #include <iprt/time.h> 39 32 #include <iprt/stream.h> … … 42 35 #include <iprt/thread.h> 43 36 #include <iprt/err.h> 44 45 46 DECLINLINE(uint64_t) OSNanoTS(void)47 {48 #ifdef RT_OS_WINDOWS49 uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */50 GetSystemTimeAsFileTime((LPFILETIME)&u64);51 return u64 * 100;52 53 #else /* posix */54 55 struct timeval tv;56 gettimeofday(&tv, NULL);57 return (uint64_t)tv.tv_sec * (uint64_t)(1000 * 1000 * 1000)58 + (uint64_t)(tv.tv_usec * 1000);59 #endif60 }61 37 62 38 … … 72 48 } 73 49 74 RTPrintf("tstTime-3: Testing difference between RTTimeNanoTS() and OS time...\n");50 RTPrintf("tstTime-3: Testing difference between RTTimeNanoTS() and RTTimeSystemNanoTS()...\n"); 75 51 76 52 for (int i = 1; i < argc; i++) … … 85 61 RTPrintf("tstTime-3: %d - %RU64 seconds period...\n", i, cSeconds); 86 62 87 RTTimeNanoTS(); OSNanoTS(); RTThreadSleep(1);63 RTTimeNanoTS(); RTTimeSystemNanoTS(); RTThreadSleep(1); 88 64 uint64_t u64RTStartTS = RTTimeNanoTS(); 89 uint64_t u64OSStartTS = OSNanoTS();65 uint64_t u64OSStartTS = RTTimeSystemNanoTS(); 90 66 91 67 RTThreadSleep(cSeconds * 1000); … … 103 79 return 0; 104 80 } 81
Note:
See TracChangeset
for help on using the changeset viewer.