Skip to content

Commit

Permalink
SWDEV-179954 - OpenCL/LC - Merge branch amd-master into amd-common
Browse files Browse the repository at this point in the history
Change-Id: I33c82de274ceffa3b6b4d90491aeb8bccc7c9084
  • Loading branch information
Jenkins committed Aug 14, 2019
2 parents 97c7275 + ff30f73 commit ae417b1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/scudo/standalone/local_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
// performance. It definitely decreases performance on Android though.
// if (!SCUDO_ANDROID) PREFETCH(P);
Stats.add(StatAllocated, ClassSize);
Stats.sub(StatFree, ClassSize);
return P;
}

Expand All @@ -98,6 +99,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
const uptr ClassSize = C->ClassSize;
C->Chunks[C->Count++] = P;
Stats.sub(StatAllocated, ClassSize);
Stats.add(StatFree, ClassSize);
}

void drain() {
Expand Down
8 changes: 4 additions & 4 deletions lib/scudo/standalone/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class HybridMutex {
NOINLINE void lock() {
if (LIKELY(tryLock()))
return;
// The compiler may try to fully unroll the loop, ending up in a
// NumberOfTries*NumberOfYields block of pauses mixed with tryLocks. This
// is large, ugly and unneeded, a compact loop is better for our purpose
// here. Use a pragma to tell the compiler not to unroll the loop.
// The compiler may try to fully unroll the loop, ending up in a
// NumberOfTries*NumberOfYields block of pauses mixed with tryLocks. This
// is large, ugly and unneeded, a compact loop is better for our purpose
// here. Use a pragma to tell the compiler not to unroll the loop.
#ifdef __clang__
#pragma nounroll
#endif
Expand Down
2 changes: 2 additions & 0 deletions lib/scudo/standalone/primary32.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ template <class SizeClassMapT, uptr RegionSizeLog> class SizeClassAllocator32 {
}
DCHECK(B);
DCHECK_GT(B->getCount(), 0);

C->getStats().add(StatFree, AllocatedUser);
Sci->AllocatedUser += AllocatedUser;
if (Sci->CanRelease)
Sci->ReleaseInfo.LastReleaseAtNs = getMonotonicTime();
Expand Down
1 change: 1 addition & 0 deletions lib/scudo/standalone/primary64.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ template <class SizeClassMapT, uptr RegionSizeLog> class SizeClassAllocator64 {
DCHECK(B);
DCHECK_GT(B->getCount(), 0);

C->getStats().add(StatFree, AllocatedUser);
Region->AllocatedUser += AllocatedUser;
Region->Exhausted = false;
if (Region->CanRelease)
Expand Down
2 changes: 1 addition & 1 deletion lib/scudo/standalone/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace scudo {

// Memory allocator statistics
enum StatType { StatAllocated, StatMapped, StatCount };
enum StatType { StatAllocated, StatFree, StatMapped, StatCount };

typedef uptr StatCounters[StatCount];

Expand Down
18 changes: 17 additions & 1 deletion lib/scudo/standalone/tests/wrappers_c_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST(ScudoWrappersCTest, Realloc) {
#define M_PURGE -101
#endif

TEST(ScudoWrappersCTest, Mallopt) {
TEST(ScudoWrappersCTest, MallOpt) {
errno = 0;
EXPECT_EQ(mallopt(-1000, 1), 0);
// mallopt doesn't set errno.
Expand Down Expand Up @@ -223,3 +223,19 @@ TEST(ScudoWrappersCTest, OtherAlloc) {

EXPECT_EQ(valloc(SIZE_MAX), nullptr);
}

TEST(ScudoWrappersCTest, MallInfo) {
const size_t BypassQuarantineSize = 1024U;

struct mallinfo MI = mallinfo();
size_t Allocated = MI.uordblks;
void *P = malloc(BypassQuarantineSize);
EXPECT_NE(P, nullptr);
MI = mallinfo();
EXPECT_GE(static_cast<size_t>(MI.uordblks), Allocated + BypassQuarantineSize);
EXPECT_GT(static_cast<size_t>(MI.hblkhd), 0U);
size_t Free = MI.fordblks;
free(P);
MI = mallinfo();
EXPECT_GE(static_cast<size_t>(MI.fordblks), Free + BypassQuarantineSize);
}
9 changes: 9 additions & 0 deletions lib/scudo/standalone/wrappers_c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ INTERFACE WEAK struct SCUDO_MALLINFO SCUDO_PREFIX(mallinfo)(void) {
struct SCUDO_MALLINFO Info = {};
scudo::StatCounters Stats;
SCUDO_ALLOCATOR.getStats(Stats);
// Space allocated in mmapped regions (bytes)
Info.hblkhd = static_cast<__scudo_mallinfo_data_t>(Stats[scudo::StatMapped]);
// Maximum total allocated space (bytes)
Info.usmblks = Info.hblkhd;
// Space in freed fastbin blocks (bytes)
Info.fsmblks = static_cast<__scudo_mallinfo_data_t>(Stats[scudo::StatFree]);
// Total allocated space (bytes)
Info.uordblks =
static_cast<__scudo_mallinfo_data_t>(Stats[scudo::StatAllocated]);
// Total free space (bytes)
Info.fordblks = Info.fsmblks;
return Info;
}

Expand Down

0 comments on commit ae417b1

Please sign in to comment.