VirtualBox

Changeset 84044 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Apr 28, 2020 12:01:07 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137617
Message:

GIM/KVM: Instead of reading the time and TSC separately, only read the time and calculate TSC. Avoids problems caused by values not being completely in sync (see bugref:7270).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/GIMKvm.cpp

    r83372 r84044  
    415415    SystemTime.u32TscScale = ASMDivU64ByU32RetU32(RT_NS_1SEC_64 << 32, uTscFreqLo);
    416416
     417    /* For informational purposes, back-calculate the exact TSC frequency the guest will see.
     418     * Note that the frequency is in kHz, not Hz, since that's what Linux uses.
     419     */
     420    uint64_t uTscKHz;
     421
     422    uTscKHz = (RT_NS_1MS_64 << 32) / SystemTime.u32TscScale;
     423    if (SystemTime.i8TscShift < 0)
     424        uTscKHz <<= -SystemTime.i8TscShift;
     425    else
     426        uTscKHz >>=  SystemTime.i8TscShift;
     427
    417428    /*
    418429     * Update guest memory with the system-time struct. Technically we are cheating
    419430     * by only writing the struct once with the version incremented by two; in reality,
    420      * the system-time struct is enabled once by the boot CPU and not concurrently read
    421      * by other VCPUs at the same time.
     431     * the system-time struct is enabled once for each CPU at boot and not concurrently
     432     * read by other VCPUs at the same time.
    422433     */
    423434    Assert(!(SystemTime.u32Version & UINT32_C(1)));
     
    426437    {
    427438        LogRel(("GIM: KVM: VCPU%3d: Enabled system-time struct. at %#RGp - u32TscScale=%#RX32 i8TscShift=%d uVersion=%#RU32 "
    428                 "fFlags=%#x uTsc=%#RX64 uVirtNanoTS=%#RX64\n", pVCpu->idCpu, pKvmCpu->GCPhysSystemTime, SystemTime.u32TscScale,
    429                 SystemTime.i8TscShift, SystemTime.u32Version, SystemTime.fFlags, pKvmCpu->uTsc, pKvmCpu->uVirtNanoTS));
     439                "fFlags=%#x uTsc=%#RX64 uVirtNanoTS=%#RX64 TscKHz=%RU64\n", pVCpu->idCpu, pKvmCpu->GCPhysSystemTime, SystemTime.u32TscScale,
     440                SystemTime.i8TscShift, SystemTime.u32Version, SystemTime.fFlags, pKvmCpu->uTsc, pKvmCpu->uVirtNanoTS, uTscKHz));
    430441        TMR3CpuTickParavirtEnable(pVM);
    431442    }
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