[all-commits] [llvm/llvm-project] 5b386a: [libc++] Do not yield from __sp_mut::lock()

Louis Dionne via All-commits all-commits at lists.llvm.org
Mon Jun 13 08:48:36 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5b386ac912eae3fad455df71ce226963fc97cdeb
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2022-06-13 (Mon, 13 Jun 2022)

  Changed paths:
    M libcxx/src/memory.cpp

  Log Message:
  [libc++] Do not yield from __sp_mut::lock()

Instead of trying to be clever and design our own locking primitive,
simply rely on the OS-provided implementation to do the right thing.

Indeed, manually yielding to the OS does not provide the necessary
information for it to make good prioritization decisions. For example,
if a thread with higher priority yields while waiting for a lock held
by a thread with lower priority but the system is contended, it is
possible for the thread with lower priority to not run until the higher
priority thread has yielded 16 times and goes for __libcpp_mutex_lock().
Once that happens, the OS can bump the priority of the thread that
currently holds the lock to unblock everyone. So instead, we might as
well give the system all the information from the start so it can make
appropriate decisions.

As a fly-by change, also increase the number of locks in the table.
The size increase is modest, but has the potential to half the amount
of contention on those locks.


Differential Revision: https://reviews.llvm.org/D126882

More information about the All-commits mailing list