VirtualBox

Changeset 1956 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Apr 5, 2007 3:26:03 PM (18 years ago)
Author:
vboxsync
Message:

Fixed a couple of issues with virtualized TSC related to pausing and state loading. Also implemented support for TSC frequencies up to 4GHz and changed the default to the host CPU (virtualized TSC again).

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/TM.cpp

    r1876 r1956  
    217217    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    218218    {
    219 #if 0  /* when tmCpuTickGetRawVirtual is done */
    220219        pVM->tm.s.cTSCTicksPerSecond = tmR3Calibrate();
    221 #else
    222         if (pVM->tm.s.fTSCUseRealTSC)
    223             pVM->tm.s.cTSCTicksPerSecond = tmR3Calibrate();
    224         else
    225             pVM->tm.s.cTSCTicksPerSecond = TMCLOCK_FREQ_VIRTUAL;/* same as the virtual clock. */
    226 #endif
     220        if (    !pVM->tm.s.fTSCUseRealTSC
     221            &&  pVM->tm.s.cTSCTicksPerSecond >= _4G)
     222            pVM->tm.s.cTSCTicksPerSecond = _4G - 1; /* (A limitation of our math code) */
    227223    }
    228224    else if (VBOX_FAILURE(rc))
    229225        return VMSetError(pVM, rc, RT_SRC_POS,
    230226                          N_("Configuration error: Failed to querying uint64_t value \"TSCTicksPerSecond\". (%Vrc)"), rc);
    231 #if 0 /* when tmCpuTickGetRawVirtual is done */
    232227    else if (   pVM->tm.s.cTSCTicksPerSecond < _1M
    233              || pVM->tm.s.cTSCTicksPerSecond > _1E)
     228             || pVM->tm.s.cTSCTicksPerSecond >= _4G)
    234229        return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
    235                           N_("Configuration error: \"TSCTicksPerSecond\" = %RI64 is not in the range 1MHz..1EHz!"),
     230                          N_("Configuration error: \"TSCTicksPerSecond\" = %RI64 is not in the range 1MHz..4GHz-1!"),
    236231                          pVM->tm.s.cTSCTicksPerSecond);
    237 #else
    238     else if (pVM->tm.s.cTSCTicksPerSecond != TMCLOCK_FREQ_VIRTUAL)
    239         return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
    240                           N_("Configuration error: \"TSCTicksPerSecond\" = %RI64 is not 1GHz! (temporary restriction)"),
    241                           pVM->tm.s.cTSCTicksPerSecond);
    242 #endif
    243232    else
    244233    {
     
    636625    /* the cpu tick clock. */
    637626    pVM->tm.s.fTSCTicking = false;
     627    SSMR3GetU64(pSSM, &pVM->tm.s.u64TSC);
    638628    rc = SSMR3GetU64(pSSM, &u64Hz);
    639629    if (VBOX_FAILURE(rc))
    640630        return rc;
    641     SSMR3GetU64(pSSM, &pVM->tm.s.u64TSC);
    642     /** @todo check TSC frequency and virtualize the TSC properly! */
    643     pVM->tm.s.u64TSCOffset = 0;
     631    if (pVM->tm.s.fTSCUseRealTSC)
     632        pVM->tm.s.u64TSCOffset = 0; /** @todo TSC restore stuff and HWACC. */
     633    else
     634        pVM->tm.s.cTSCTicksPerSecond = u64Hz;
     635    LogRel(("TM: cTSCTicksPerSecond=%#RX64 (%RU64) fTSCVirtualized=%RTbool fTSCUseRealTSC=%RTbool (state load)\n",
     636            pVM->tm.s.cTSCTicksPerSecond, pVM->tm.s.cTSCTicksPerSecond, pVM->tm.s.fTSCVirtualized, pVM->tm.s.fTSCUseRealTSC));
    644637
    645638    /*
     
    12861279    if (pVM->tm.s.fTSCUseRealTSC)
    12871280    {
    1288         pHlp->pfnPrintf(pHlp, "- real tsc");
     1281        pHlp->pfnPrintf(pHlp, " - real tsc");
    12891282        if (pVM->tm.s.u64TSCOffset)
    12901283            pHlp->pfnPrintf(pHlp, "\n          offset %#RX64", pVM->tm.s.u64TSCOffset);
    12911284    }
    12921285    else
    1293         pHlp->pfnPrintf(pHlp, "- virtual clock");
     1286        pHlp->pfnPrintf(pHlp, " - virtual clock");
    12941287    pHlp->pfnPrintf(pHlp, "\n");
    12951288
  • trunk/src/VBox/VMM/VMMAll/TMAllCpu.cpp

    r1057 r1956  
    4242{
    4343    uint64_t u64 = TMVirtualGet(pVM);
    44     /** @todo calc tsc from virtual time. */
     44    if (u64 != TMCLOCK_FREQ_VIRTUAL)
     45        u64 = ASMMultU64ByU32DivByU32(u64, pVM->tm.s.cTSCTicksPerSecond, TMCLOCK_FREQ_VIRTUAL);
    4546    return u64;
    4647}
     
    8283    if (pVM->tm.s.fTSCTicking)
    8384    {
    84         if (!pVM->tm.s.fTSCVirtualized)
    85         {
    86             if (pVM->tm.s.fTSCUseRealTSC)
    87                 pVM->tm.s.u64TSC = ASMReadTSC() - pVM->tm.s.u64TSCOffset;
    88             else
    89                 pVM->tm.s.u64TSC = tmCpuTickGetRawVirtual(pVM) - pVM->tm.s.u64TSCOffset;
    90         }
     85        pVM->tm.s.u64TSC = TMCpuTickGet(pVM);
    9186        pVM->tm.s.fTSCTicking = false;
    9287        return VINF_SUCCESS;
     
    107102{
    108103    uint64_t u64;
    109     if (pVM->tm.s.fTSCUseRealTSC)
    110         u64 = ASMReadTSC();
    111     else
     104    if (RT_LIKELY(pVM->tm.s.fTSCTicking))
    112105    {
    113         if (pVM->tm.s.fTSCTicking)
     106        if (pVM->tm.s.fTSCVirtualized)
    114107        {
    115108            if (pVM->tm.s.fTSCUseRealTSC)
    116                 u64 = ASMReadTSC() - pVM->tm.s.u64TSCOffset;
     109                u64 = ASMReadTSC();
    117110            else
    118                 u64 = tmCpuTickGetRawVirtual(pVM) - pVM->tm.s.u64TSCOffset;
     111                u64 = tmCpuTickGetRawVirtual(pVM);
     112            u64 -= pVM->tm.s.u64TSCOffset;
    119113        }
    120114        else
    121             u64 = pVM->tm.s.u64TSC;
     115            u64 = ASMReadTSC();
    122116    }
     117    else
     118        u64 = pVM->tm.s.u64TSC;
    123119    return u64;
    124120}
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