From: Kostya Kortchinsky Date: Fri, 27 Oct 2017 20:10:14 +0000 (+0000) Subject: [scudo] Allow to specify the maximum number of TSDs at compile time X-Git-Tag: llvmorg-6.0.0-rc1~4719 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91b7558ca888096483614ed92166f67c3c91027e;p=platform%2Fupstream%2Fllvm.git [scudo] Allow to specify the maximum number of TSDs at compile time Summary: This introduces `SCUDO_MAX_CACHES` allowing to define an upper bound to the number of `ScudoTSD` created in the Shared TSD model (by default 32U). This name felt clearer than `SCUDO_MAX_TSDS` which is technically what it really is. I am opened to suggestions if that doesn't feel right. Additionally change `getNumberOfCPUs` to return a `u32` to be more consistent. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D39338 llvm-svn: 316788 --- diff --git a/compiler-rt/lib/scudo/scudo_platform.h b/compiler-rt/lib/scudo/scudo_platform.h index 095d6ef..7db1197 100644 --- a/compiler-rt/lib/scudo/scudo_platform.h +++ b/compiler-rt/lib/scudo/scudo_platform.h @@ -40,6 +40,11 @@ # error "The exclusive TSD model is not supported on this platform." #endif +// Maximum number of TSDs that can be created for the Shared model. +#ifndef SCUDO_SHARED_TSD_POOL_SIZE +# define SCUDO_SHARED_TSD_POOL_SIZE 32U +#endif // SCUDO_SHARED_TSD_POOL_SIZE + namespace __scudo { #if SANITIZER_CAN_USE_ALLOCATOR64 diff --git a/compiler-rt/lib/scudo/scudo_tsd_shared.cpp b/compiler-rt/lib/scudo/scudo_tsd_shared.cpp index 6ee2f84..191c9ff 100644 --- a/compiler-rt/lib/scudo/scudo_tsd_shared.cpp +++ b/compiler-rt/lib/scudo/scudo_tsd_shared.cpp @@ -25,7 +25,7 @@ static ScudoTSD *TSDs; static u32 NumberOfTSDs; // sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used as they allocate memory. -static uptr getNumberOfCPUs() { +static u32 getNumberOfCPUs() { cpu_set_t CPUs; CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); return CPU_COUNT(&CPUs); @@ -34,11 +34,8 @@ static uptr getNumberOfCPUs() { static void initOnce() { CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0); initScudo(); - NumberOfTSDs = getNumberOfCPUs(); - if (NumberOfTSDs == 0) - NumberOfTSDs = 1; - if (NumberOfTSDs > 32) - NumberOfTSDs = 32; + NumberOfTSDs = Min(Max(1U, getNumberOfCPUs()), + static_cast(SCUDO_SHARED_TSD_POOL_SIZE)); TSDs = reinterpret_cast( MmapOrDie(sizeof(ScudoTSD) * NumberOfTSDs, "ScudoTSDs")); for (u32 i = 0; i < NumberOfTSDs; i++)