VirtualBox

Changeset 90665 in vbox


Ignore:
Timestamp:
Aug 12, 2021 2:29:37 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146277
Message:

VMM/PDMCritSectRwEnterExcl: Tiny optimization. bugref:6695

File:
1 edited

Legend:

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

    r90660 r90665  
    827827 * gotten exclusive ownership of the critical section.
    828828 */
    829 DECLINLINE(int) pdmCritSectRwEnterExclFirst(PPDMCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPos, bool fNoVal, RTTHREAD hThreadSelf)
     829DECL_FORCE_INLINE(int) pdmCritSectRwEnterExclFirst(PPDMCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPos,
     830                                                   bool fNoVal, RTTHREAD hThreadSelf)
    830831{
    831832    RT_NOREF(hThreadSelf, fNoVal, pSrcPos);
     
    10711072
    10721073    /*
    1073      * Get cracking.
    1074      */
    1075     uint64_t u64State    = PDMCRITSECTRW_READ_STATE(&pThis->s.Core.u.s.u64State);
     1074     * First we try grab an idle critical section using 128-bit atomics.
     1075     */
     1076    /** @todo This could be moved up before the recursion check. */
     1077    uint64_t u64State = PDMCRITSECTRW_READ_STATE(&pThis->s.Core.u.s.u64State);
     1078#ifdef RTASM_HAVE_CMP_WRITE_U128
     1079    if (   (u64State & ~RTCSRW_DIR_MASK) == 0
     1080        && pdmCritSectRwIsCmpWriteU128Supported())
     1081    {
     1082        RTCRITSECTRWSTATE OldState;
     1083        OldState.s.u64State      = u64State;
     1084        OldState.s.hNativeWriter = NIL_RTNATIVETHREAD;
     1085        AssertCompile(sizeof(OldState.s.hNativeWriter) == sizeof(OldState.u128.s.Lo));
     1086
     1087        RTCRITSECTRWSTATE NewState;
     1088        NewState.s.u64State      = (UINT64_C(1) << RTCSRW_CNT_WR_SHIFT) | (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT);
     1089        NewState.s.hNativeWriter = hNativeSelf;
     1090
     1091        if (ASMAtomicCmpWriteU128U(&pThis->s.Core.u.u128, NewState.u128, OldState.u128))
     1092            return pdmCritSectRwEnterExclFirst(pThis, pSrcPos, fNoVal, hThreadSelf);
     1093
     1094        u64State = PDMCRITSECTRW_READ_STATE(&pThis->s.Core.u.s.u64State);
     1095    }
     1096#endif
     1097
     1098    /*
     1099     * Do it step by step.  Update the state to reflect our desire.
     1100     */
    10761101    uint64_t u64OldState = u64State;
    10771102
     
    13861411    AssertReturn(hNativeSelf == hNativeWriter, VERR_NOT_OWNER);
    13871412
     1413
    13881414    /*
    13891415     * Unwind one recursion. Not the last?
     
    14101436    }
    14111437
     1438
    14121439    /*
    14131440     * Final recursion.
     
    14241451    }
    14251452#endif
     1453
    14261454
    14271455#ifdef RTASM_HAVE_CMP_WRITE_U128
     
    14561484        }
    14571485    }
    1458 #endif
     1486#endif /* RTASM_HAVE_CMP_WRITE_U128 */
     1487
    14591488
    14601489#if defined(IN_RING3) || defined(IN_RING0)
     
    15661595#endif /* IN_RING3 || IN_RING0 */
    15671596
     1597
    15681598#ifndef IN_RING3
    15691599    /*
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