Changeset 4230 in vbox for trunk/src/VBox/Runtime/r0drv/nt
- Timestamp:
- Aug 19, 2007 4:56:05 PM (17 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/time-r0drv-nt.cpp
r4228 r4230 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Time, Ring-0 Driver, Darwin.3 * innotek Portable Runtime - Time, Ring-0 Driver, Nt. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 200 6-2007 innotek GmbH7 * Copyright (C) 2007 innotek GmbH 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 *******************************************************************************/ 22 22 #define LOG_GROUP RTLOGGROUP_TIME 23 #include "the- darwin-kernel.h"23 #include "the-nt-kernel.h" 24 24 #include <iprt/time.h> 25 #include <iprt/asm.h>26 25 27 26 28 27 DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void) 29 28 { 30 static int8_t s_fSimple = -1; 29 #if 1 30 ULONGLONG InterruptTime = KeQueryInterruptTime(); 31 return (uint64_t)InterruptTime * 100; 32 #else 33 LARGE_INTEGER InterruptTime; 34 do 35 { 36 InterruptTime.HighPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.High1Time; 37 InterruptTime.LowPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.LowPart; 38 } while (((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.High2Time != InterruptTime.HighPart); 31 39 32 /* first call: check if life is simple or not. */ 33 if (s_fSimple < 0) 34 { 35 struct mach_timebase_info Info; 36 clock_timebase_info(&Info); 37 ASMAtomicXchgS8((int8_t * volatile)&s_fSimple, Info.denom == 1 && Info.numer == 1); 38 } 39 40 /* special case: absolute time is in nanoseconds */ 41 if (s_fSimple) 42 return mach_absolute_time(); 43 44 /* general case: let mach do the mult/div for us. */ 45 uint64_t u64; 46 absolutetime_to_nanoseconds(mach_absolute_time(), &u64); 47 return u64; 40 return (uint64_t)InterruptTime.QuadPart * 100; 41 #endif 48 42 } 49 43 50 44 51 /**52 * Gets the current nanosecond timestamp.53 *54 * @returns nanosecond timestamp.55 */56 45 RTDECL(uint64_t) RTTimeNanoTS(void) 57 46 { … … 60 49 61 50 62 /**63 * Gets the current millisecond timestamp.64 *65 * @returns millisecond timestamp.66 */67 51 RTDECL(uint64_t) RTTimeMilliTS(void) 68 52 { … … 71 55 72 56 73 /**74 * Gets the current nanosecond timestamp.75 *76 * This differs from RTTimeNanoTS in that it will use system APIs and not do any77 * resolution or performance optimizations.78 *79 * @returns nanosecond timestamp.80 */81 57 RTDECL(uint64_t) RTTimeSystemNanoTS(void) 82 58 { … … 85 61 86 62 87 /**88 * Gets the current millisecond timestamp.89 *90 * This differs from RTTimeNanoTS in that it will use system APIs and not do any91 * resolution or performance optimizations.92 *93 * @returns millisecond timestamp.94 */95 63 RTDECL(uint64_t) RTTimeSystemMilliTS(void) 96 64 { … … 99 67 100 68 101 /**102 * Gets the current system time.103 *104 * @returns pTime.105 * @param pTime Where to store the time.106 */107 69 RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime) 108 70 { 109 uint32_t u32Secs; 110 uint32_t u32Nanosecs; 111 clock_get_calendar_nanotime(&u32Secs, &u32Nanosecs); 112 return RTTimeSpecSetNano(pTime, (uint64_t)u32Secs * 1000000000 + u32Nanosecs); 71 LARGE_INTEGER SystemTime; 72 #if 1 73 KeQuerySystemTime(&SystemTime); 74 #else 75 do 76 { 77 SystemTime.HighPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.High1Time; 78 SystemTime.LowPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.LowPart; 79 } while (((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.High2Time != SystemTime.HighPart); 80 #endif 81 return RTTimeSpecSetNtTime(pTime, SystemTime.QuadPart); 113 82 } 114 83
Note:
See TracChangeset
for help on using the changeset viewer.