VirtualBox

Changeset 36232 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Mar 9, 2011 4:41:09 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
70453
Message:

RTCPUSET, SUPDrv: Preparation for supporting 256 CPUs/cores/threads.

Location:
trunk/include/iprt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpuset.h

    r28800 r36232  
    4242 * The maximum number of CPUs a set can contain and IPRT is able
    4343 * to reference.
     44 *
     45 * @remarks Must match the size of RTCPUSET.
    4446 * @remarks This is the maximum value of the supported platforms.
    4547 */
    46 #define RTCPUSET_MAX_CPUS       64
     48#ifdef RT_WITH_LOTS_OF_CPUS
     49# define RTCPUSET_MAX_CPUS      256
     50#else
     51# define RTCPUSET_MAX_CPUS      64
     52#endif
    4753
    4854/**
     
    5460DECLINLINE(PRTCPUSET) RTCpuSetEmpty(PRTCPUSET pSet)
    5561{
     62#ifdef RTCPUSET_IS_BITMAP
     63    unsigned i;
     64    for (i = 0; i < RT_ELEMENTS(pSet->bmSet); i++)
     65        pSet->bmSet[i] = 0;
     66#else
    5667    *pSet = 0;
     68#endif
    5769    return pSet;
    5870}
     
    6779DECLINLINE(PRTCPUSET) RTCpuSetFill(PRTCPUSET pSet)
    6880{
     81#ifdef RTCPUSET_IS_BITMAP
     82    unsigned i;
     83    for (i = 0; i < RT_ELEMENTS(pSet->bmSet); i++)
     84        pSet->bmSet[i] = UINT64_MAX;
     85#else
    6986    *pSet = UINT64_MAX;
     87#endif
    7088    return pSet;
    7189}
     
    167185DECLINLINE(bool) RTCpuSetIsEqual(PCRTCPUSET pSet1, PCRTCPUSET pSet2)
    168186{
     187#ifdef RTCPUSET_IS_BITMAP
     188    unsigned i;
     189    for (i = 0; i < RT_ELEMENTS(pSet1->bmSet); i++)
     190        if (pSet1->bmSet[i] != pSet1->bmSet[i])
     191            return false;
     192    return true;
     193#else
    169194    return *pSet1 == *pSet2 ? true : false;
     195#endif
    170196}
    171197
     
    176202 * @returns The mask.
    177203 * @param   pSet    Pointer to the set.
     204 * @remarks Use with extreme care as it may lose information!
    178205 */
    179206DECLINLINE(uint64_t) RTCpuSetToU64(PCRTCPUSET pSet)
    180207{
     208#ifdef RTCPUSET_IS_BITMAP
     209    return pSet->bmSet[0];
     210#else
    181211    return *pSet;
     212#endif
    182213}
    183214
     
    191222DECLINLINE(PRTCPUSET) RTCpuSetFromU64(PRTCPUSET pSet, uint64_t fMask)
    192223{
     224#ifdef RTCPUSET_IS_BITMAP
     225    unsigned i;
     226
     227    pSet->bmSet[0] = fMask;
     228    for (i = 1; i < RT_ELEMENTS(pSet->bmSet); i++)
     229        pSet->bmSet[i] = 0;
     230#else
    193231    *pSet = fMask;
     232#endif
    194233    return pSet;
    195234}
     
    204243DECLINLINE(int) RTCpuSetCount(PCRTCPUSET pSet)
    205244{
    206     int     cCpus = 0;
    207     RTCPUID iCpu = 64;
     245    int         cCpus = 0;
     246#ifdef RTCPUSET_IS_BITMAP
     247    unsigned    i;
     248
     249    for (i = 0; i < RT_ELEMENTS(pSet->bmSet); i++)
     250    {
     251        uint64_t u64 = pSet->bmSet[i];
     252        if (u64 != 0)
     253        {
     254            unsigned iCpu = 64;
     255            while (iCpu-- > 0)
     256            {
     257                if (u64 & 1)
     258                    cCpus++;
     259                u64 >>= 1;
     260            }
     261        }
     262    }
     263
     264#else
     265    unsigned    iCpu = 64;
    208266    while (iCpu-- > 0)
    209267        if (*pSet & RT_BIT_64(iCpu))
    210268            cCpus++;
     269#endif
    211270    return cCpus;
    212271}
     
    221280DECLINLINE(int) RTCpuLastIndex(PCRTCPUSET pSet)
    222281{
     282#ifdef RTCPUSET_IS_BITMAP
     283    unsigned i = RT_ELEMENTS(pSet->bmSet);
     284    while (i-- > 0)
     285    {
     286        uint64_t u64 = pSet->bmSet[i];
     287        if (u64)
     288        {
     289            /* There are more efficient ways to do this in asm.h... */
     290            unsigned iBit;
     291            for (iBit = 63; iBit > 0; iBit--)
     292            {
     293                if (u64 & RT_BIT_64(63))
     294                    break;
     295                u64 <<= 1;
     296            }
     297            return i * 64 + iBit;
     298        }
     299    }
     300    return 0;
     301
     302#else
    223303    /* There are more efficient ways to do this in asm.h... */
    224304    int iCpu = RTCPUSET_MAX_CPUS;
     
    227307            return iCpu;
    228308    return iCpu;
     309#endif
    229310}
    230311
  • trunk/include/iprt/types.h

    r35662 r36232  
    16721672 * Treat this as an opaque type and always use RTCpuSet* for manupulating it.
    16731673 * @remarks Subject to change. */
     1674#ifdef RT_WITH_LOTS_OF_CPUS /** @todo RT_WITH_LOTS_OF_CPUS is just a temporary placeholder. */
     1675typedef struct RTCPUSET
     1676{
     1677    /** The bitmap.
     1678     * @remarks Must be large enough to hold RTCPUSET_MAX_CPUS bits, see
     1679     *          iprt/cpuset.h. */
     1680    uint64_t bmSet[256 / 64];
     1681} RTCPUSET;
     1682/** Indicates that RTCPUSET is a bitmap and not a 64-bit integer. */
     1683# define RTCPUSET_IS_BITMAP                         1
     1684#else
    16741685typedef uint64_t                                    RTCPUSET;
     1686#endif
    16751687/** Pointer to a CPU set. */
    16761688typedef RTCPUSET                                   *PRTCPUSET;
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