VirtualBox

Changeset 70405 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Jan 1, 2018 5:45:14 PM (7 years ago)
Author:
vboxsync
Message:

IPRT/time-win.cpp: Use RtlGetInterruptTimePrecise for RTTimeSystemNanoTS when available (based on RDTSC) and using KUSER_SHARED_DATA from nt.h instead of duplicating it and its address.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/time-win.cpp

    r70402 r70405  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030*********************************************************************************************************************************/
    3131#define LOG_GROUP RTLOGGROUP_TIME
    32 #include <iprt/win/windows.h>
     32#include <iprt/nt/nt-and-windows.h>
    3333
    3434#include <iprt/time.h>
     
    5353//#endif
    5454
    55 
    56 #ifdef USE_INTERRUPT_TIME
    57 
    58 typedef struct _MY_KSYSTEM_TIME
    59 {
    60     ULONG LowPart;
    61     LONG High1Time;
    62     LONG High2Time;
    63 } MY_KSYSTEM_TIME;
    64 
    65 typedef struct _MY_KUSER_SHARED_DATA
    66 {
    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 */
    7455
    7556
     
    11293    /*
    11394     * 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.
    11497     */
    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)
    120102    { /* likely */ }
    121103    else
     
    123105        /* We may be called before g_enmWinVer has been initialized. */
    124106        if (g_enmWinVer != kRTWinOSType_UNKNOWN)
    125             fCanUseUserSharedData = g_enmWinVer > kRTWinOSType_NT310;
     107            iCanUseUserSharedData = g_enmWinVer > kRTWinOSType_NT310;
    126108        else
    127109        {
    128110            DWORD dwVer = GetVersion();
    129             fCanUseUserSharedData = (dwVer & 0xff) != 3 || ((dwVer >> 8) & 0xff) >= 50;
     111            iCanUseUserSharedData = (dwVer & 0xff) != 3 || ((dwVer >> 8) & 0xff) >= 50;
    130112        }
    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;
    132123    }
    133124
    134     if (fCanUseUserSharedData != 0)
     125    if (iCanUseUserSharedData != 0)
    135126    {
    136         PMY_KUSER_SHARED_DATA pUserSharedData = (PMY_KUSER_SHARED_DATA)(uintptr_t)0x7ffe0000;
    137127        LARGE_INTEGER Time;
    138         do
     128        if (iCanUseUserSharedData == 42)
    139129        {
    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        }
    143142
    144143        return (uint64_t)Time.QuadPart * 100;
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