VirtualBox

Changeset 90598 in vbox


Ignore:
Timestamp:
Aug 10, 2021 1:12:43 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146209
Message:

VMM: Speed up VMMGetCpuId in ring-0 by using hash table (via new GVMMR0GetGVCpuByGVMandEMT call). bugref:6695

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/VMMAll.cpp

    r90597 r90598  
    187187
    188188#elif defined(IN_RING0)
    189     if (pVM->cCpus == 1)
    190         return 0;
    191     VMCPUID const cCpus = pVM->cCpus;
    192 
    193     /* Search first by host cpu id (most common case)
    194      * and then by native thread id (page fusion case).
    195      */
    196     if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD))
    197     {
    198         /** @todo r=ramshankar: This doesn't buy us anything in terms of performance
    199          *        leaving it here for hysterical raisins and as a reference if we
    200          *        implemented a hashing approach in the future. */
    201         RTCPUID idHostCpu = RTMpCpuId();
    202 
    203         /** @todo optimize for large number of VCPUs when that becomes more common. */
    204         for (VMCPUID idCpu = 0; idCpu < cCpus; idCpu++)
    205         {
    206             PVMCPUCC pVCpu = VMCC_GET_CPU(pVM, idCpu);
    207             if (pVCpu->idHostCpu == idHostCpu)
    208                 return pVCpu->idCpu;
    209         }
    210     }
    211 
    212     /* RTThreadGetNativeSelf had better be cheap. */
    213     RTNATIVETHREAD hThread = RTThreadNativeSelf();
    214 
    215     /** @todo optimize for large number of VCPUs when that becomes more common. */
    216     for (VMCPUID idCpu = 0; idCpu < cCpus; idCpu++)
    217     {
    218         PVMCPUCC pVCpu = VMCC_GET_CPU(pVM, idCpu);
    219         if (pVCpu->hNativeThreadR0 == hThread)
    220             return pVCpu->idCpu;
    221     }
    222     return NIL_VMCPUID;
     189    PVMCPUCC pVCpu = GVMMR0GetGVCpuByGVMandEMT(pVM, NIL_RTNATIVETHREAD);
     190    return pVCpu ? pVCpu->idCpu : NIL_VMCPUID;
    223191
    224192#else /* RC: Always EMT(0) */
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