VirtualBox

Changeset 86191 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 21, 2020 9:59:04 AM (4 years ago)
Author:
vboxsync
Message:

Runtime/mp-r0drv-nt.cpp: Dynamically determine the size of the KAFFINITY_EX structure as it is not static across Windows versions (increased lately with W10 20H2) [2nd attempt]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/nt/mp-r0drv-nt.cpp

    r86177 r86191  
    122122/** The handle of the rtR0NtMpProcessorChangeCallback registration. */
    123123static PVOID                            g_pvMpCpuChangeCallback = NULL;
     124/** Size of the KAFFINITY_EX structure.
     125 * This increased from 20 to 32 bitmap words in the 2020 H2 windows 10 release
     126 * (i.e. 1280 to 2048 CPUs).  We expect this to increase in the future. */
     127static size_t                           g_cbRtMpNtKaffinityEx = RT_UOFFSETOF(KAFFINITY_EX, Bitmap)
     128                                                              + RT_SIZEOFMEMB(KAFFINITY_EX, Bitmap[0]) * 256;
     129/** The size value of the KAFFINITY_EX structure. */
     130static uint16_t                         g_cRtMpNtKaffinityExEntries = 256;
    124131
    125132
     
    598605        && g_pfnrtKeGetProcessorIndexFromNumber)
    599606    {
    600         g_pfnrtMpPokeCpuWorker = rtMpPokeCpuUsingHalRequestIpiW7Plus;
    601         DbgPrint("IPRT: RTMpPoke => rtMpPokeCpuUsingHalRequestIpiW7Plus\n");
    602     }
    603     else if (pOsVerInfo->uMajorVer >= 6 && g_pfnrtKeIpiGenericCall)
     607        /* Determine the real size of the KAFFINITY_EX structure. */
     608        size_t const  cbAffinity = _8K;
     609        PKAFFINITY_EX pAffinity  = (PKAFFINITY_EX)RTMemAllocZ(cbAffinity);
     610        AssertReturn(pAffinity, VERR_NO_MEMORY);
     611        size_t const cMaxEntries = (cbAffinity - RT_UOFFSETOF(KAFFINITY_EX, Bitmap[0])) / sizeof(pAffinity->Bitmap[0]);
     612        g_pfnrtKeInitializeAffinityEx(pAffinity);
     613        if (pAffinity->Size > 1 && pAffinity->Size <= cMaxEntries)
     614        {
     615            g_cRtMpNtKaffinityExEntries = pAffinity->Size;
     616            g_cbRtMpNtKaffinityEx       = pAffinity->Size * sizeof(pAffinity->Bitmap[0]) + RT_UOFFSETOF(KAFFINITY_EX, Bitmap[0]);
     617            g_pfnrtMpPokeCpuWorker      = rtMpPokeCpuUsingHalRequestIpiW7Plus;
     618            RTMemFree(pAffinity);
     619            DbgPrint("IPRT: RTMpPoke => rtMpPokeCpuUsingHalRequestIpiW7Plus\n");
     620            return VINF_SUCCESS;
     621        }
     622        DbgPrint("IPRT: RTMpPoke can't use rtMpPokeCpuUsingHalRequestIpiW7Plus! pAffinity->Size=%u\n", pAffinity->Size);
     623        AssertReleaseMsg(pAffinity->Size <= cMaxEntries, ("%#x\n", pAffinity->Size)); /* stack is toast if larger (32768 CPUs). */
     624        RTMemFree(pAffinity);
     625    }
     626
     627    if (pOsVerInfo->uMajorVer >= 6 && g_pfnrtKeIpiGenericCall)
    604628    {
    605629        DbgPrint("IPRT: RTMpPoke => rtMpPokeCpuUsingBroadcastIpi\n");
     
    18611885{
    18621886    /* idCpu is an HAL processor index, so we can use it directly. */
    1863     KAFFINITY_EX Target;
    1864     g_pfnrtKeInitializeAffinityEx(&Target);
    1865     g_pfnrtKeAddProcessorAffinityEx(&Target, idCpu);
    1866 
    1867     g_pfnrtHalRequestIpiW7Plus(0, &Target);
     1887    PKAFFINITY_EX pTarget = (PKAFFINITY_EX)alloca(g_cbRtMpNtKaffinityEx);
     1888    pTarget->Size = g_cRtMpNtKaffinityExEntries; /* (just in case KeInitializeAffinityEx starts using it) */
     1889    g_pfnrtKeInitializeAffinityEx(pTarget);
     1890    g_pfnrtKeAddProcessorAffinityEx(pTarget, idCpu);
     1891
     1892    g_pfnrtHalRequestIpiW7Plus(0, pTarget);
    18681893    return VINF_SUCCESS;
    18691894}
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