[PATCH] D63783: [scudo] Correct a behavior on the shared TSD registry

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 12:03:15 PDT 2019


cryptoad created this revision.
cryptoad added reviewers: morehouse, eugenis, vitalybuka, hctim.
Herald added subscribers: Sanitizers, delcypher.
Herald added projects: LLVM, Sanitizers.
cryptoad updated this revision to Diff 206500.
cryptoad added a comment.

Remove unchanged files from CL.


There is an error in the shared TSD registry logic when looking for a
TSD in the slow path. There is an unlikely event when a TSD's precedence
was 0 after attempting a `tryLock` which indicated that it was grabbed
by another thread in between. We dealt with that case by continuing to
the next iteration, but that meant that the `Index` was not increased
and we ended up trying to lock the same TSD.
This would manifest in heavy contention, and in the end we would still
lock a TSD, but that was a wasted iteration.
So, do not `continue`, just skip the TSD as a potential candidate.

This is in both the standalone & non-standalone versions.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D63783

Files:
  lib/scudo/scudo_tsd_shared.cpp
  lib/scudo/standalone/tsd_shared.h


Index: lib/scudo/standalone/tsd_shared.h
===================================================================
--- lib/scudo/standalone/tsd_shared.h
+++ lib/scudo/standalone/tsd_shared.h
@@ -126,9 +126,7 @@
         }
         const uptr Precedence = TSDs[Index].getPrecedence();
         // A 0 precedence here means another thread just locked this TSD.
-        if (UNLIKELY(Precedence == 0))
-          continue;
-        if (Precedence < LowestPrecedence) {
+        if (Precedence && Precedence < LowestPrecedence) {
           CandidateTSD = &TSDs[Index];
           LowestPrecedence = Precedence;
         }
Index: lib/scudo/scudo_tsd_shared.cpp
===================================================================
--- lib/scudo/scudo_tsd_shared.cpp
+++ lib/scudo/scudo_tsd_shared.cpp
@@ -83,9 +83,7 @@
       }
       const uptr Precedence = TSDs[Index].getPrecedence();
       // A 0 precedence here means another thread just locked this TSD.
-      if (UNLIKELY(Precedence == 0))
-        continue;
-      if (Precedence < LowestPrecedence) {
+      if (Precedence && Precedence < LowestPrecedence) {
         CandidateTSD = &TSDs[Index];
         LowestPrecedence = Precedence;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63783.206500.patch
Type: text/x-patch
Size: 1195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190625/75347e9f/attachment.bin>


More information about the llvm-commits mailing list