VirtualBox

Ignore:
Timestamp:
Aug 13, 2009 1:39:07 PM (15 years ago)
Author:
vboxsync
Message:

Grab TSC as quickly as possible; minor accuracy improvement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r22224 r22236  
    49594959    RTCCUINTREG     fOldFlags = ASMIntDisableFlags(); /* No interruptions please (real problem on S10). */
    49604960    PSUPDRVDEVEXT   pDevExt   = (PSUPDRVDEVEXT)pvUser;
    4961 
    4962     supdrvGipUpdate(pDevExt->pGip, RTTimeSystemNanoTS());
     4961    uint64_t        u64TSC    = ASMReadTSC();
     4962    uint64_t        NanoTS    = RTTimeSystemNanoTS();
     4963
     4964    supdrvGipUpdate(pDevExt->pGip, NanoTS, u64TSC);
    49634965
    49644966    ASMSetFlags(fOldFlags);
     
    49764978    PSUPDRVDEVEXT   pDevExt   = (PSUPDRVDEVEXT)pvUser;
    49774979    RTCPUID         idCpu     = RTMpCpuId();
     4980    uint64_t        u64TSC    = ASMReadTSC();
    49784981    uint64_t        NanoTS    = RTTimeSystemNanoTS();
    49794982
    49804983    /** @todo reset the transaction number and whatnot when iTick == 1. */
    49814984    if (pDevExt->idGipMaster == idCpu)
    4982         supdrvGipUpdate(pDevExt->pGip, NanoTS);
     4985        supdrvGipUpdate(pDevExt->pGip, NanoTS, u64TSC);
    49834986    else
    4984         supdrvGipUpdatePerCpu(pDevExt->pGip, NanoTS, ASMGetApicId());
     4987        supdrvGipUpdatePerCpu(pDevExt->pGip, NanoTS, u64TSC, ASMGetApicId());
    49854988
    49864989    ASMSetFlags(fOldFlags);
     
    52785281 * @param   pGipCpu         Pointer to the per cpu data.
    52795282 * @param   u64NanoTS       The current time stamp.
    5280  */
    5281 static void supdrvGipDoUpdateCpu(PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu, uint64_t u64NanoTS)
    5282 {
    5283     uint64_t    u64TSC;
     5283 * @param   u64TSC          The current TSC.
     5284 */
     5285static void supdrvGipDoUpdateCpu(PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu, uint64_t u64NanoTS, uint64_t u64TSC)
     5286{
    52845287    uint64_t    u64TSCDelta;
    52855288    uint32_t    u32UpdateIntervalTSC;
     
    52885291    uint64_t    u64CpuHz;
    52895292
     5293    /* Delta between this and the previous update. */
     5294    pGipCpu->u32UpdateIntervalNS = (uint32_t)(u64NanoTS - pGipCpu->u64NanoTS);
     5295
    52905296    /*
    52915297     * Update the NanoTS.
     
    52975303     */
    52985304    /** @todo validate the NanoTS delta, don't trust the OS to call us when it should... */
    5299     u64TSC = ASMReadTSC();
    53005305    u64TSCDelta = u64TSC - pGipCpu->u64TSC;
    53015306    ASMAtomicXchgU64(&pGipCpu->u64TSC, u64TSC);
     
    53695374 * @param   pGip        Pointer to the GIP.
    53705375 * @param   u64NanoTS   The current nanosecond timesamp.
    5371  */
    5372 void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS)
     5376 * @param   u64TSC      The current TSC timesamp.
     5377 */
     5378void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC)
    53735379{
    53745380    /*
     
    54215427     * Update the data.
    54225428     */
    5423     supdrvGipDoUpdateCpu(pGip, pGipCpu, u64NanoTS);
     5429    supdrvGipDoUpdateCpu(pGip, pGipCpu, u64NanoTS, u64TSC);
    54245430
    54255431    /*
     
    54355441 * @param   pGip        Pointer to the GIP.
    54365442 * @param   u64NanoTS   The current nanosecond timesamp.
     5443 * @param   u64TSC      The current TSC timesamp.
    54375444 * @param   iCpu        The CPU index.
    54385445 */
    5439 void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, unsigned iCpu)
     5446void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, unsigned iCpu)
    54405447{
    54415448    PSUPGIPCPU  pGipCpu;
     
    54595466         * Update the data.
    54605467         */
    5461         supdrvGipDoUpdateCpu(pGip, pGipCpu, u64NanoTS);
     5468        supdrvGipDoUpdateCpu(pGip, pGipCpu, u64NanoTS, u64TSC);
    54625469
    54635470        /*
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