VirtualBox

Changeset 4230 in vbox for trunk/src/VBox/Runtime/r0drv/nt


Ignore:
Timestamp:
Aug 19, 2007 4:56:05 PM (17 years ago)
Author:
vboxsync
Message:

Ported time-r0drv to NT.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/nt/time-r0drv-nt.cpp

    r4228 r4230  
    11/* $Id$ */
    22/** @file
    3  * innotek Portable Runtime - Time, Ring-0 Driver, Darwin.
     3 * innotek Portable Runtime - Time, Ring-0 Driver, Nt.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 innotek GmbH
     7 * Copyright (C) 2007 innotek GmbH
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121*******************************************************************************/
    2222#define LOG_GROUP RTLOGGROUP_TIME
    23 #include "the-darwin-kernel.h"
     23#include "the-nt-kernel.h"
    2424#include <iprt/time.h>
    25 #include <iprt/asm.h>
    2625
    2726
    2827DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
    2928{
    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);
    3139
    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
    4842}
    4943
    5044
    51 /**
    52  * Gets the current nanosecond timestamp.
    53  *
    54  * @returns nanosecond timestamp.
    55  */
    5645RTDECL(uint64_t) RTTimeNanoTS(void)
    5746{
     
    6049
    6150
    62 /**
    63  * Gets the current millisecond timestamp.
    64  *
    65  * @returns millisecond timestamp.
    66  */
    6751RTDECL(uint64_t) RTTimeMilliTS(void)
    6852{
     
    7155
    7256
    73 /**
    74  * Gets the current nanosecond timestamp.
    75  *
    76  * This differs from RTTimeNanoTS in that it will use system APIs and not do any
    77  * resolution or performance optimizations.
    78  *
    79  * @returns nanosecond timestamp.
    80  */
    8157RTDECL(uint64_t) RTTimeSystemNanoTS(void)
    8258{
     
    8561
    8662
    87 /**
    88  * Gets the current millisecond timestamp.
    89  *
    90  * This differs from RTTimeNanoTS in that it will use system APIs and not do any
    91  * resolution or performance optimizations.
    92  *
    93  * @returns millisecond timestamp.
    94  */
    9563RTDECL(uint64_t) RTTimeSystemMilliTS(void)
    9664{
     
    9967
    10068
    101 /**
    102  * Gets the current system time.
    103  *
    104  * @returns pTime.
    105  * @param   pTime   Where to store the time.
    106  */
    10769RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
    10870{
    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);
    11382}
    11483
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette