VirtualBox

Changeset 53435 in vbox


Ignore:
Timestamp:
Dec 3, 2014 6:03:25 PM (10 years ago)
Author:
vboxsync
Message:

VBox/sup.h: r=bird: Try unbreak non-x86/amd64 use of the header (busted by r96760 and compounded in 97118). Doc + codestyle changes: 1. Brief function/whatever description should stand alone and be, well, brief. Ofthen you only want to get clued in on what the function does, not read about all the pitfalls and stuff. 2. No 'else' after 'return'.

File:
1 edited

Legend:

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

    r53430 r53435  
    3333#include <iprt/stdarg.h>
    3434#include <iprt/cpuset.h>
    35 #include <iprt/asm-amd64-x86.h>
     35#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     36# include <iprt/asm-amd64-x86.h>
     37#endif
    3638
    3739RT_C_DECLS_BEGIN
     
    427429SUPDECL(PSUPGLOBALINFOPAGE)             SUPGetGIP(void);
    428430
    429 
     431#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    430432/**
    431433 * Gets the TSC frequency of the calling CPU.
     
    448450        Assert(pGip->u32Mode == SUPGIPMODE_ASYNC_TSC);
    449451        iCpu = pGip->aiCpuFromApicId[ASMGetApicId()];
    450         if (iCpu >= pGip->cCpus)
     452        if (RT_UNLIKELY(iCpu >= pGip->cCpus))
    451453            return UINT64_MAX;
    452454    }
     
    454456    return pGip->aCPUs[iCpu].u64CpuHz;
    455457}
    456 
     458#endif /* X86 || AMD64 */
    457459
    458460/**
     
    14831485    switch (pGip->u32Mode)
    14841486    {
    1485         case SUPGIPMODE_INVARIANT_TSC: return "Invariant";
    1486         case SUPGIPMODE_SYNC_TSC:      return "Synchronous";
    1487         case SUPGIPMODE_ASYNC_TSC:     return "Asynchronous";
    1488         case SUPGIPMODE_INVALID:       return "Invalid";
    1489         default:                       return "???";
     1487        case SUPGIPMODE_INVARIANT_TSC:  return "Invariant";
     1488        case SUPGIPMODE_SYNC_TSC:       return "Synchronous";
     1489        case SUPGIPMODE_ASYNC_TSC:      return "Asynchronous";
     1490        case SUPGIPMODE_INVALID:        return "Invalid";
     1491        default:                        return "???";
    14901492    }
    14911493}
     
    15041506        && pGip->u32Mode == SUPGIPMODE_INVARIANT_TSC)
    15051507    {
    1506         uint64_t uLo;
    1507         uint64_t uHi;
    1508 
    1509         if (pGip->u64CpuHz == u64CpuHz)
    1510             return true;
    1511 
    1512         /* Arbitrary tolerance threshold, tweak later if required, perhaps
    1513            more tolerance on lower frequencies and less tolerance on higher. */
    1514         uLo = (pGip->u64CpuHz << 10) / 1025;
    1515         uHi = pGip->u64CpuHz + (pGip->u64CpuHz - uLo);
    1516         if (   u64CpuHz < uLo
    1517             || u64CpuHz > uHi)
    1518             return false;
     1508        if (pGip->u64CpuHz != u64CpuHz)
     1509        {
     1510            /* Arbitrary tolerance threshold, tweak later if required, perhaps
     1511               more tolerance on lower frequencies and less tolerance on higher. */
     1512            uint64_t uLo = (pGip->u64CpuHz << 10) / 1025;
     1513            uint64_t uHi = pGip->u64CpuHz + (pGip->u64CpuHz - uLo);
     1514            if (   u64CpuHz < uLo
     1515                || u64CpuHz > uHi)
     1516                return false;
     1517        }
    15191518        return true;
    15201519    }
     
    15221521}
    15231522
     1523#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    15241524
    15251525/**
     
    15331533 *                          applied or not (optional, can be NULL).
    15341534 *
    1535  * @note If you change the delta calculation made here, make sure to update the
    1536  *       assembly version in sup.mac! Also update supdrvGipMpEvent() while
    1537  *       re-adjusting deltas while choosing a new GIP master.
    15381535 * @remarks Maybe called with interrupts disabled in ring-0!
     1536 *
     1537 * @note    If you change the delta calculation made here, make sure to update
     1538 *          the assembly version in sup.mac! Also update supdrvGipMpEvent()
     1539 *          while re-adjusting deltas while choosing a new GIP master.
    15391540 */
    15401541DECLINLINE(int) SUPTscDeltaApply(PSUPGLOBALINFOPAGE pGip, uint64_t *puTsc, uint16_t idApic, bool *pfDeltaApplied)
     
    15671568
    15681569/**
    1569  * Gets the delta-adjusted TSC, must only be called when GIP mode is invariant
    1570  * (i.e. when TSC deltas are likely to be computed and available).
    1571  *
    1572  * In other GIP modes, like async, we don't bother with computing TSC deltas and
    1573  * therefore it is meaningless to call this function, use SUPReadTSC() instead.
     1570 * Gets the delta-adjusted TSC.
     1571 *
     1572 * Must only be called when GIP mode is invariant (i.e. when TSC deltas are
     1573 * likely to be computed and available).  In other GIP modes, like async, we
     1574 * don't bother with computing TSC deltas and therefore it is meaningless to
     1575 * call this function, use SUPReadTSC() instead.
    15741576 *
    15751577 * @returns VBox status code.
     
    15851587DECLINLINE(int) SUPGetTsc(uint64_t *puTsc, uint16_t *pidApic)
    15861588{
    1587 #ifdef IN_RING3
     1589# ifdef IN_RING3
    15881590    return SUPR3ReadTsc(puTsc, pidApic);
    1589 #else
     1591# else
    15901592    RTCCUINTREG uFlags;
    15911593    uint16_t    idApic;
     
    16071609    AssertRCReturn(rc, rc);
    16081610    return fDeltaApplied ? VINF_SUCCESS : VERR_SUPDRV_TSC_READ_FAILED;
    1609 #endif
     1611# endif
    16101612}
    16111613
     
    16131615/**
    16141616 * Reads the host TSC value.
     1617 *
    16151618 * If applicable, normalizes the host TSC value with intercpu TSC deltas.
    16161619 *
     
    16281631        return u64Tsc;
    16291632    }
    1630     else
    1631         return ASMReadTSC();
     1633    return ASMReadTSC();
    16321634}
     1635
     1636#endif /* X86 || AMD64 */
    16331637
    16341638
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