VirtualBox

Changeset 53269 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Nov 7, 2014 5:41:01 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
96841
Message:

HostDrivers/Support: Enabled global TSC rate calculation and implemented TSC calibration over a longer interval for invariant hosts.

Location:
trunk/include/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/sup.h

    r53214 r53269  
    310310    /** The timestamp of the last time we update the update frequency. */
    311311    volatile uint64_t   u64NanoTSLastUpdateHz;
     312    /** The TSC frequency of the system. */
     313    uint64_t            u64CpuHz;
    312314    /** The set of online CPUs. */
    313315    RTCPUSET            OnlineCpuSet;
     
    322324    /** The highest number of CPUs possible. */
    323325    uint16_t            cPossibleCpus;
    324     /** The highest number of CPUs possible. */
    325326    uint16_t            u16Padding0;
    326327    /** The max CPU ID (RTMpGetMaxCpuId). */
     
    328329
    329330    /** Padding / reserved space for future data. */
    330     uint32_t            au32Padding1[29];
     331    uint32_t            au32Padding1[27];
    331332
    332333    /** Table indexed by the CPU APIC ID to get the CPU table index. */
     
    360361 * Upper 16 bits is the major version. Major version is only changed with
    361362 * incompatible changes in the GIP. */
    362 #define SUPGLOBALINFOPAGE_VERSION   0x00040000
     363#define SUPGLOBALINFOPAGE_VERSION   0x00050000
    363364
    364365/**
     
    14671468
    14681469/**
     1470 * Gets the GIP mode name given the GIP mode.
     1471 *
     1472 * @returns The name
     1473 * @param   enmGipMode      The GIP mode.
     1474 */
     1475DECLINLINE(const char *) SUPGetGIPModeName(PSUPGLOBALINFOPAGE pGip)
     1476{
     1477    Assert(pGip);
     1478    switch (pGip->u32Mode)
     1479    {
     1480        /* case SUPGIPMODE_INVARIANT_TSC:  return "Invariant"; */
     1481        case SUPGIPMODE_SYNC_TSC:       return "Synchronous";
     1482        case SUPGIPMODE_ASYNC_TSC:      return "Asynchronous";
     1483        case SUPGIPMODE_INVALID:        return "Invalid";
     1484        default:                        return "???";
     1485    }
     1486}
     1487
     1488
     1489/**
     1490 * Checks if the provided TSC frequency is close enough to the computed TSC
     1491 * frequency of the host.
     1492 *
     1493 * @returns true if it's compatible, false otherwise.
     1494 */
     1495DECLINLINE(bool) SUPIsTscFreqCompatible(uint64_t u64CpuHz)
     1496{
     1497    PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
     1498    if (   pGip
     1499        && pGip->u32Mode == SUPGIPMODE_SYNC_TSC)   /** @todo use INVARIANT_TSC */
     1500    {
     1501        uint64_t uLo;
     1502        uint64_t uHi;
     1503
     1504        if (pGip->u64CpuHz == u64CpuHz)
     1505            return true;
     1506
     1507        /* Arbitrary tolerance threshold, tweak later if required, perhaps
     1508           more tolerance on higher frequencies and less tolerance on lower. */
     1509        uLo = (pGip->u64CpuHz << 10) / 1025;
     1510        uHi = pGip->u64CpuHz + (pGip->u64CpuHz - uLo);
     1511        if (   u64CpuHz < uLo
     1512            || u64CpuHz > uHi)
     1513        {
     1514            return false;
     1515        }
     1516        return true;
     1517    }
     1518    return false;
     1519}
     1520
     1521
     1522
     1523/**
    14691524 * Applies the TSC delta to the supplied raw TSC value.
    14701525 *
     
    14781533 * @remarks Maybe called with interrupts disabled!
    14791534 */
    1480 DECLINLINE(int) SUPTscDeltaApply(PSUPGLOBALINFOPAGE pGip, uint64_t *puTsc, uint16_t idApic, bool *fDeltaApplied)
     1535DECLINLINE(int) SUPTscDeltaApply(PSUPGLOBALINFOPAGE pGip, uint64_t *puTsc, uint16_t idApic, bool *pfDeltaApplied)
    14811536{
    14821537    PSUPGIPCPU pGipCpu;
     
    14871542    Assert(pGip);
    14881543
     1544    AssertMsgReturn(idApic < RT_ELEMENTS(pGip->aiCpuFromApicId), ("idApic=%u\n", idApic), VERR_INVALID_CPU_ID);
    14891545    iCpu = pGip->aiCpuFromApicId[idApic];
    14901546    AssertMsgReturn(iCpu < pGip->cCpus, ("iCpu=%u cCpus=%u\n", iCpu, pGip->cCpus), VERR_INVALID_CPU_INDEX);
     
    14951551    {
    14961552        *puTsc -= pGipCpu->i64TSCDelta;
    1497         if (fDeltaApplied)
    1498             *fDeltaApplied = true;
     1553        if (pfDeltaApplied)
     1554            *pfDeltaApplied = true;
    14991555    }
    1500     else if (fDeltaApplied)
    1501         *fDeltaApplied = false;
     1556    else if (pfDeltaApplied)
     1557        *pfDeltaApplied = false;
    15021558
    15031559    return VINF_SUCCESS;
  • trunk/include/VBox/sup.mac

    r52618 r53269  
    5858    .u32UpdateIntervalNS        resd 1
    5959    .u64NanoTSLastUpdateHz      resq 1
     60    .u64CpuHz                   resq 1
    6061    .OnlineCpuSet               resq 4
    6162    .PresentCpuSet              resq 4
     
    6667    .u16Padding0                resw 1
    6768    .idCpuMax                   resd 1
    68     .au32Padding1               resd 29
     69    .au32Padding1               resd 27
    6970    .aiCpuFromApicId            resw 256
    7071    .aiCpuFromCpuSetIdx         resw 256
Note: See TracChangeset for help on using the changeset viewer.

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