VirtualBox

Ignore:
Timestamp:
Dec 3, 2014 1:18:41 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
97118
Message:

VMM/TM: First step in introducing the invariant TM mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/testcase/tstGIP-2.cpp

    r53358 r53430  
    3939#include <iprt/initterm.h>
    4040#include <iprt/getopt.h>
     41#include <iprt/x86.h>
     42
     43
     44/**
     45 * Checks whether the CPU advertises an invariant TSC or not.
     46 *
     47 * @returns true if invariant, false otherwise.
     48 */
     49bool tstIsInvariantTsc(void)
     50{
     51    if (ASMHasCpuId())
     52    {
     53        uint32_t uEax, uEbx, uEcx, uEdx;
     54        ASMCpuId(0x80000000, &uEax, &uEbx, &uEcx, &uEdx);
     55        if (uEax >= 0x80000007)
     56        {
     57            ASMCpuId(0x80000007, &uEax, &uEbx, &uEcx, &uEdx);
     58            if (uEdx & X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR)
     59                return true;
     60        }
     61    }
     62    return false;
     63}
    4164
    4265
     
    6487    uint64_t uCpuHzRef = 0;
    6588    uint64_t uCpuHzOverallDeviation = 0;
     89    int64_t  iCpuHzMaxDeviation = 0;
    6690    int32_t cCpuHzOverallDevCnt = 0;
    6791    RTGETOPTUNION ValueUnion;
     
    144168                            else
    145169                            {
    146                                 if (pCpu->u32TransactionId > 7)
     170                                /* Wait until the history validation code takes effect. */
     171                                if (pCpu->u32TransactionId > 23 + (8 * 2) + 1)
    147172                                {
     173                                    if (RT_ABS(iCpuHzDeviation) > RT_ABS(iCpuHzMaxDeviation))
     174                                        iCpuHzMaxDeviation = iCpuHzDeviation;
    148175                                    uCpuHzOverallDeviation += uCpuHzDeviation;
    149176                                    cCpuHzOverallDevCnt++;
     
    222249                    RTPrintf("tstGIP-2: offline: %lld\n", g_pSUPGlobalInfoPage->aCPUs[iCpu].i64TSCDelta);
    223250
    224             if (uCpuHzRef)
     251            RTPrintf("CPUID.Invariant-TSC    : %RTbool\n", tstIsInvariantTsc());
     252            if (   uCpuHzRef
     253                && cCpuHzOverallDevCnt)
    225254            {
    226                 uint32_t uPct = (uint32_t)(uCpuHzOverallDeviation * 100000 / cCpuHzOverallDevCnt / uCpuHzRef + 5);
    227                 RTPrintf("tstGIP-2: Overall CpuHz deviation: %d.%02d%%\n", uPct / 1000, (uPct % 1000) / 10);
     255                uint32_t uPct    = (uint32_t)(uCpuHzOverallDeviation * 100000 / cCpuHzOverallDevCnt / uCpuHzRef + 5);
     256                uint32_t uMaxPct = (uint32_t)(RT_ABS(iCpuHzMaxDeviation) * 100000 / uCpuHzRef + 5);
     257                RTPrintf("Average CpuHz deviation: %d.%02d%%\n", uPct / 1000, (uPct % 1000) / 10);
     258                RTPrintf("Maximum CpuHz deviation: %d.%02d%% (%RI64 ticks)\n", uMaxPct / 1000, (uMaxPct % 1000) / 10, iCpuHzMaxDeviation);
    228259            }
    229260        }
     
    240271    return !!rc;
    241272}
     273
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