kernel/condition_variable: Granularize locking.

Before this commit, *all* ConditionVariable operations (yes, all;
even Wait, Notify, etc.) went through a single spinlock, that also
protected the sConditionVariableHash. This obviously does not scale
so well with core count, to say the least!

With this commit, we add spinlocks to each Variable and Entry.
This makes locking somewhat more complicated (and nuanced; see
inline comment), but the trade-off seems completely worth it:

(compile HaikuDepot in VMware, 2 cores)
before
real 1m20.219s
user 1m5.619s
sys  0m40.724s

after
real 1m12.667s
user 0m57.684s
sys  0m37.251s

The more cores there are, the more of an optimization this will
likely prove to be. But 10%-across-the-board is not bad to say
the least.

Change-Id: I1e40a997fff58a79e987d7cdcafa8f7358e1115a
This commit is contained in:
Augustin Cavalier
2019-08-03 11:24:34 -04:00
parent 489612d43f
commit 37eda488be
2 changed files with 67 additions and 38 deletions
+5 -1
View File
@@ -1,5 +1,6 @@
/*
* Copyright 2007-2011, Ingo Weinhold, [email protected].
* Copyright 2019, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_CONDITION_VARIABLE_H
@@ -37,9 +38,10 @@ public:
inline ConditionVariable* Variable() const { return fVariable; }
private:
inline void AddToVariable(ConditionVariable* variable);
inline void AddToLockedVariable(ConditionVariable* variable);
private:
spinlock fLock;
ConditionVariable* fVariable;
Thread* fThread;
status_t fWaitStatus;
@@ -88,6 +90,8 @@ protected:
const void* fObject;
const char* fObjectType;
spinlock fLock;
EntryList fEntries;
ConditionVariable* fNext;