Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/gpgmm/common/BuddyMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> BuddyMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "BuddyMemoryAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -100,7 +100,7 @@ namespace gpgmm {
void BuddyMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) {
std::lock_guard<std::mutex> lock(mMutex);

TRACE_EVENT0(TraceEventCategory::Default, "BuddyMemoryAllocator.DeallocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.DeallocateMemory");

ASSERT(subAllocation != nullptr);

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/ConditionalMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> ConditionalMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "ConditionalMemoryAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "ConditionalMemoryAllocator.TryAllocateMemory");
if (request.SizeInBytes <= mConditionalSize) {
return mFirstAllocator->TryAllocateMemory(request);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/common/DedicatedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> DedicatedMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "DedicatedMemoryAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand All @@ -44,7 +44,7 @@ namespace gpgmm {
}

void DedicatedMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::Default, "DedicatedMemoryAllocator.DeallocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
12 changes: 6 additions & 6 deletions src/gpgmm/common/EventMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ namespace gpgmm {

// EventMessage

EventMessage::EventMessage(const LogSeverity& level, const char* name, int messageId)
EventMessage::EventMessage(const LogSeverity& level, const char* name, EventMessageId messageId)
: mSeverity(level), mName(name), mMessageId(messageId) {
}

EventMessage::~EventMessage() {
const std::string description = mStream.str();

gpgmm::Log(mSeverity) << mName << "(" << mMessageId << ")"
gpgmm::Log(mSeverity) << mName << "(" << static_cast<int>(mMessageId) << ")"
<< ": " << description;

#if defined(GPGMM_ENABLE_ASSERT_ON_WARNING)
Expand All @@ -65,19 +65,19 @@ namespace gpgmm {
}
}

EventMessage DebugEvent(const char* name, int messageId) {
EventMessage DebugEvent(const char* name, EventMessageId messageId) {
return {LogSeverity::Debug, name, messageId};
}

EventMessage InfoEvent(const char* name, int messageId) {
EventMessage InfoEvent(const char* name, EventMessageId messageId) {
return {LogSeverity::Info, name, messageId};
}

EventMessage WarnEvent(const char* name, int messageId) {
EventMessage WarnEvent(const char* name, EventMessageId messageId) {
return {LogSeverity::Warning, name, messageId};
}

EventMessage ErrorEvent(const char* name, int messageId) {
EventMessage ErrorEvent(const char* name, EventMessageId messageId) {
return {LogSeverity::Error, name, messageId};
}

Expand Down
32 changes: 16 additions & 16 deletions src/gpgmm/common/EventMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@

namespace gpgmm {

enum EventMessageId {
Unknown,
SizeExceeded,
AlignmentMismatch,
AllocatorFailed,
PrefetchFailed,
BudgetExceeded,
BudgetUpdated,
BudgetInvalid,
enum class EventMessageId {
kUnknown,
kSizeExceeded,
kAlignmentMismatch,
kAllocatorFailed,
kPrefetchFailed,
kBudgetExceeded,
kBudgetUpdated,
kBudgetInvalid,
};

struct EventMessageInfo {
std::string Description;
int ID;
EventMessageId ID;
};

class EventMessage {
public:
EventMessage(const LogSeverity& level,
const char* name,
int messageId = EventMessageId::Unknown);
EventMessageId messageId = EventMessageId::kUnknown);
~EventMessage();

EventMessage(EventMessage&& other) = default;
Expand All @@ -58,15 +58,15 @@ namespace gpgmm {
private:
LogSeverity mSeverity;
const char* mName = nullptr;
int mMessageId = 0;
EventMessageId mMessageId = EventMessageId::kUnknown;

std::ostringstream mStream;
};

EventMessage DebugEvent(const char* name, int messageId = EventMessageId::Unknown);
EventMessage InfoEvent(const char* name, int messageId = EventMessageId::Unknown);
EventMessage WarnEvent(const char* name, int messageId = EventMessageId::Unknown);
EventMessage ErrorEvent(const char* name, int messageId = EventMessageId::Unknown);
EventMessage DebugEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown);
EventMessage InfoEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown);
EventMessage WarnEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown);
EventMessage ErrorEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown);

// Messages of a given severity to be recorded.
void SetEventMessageLevel(const LogSeverity& level);
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/common/EventTraceWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ namespace gpgmm {
eventData.AddItem("name", traceEvent.mName);

switch (traceEvent.mCategory) {
case TraceEventCategory::Default:
case TraceEventCategory::kDefault:
eventData.AddItem("cat", "default");
break;

case TraceEventCategory::Metadata:
case TraceEventCategory::kMetadata:
eventData.AddItem("cat", "__metadata");
break;

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/GPUInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace gpgmm {

enum GPUVendor {
enum class GPUVendor {
kAMD_VkVendor = 4098,
kARM_VkVendor = 5045,
kImagination_VkVendor = 4112,
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/JSONSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gpgmm {
JSONDict JSONSerializer::Serialize(const EventMessageInfo& info) {
JSONDict dict;
dict.AddItem("Description", info.Description);
dict.AddItem("ID", info.ID);
dict.AddItem("ID", static_cast<uint32_t>(info.ID));
return dict;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/MemoryAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace gpgmm {
/** \enum AllocationMethod
Represents how memory was allocated.
*/
enum AllocationMethod {
enum class AllocationMethod {

/** \brief Not yet allocated or invalid.

Expand Down
8 changes: 4 additions & 4 deletions src/gpgmm/common/MemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace gpgmm {

// Check request size cannot overflow.
if (request.SizeInBytes > std::numeric_limits<uint64_t>::max() - (request.Alignment - 1)) {
DebugEvent(GetTypename(), EventMessageId::SizeExceeded)
DebugEvent(GetTypename(), EventMessageId::kSizeExceeded)
<< "Requested size rejected due to overflow: " + std::to_string(request.SizeInBytes)
<< " bytes.";
return false;
Expand All @@ -168,7 +168,7 @@ namespace gpgmm {
// Check request size cannot overflow |this| memory allocator.
const uint64_t alignedSize = AlignTo(request.SizeInBytes, request.Alignment);
if (GetMemorySize() != kInvalidSize && alignedSize > GetMemorySize()) {
DebugEvent(GetTypename(), EventMessageId::SizeExceeded)
DebugEvent(GetTypename(), EventMessageId::kSizeExceeded)
<< "Requested size exceeds memory size (" + std::to_string(alignedSize) + " vs " +
std::to_string(GetMemorySize()) + " bytes).";
return false;
Expand All @@ -178,7 +178,7 @@ namespace gpgmm {
// Alignment value of 1 means no alignment required.
if (GetMemoryAlignment() == 0 ||
(GetMemoryAlignment() > 1 && !IsAligned(GetMemoryAlignment(), request.Alignment))) {
DebugEvent(GetTypename(), EventMessageId::AlignmentMismatch)
DebugEvent(GetTypename(), EventMessageId::kAlignmentMismatch)
<< "Requested alignment exceeds memory alignment (" +
std::to_string(request.Alignment) + " vs " +
std::to_string(GetMemoryAlignment()) + " bytes).";
Expand All @@ -204,7 +204,7 @@ namespace gpgmm {

void MemoryAllocator::CheckAndReportAllocationMisalignment(const MemoryAllocation& allocation) {
if (allocation.GetSize() > allocation.GetRequestSize()) {
DebugEvent(GetTypename(), EventMessageId::AlignmentMismatch)
DebugEvent(GetTypename(), EventMessageId::kAlignmentMismatch)
<< "Resource allocation is larger then the requested size (" +
std::to_string(allocation.GetSize()) + " vs " +
std::to_string(allocation.GetRequestSize()) + " bytes).";
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/common/PooledMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> PooledMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "PooledMemoryAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand All @@ -61,7 +61,7 @@ namespace gpgmm {
}

void PooledMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::Default, "PooledMemoryAllocator.DeallocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/common/SegmentedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> SegmentedMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "SegmentedMemoryAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -152,7 +152,7 @@ namespace gpgmm {
}

void SegmentedMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::Default, "SegmentedMemoryAllocator.DeallocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
12 changes: 6 additions & 6 deletions src/gpgmm/common/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> SlabMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "SlabMemoryAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -281,7 +281,7 @@ namespace gpgmm {
}

if (prefetchedSlabAllocation != nullptr) {
DebugEvent(GetTypename(), EventMessageId::PrefetchFailed)
DebugEvent(GetTypename(), EventMessageId::kPrefetchFailed)
<< "Pre-fetch slab memory is incompatible (" << slabSize << " vs "
<< prefetchedSlabAllocation->GetSize() << " bytes.";
}
Expand Down Expand Up @@ -382,7 +382,7 @@ namespace gpgmm {
}

void SlabMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) {
TRACE_EVENT0(TraceEventCategory::Default, "SlabMemoryAllocator.DeallocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -458,7 +458,7 @@ namespace gpgmm {
SafeDivide(mInfo.PrefetchedMemoryMissesEliminated,
mInfo.PrefetchedMemoryMissesEliminated + mInfo.PrefetchedMemoryMisses);
if (currentCoverage < kPrefetchCoverageWarnMinThreshold) {
WarnEvent(GetTypename(), EventMessageId::PrefetchFailed)
WarnEvent(GetTypename(), EventMessageId::kPrefetchFailed)
<< "Prefetch coverage is below threshold (%): " << currentCoverage * 100 << " vs "
<< kPrefetchCoverageWarnMinThreshold * 100;
return false;
Expand Down Expand Up @@ -493,7 +493,7 @@ namespace gpgmm {

std::unique_ptr<MemoryAllocation> SlabCacheAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::Default, "SlabCacheAllocator.TryAllocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -527,7 +527,7 @@ namespace gpgmm {
}

void SlabCacheAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) {
TRACE_EVENT0(TraceEventCategory::Default, "SlabCacheAllocator.DeallocateMemory");
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/TraceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace gpgmm {
#endif

GetInstance()->SetConfiguration(traceFile, ignoreMask);
TRACE_EVENT_METADATA1(TraceEventCategory::Metadata, "thread_name", "name",
TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name",
"GPGMM_MainThread");
}

Expand Down
16 changes: 8 additions & 8 deletions src/gpgmm/common/TraceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,26 @@ const uint64_t kNoId = 0;

#define GPGMM_TRACE_EVENT_OBJECT_NEW(objPtr) \
do { \
TRACE_EVENT_OBJECT_CREATED_WITH_ID(TraceEventCategory::Default, \
TRACE_EVENT_OBJECT_CREATED_WITH_ID(TraceEventCategory::kDefault, \
(*objPtr).GetTypename(), objPtr); \
} while (false)

#define GPGMM_TRACE_EVENT_OBJECT_DESTROY(objPtr) \
do { \
TRACE_EVENT_OBJECT_DELETED_WITH_ID(TraceEventCategory::Default, \
TRACE_EVENT_OBJECT_DELETED_WITH_ID(TraceEventCategory::kDefault, \
(*objPtr).GetTypename(), objPtr); \
} while (false)

#define GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(objPtr, desc) \
do { \
TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( \
TraceEventCategory::Default, (*objPtr).GetTypename(), objPtr, \
TraceEventCategory::kDefault, (*objPtr).GetTypename(), objPtr, \
GPGMM_LAZY_SERIALIZE(desc, IsEventTraceEnabled())); \
} while (false)

#define GPGMM_TRACE_EVENT_OBJECT_CALL(name, desc) \
do { \
TRACE_EVENT_INSTANT1(TraceEventCategory::Default, name, \
TRACE_EVENT_INSTANT1(TraceEventCategory::kDefault, name, \
GPGMM_LAZY_SERIALIZE(desc, IsEventTraceEnabled())); \
} while (false)

Expand All @@ -152,16 +152,16 @@ const uint64_t kNoId = 0;
#define GPGMM_TRACE_EVENT_METRIC(name, value) \
do { \
if (value == 0) break; \
TRACE_COUNTER1(TraceEventCategory::Default, name, value); \
TRACE_COUNTER1(TraceEventCategory::kDefault, name, value); \
} while (false)

#endif

namespace gpgmm {

enum TraceEventCategory {
Default = 0,
Metadata = 1,
enum class TraceEventCategory {
kDefault = 0,
kMetadata = 1,
};

enum TraceEventPhase {
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/common/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace gpgmm {
AsyncEventImpl() = default;

void Wait() override {
TRACE_EVENT0(TraceEventCategory::Default, "AsyncEventImpl.Wait");
TRACE_EVENT0(TraceEventCategory::kDefault, "AsyncEventImpl.Wait");

std::unique_lock<std::mutex> lock(mMutex);
mCondition.wait(lock, [this] { return mIsSignaled; });
Expand Down Expand Up @@ -63,7 +63,7 @@ namespace gpgmm {
std::shared_ptr<Event> event = std::make_shared<AsyncEventImpl>();
std::thread thread([callback, event, name]() {
SetThreadName(name);
TRACE_EVENT_METADATA1(TraceEventCategory::Metadata, "thread_name", "name", name);
TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name", name);
(*callback)();
event->Signal();
});
Expand Down
Loading