VirtualBox

Changeset 104131 in vbox


Ignore:
Timestamp:
Apr 3, 2024 8:02:36 AM (8 months ago)
Author:
vboxsync
Message:

VMM/TM: Allow linear scaling of the guest TSC; primarily required for scaling up a 24MHz tickrate on ARM64 hosts.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/TMAllCpu.cpp

    r100005 r104131  
    116116        {
    117117            case TMTSCMODE_REAL_TSC_OFFSET:
    118                 pVCpu->tm.s.offTSCRawSrc = SUPReadTsc() - pVCpu->tm.s.u64TSC;
     118                pVCpu->tm.s.offTSCRawSrc = SUPReadTsc() * pVM->tm.s.u8TSCMultiplier - pVCpu->tm.s.u64TSC;
    119119                break;
    120120            case TMTSCMODE_VIRT_TSC_EMULATED:
     
    163163            {
    164164                case TMTSCMODE_REAL_TSC_OFFSET:
    165                     pVCpu->tm.s.offTSCRawSrc = SUPReadTsc() - pVM->tm.s.u64LastPausedTSC;
     165                    pVCpu->tm.s.offTSCRawSrc = SUPReadTsc() * pVM->tm.s.u8TSCMultiplier - pVM->tm.s.u64LastPausedTSC;
    166166                    break;
    167167                case TMTSCMODE_VIRT_TSC_EMULATED:
     
    496496        {
    497497            case TMTSCMODE_REAL_TSC_OFFSET:
    498                 u64 = SUPReadTsc();
     498                u64 = SUPReadTsc() * pVM->tm.s.u8TSCMultiplier;
    499499                break;
    500500            case TMTSCMODE_VIRT_TSC_EMULATED:
     
    642642#endif
    643643            if (RT_LIKELY(cTSCTicksPerSecond != ~(uint64_t)0))
    644                 return cTSCTicksPerSecond;
     644                return cTSCTicksPerSecond * pVM->tm.s.u8TSCMultiplier;
    645645        }
    646646    }
  • trunk/src/VBox/VMM/VMMR3/TM.cpp

    r100000 r104131  
    335335                              "TSCTiedToExecution|"
    336336                              "TSCNotTiedToHalt|"
     337                              "TSCMultiplier|"
    337338                              "ScheduleSlack|"
    338339                              "CatchUpStopThreshold|"
     
    420421    }
    421422
     423    /** @cfgm{/TM/TSCMultiplier, uint8_t}
     424     * This is a multiplier to apply to the host TSC while calculating the guest
     425     * TSC.  It's recommended to avoid using a power-of-two value to reduce number
     426     * of zeros in least-significant-bits of the scaled TSC.  Defaults to 43 on
     427     * ARM64 and 1 on all other hosts. */
     428#ifdef RT_ARCH_ARM64
     429    pVM->tm.s.u8TSCMultiplier = 43; /* 125/3 + some fudge to get us >= 1GHz from 24MHz */
     430#else
     431    pVM->tm.s.u8TSCMultiplier = 1;
     432#endif
     433    rc = CFGMR3QueryU8Def(pCfgHandle, "TSCMultiplier", &pVM->tm.s.u8TSCMultiplier, pVM->tm.s.u8TSCMultiplier);
     434    if (RT_FAILURE(rc))
     435        return VMSetError(pVM, rc, RT_SRC_POS,
     436                          N_("Configuration error: Failed to query 8-bit value \"TSCMultiplier\""));
     437    if (pVM->tm.s.u8TSCMultiplier == 0)
     438        return VMSetError(pVM, rc, RT_SRC_POS, N_("Configuration error: \"TSCMultiplier\" must not be zero!"));
     439
    422440    /** @cfgm{/TM/TSCTicksPerSecond, uint32_t, Current TSC frequency from GIP}
    423441     * The number of TSC ticks per second (i.e. the TSC frequency). This will
     
    428446    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    429447    {
    430         pVM->tm.s.cTSCTicksPerSecond = pVM->tm.s.cTSCTicksPerSecondHost;
     448        pVM->tm.s.cTSCTicksPerSecond = pVM->tm.s.cTSCTicksPerSecondHost * pVM->tm.s.u8TSCMultiplier;
    431449        if (   (   pVM->tm.s.enmTSCMode == TMTSCMODE_DYNAMIC
    432450                || pVM->tm.s.enmTSCMode == TMTSCMODE_VIRT_TSC_EMULATED)
     
    450468    {
    451469        LogRel(("TM: NEM overrides the /TM/TSCTicksPerSecond=%RU64 setting.\n", pVM->tm.s.cTSCTicksPerSecond));
    452         pVM->tm.s.cTSCTicksPerSecond = pVM->tm.s.cTSCTicksPerSecondHost;
     470        pVM->tm.s.cTSCTicksPerSecond = pVM->tm.s.cTSCTicksPerSecondHost * pVM->tm.s.u8TSCMultiplier;
    453471    }
    454472
     
    641659    CPUMR3SetCR4Feature(pVM, X86_CR4_TSD, ~X86_CR4_TSD);
    642660#endif
    643     LogRel(("TM:     cTSCTicksPerSecond=%'RU64 (%#RX64) enmTSCMode=%d (%s)\n"
     661    LogRel(("TM:     cTSCTicksPerSecond=%'RU64 (%#RX64) enmTSCMode=%d (%s) TSCMultiplier=%u\n"
    644662            "TM: cTSCTicksPerSecondHost=%'RU64 (%#RX64)\n"
    645663            "TM: TSCTiedToExecution=%RTbool TSCNotTiedToHalt=%RTbool\n",
    646             pVM->tm.s.cTSCTicksPerSecond, pVM->tm.s.cTSCTicksPerSecond, pVM->tm.s.enmTSCMode, tmR3GetTSCModeName(pVM),
     664            pVM->tm.s.cTSCTicksPerSecond, pVM->tm.s.cTSCTicksPerSecond, pVM->tm.s.enmTSCMode, tmR3GetTSCModeName(pVM), pVM->tm.s.u8TSCMultiplier,
    647665            pVM->tm.s.cTSCTicksPerSecondHost, pVM->tm.s.cTSCTicksPerSecondHost,
    648666            pVM->tm.s.fTSCTiedToExecution, pVM->tm.s.fTSCNotTiedToHalt));
     
    12501268    {
    12511269        case TMTSCMODE_REAL_TSC_OFFSET:
    1252             offTscRawSrc = SUPReadTsc();
     1270            offTscRawSrc = SUPReadTsc() * pVM->tm.s.u8TSCMultiplier;
    12531271            break;
    12541272        case TMTSCMODE_DYNAMIC:
     
    37423760         */
    37433761        uint64_t uRawOldTsc = tmR3CpuTickGetRawVirtualNoCheck(pVM);
    3744         uint64_t uRawNewTsc = SUPReadTsc();
     3762        uint64_t uRawNewTsc = SUPReadTsc() * pVM->tm.s.u8TSCMultiplier;
    37453763        uint32_t cCpus = pVM->cCpus;
    37463764        for (uint32_t i = 0; i < cCpus; i++)
     
    37963814         * See tmR3CpuTickParavirtEnable for an explanation of the conversion math.
    37973815         */
    3798         uint64_t uRawOldTsc = SUPReadTsc();
     3816        uint64_t uRawOldTsc = SUPReadTsc() * pVM->tm.s.u8TSCMultiplier;
    37993817        uint64_t uRawNewTsc = tmR3CpuTickGetRawVirtualNoCheck(pVM);
    38003818        uint32_t cCpus = pVM->cCpus;
  • trunk/src/VBox/VMM/include/TMInternal.h

    r98103 r104131  
    478478    /** Virtual timer synchronous time catch-up active. */
    479479    bool volatile               fVirtualSyncCatchUp;
    480     /** Alignment padding. */
    481     bool                        afAlignment1[1];
     480    /** The multiplier for TSC. */
     481    uint8_t                     u8TSCMultiplier;
    482482    /** WarpDrive percentage.
    483483     * 100% is normal (fVirtualSyncNormal == true). When other than 100% we apply
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