Skip to content

Commit 9487229

Browse files
authored
[NFC][OMPT] Refactor to follow naming convention (llvm#4073)
2 parents 1cc03b2 + 1dccf91 commit 9487229

File tree

2 files changed

+76
-76
lines changed

2 files changed

+76
-76
lines changed

offload/include/OpenMP/OMPT/OmptTracingBuffer.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class OmptTracingBufferMgr {
7979
*
8080
* Id, DeviceId, Start, and TotalBytes are not changed once set.
8181
* RemainingBytes could be written multiple times but only by the same
82-
* thread. But Cursor and isFull may be read/written by an OpenMP worker
82+
* thread. But Cursor and IsFull may be read/written by an OpenMP worker
8383
* thread and read by helper threads. Hence, accesses of
8484
* this 2nd set of locations need to be atomic or synchronized.
8585
*/
@@ -91,12 +91,12 @@ class OmptTracingBufferMgr {
9191
size_t RemainingBytes; // Total number of unused bytes
9292
// corresponding to Cursor
9393
std::atomic<void *> Cursor; // Address of the last trace record carved out
94-
std::atomic<bool> isFull; // true if no more trace records can be
94+
std::atomic<bool> IsFull; // true if no more trace records can be
9595
// accomodated, otherwise false
9696
Buffer(uint64_t BufId, int64_t DevId, void *S, size_t Bytes, size_t Rem,
9797
void *C, bool F)
9898
: Id(BufId), DeviceId(DevId), Start(S), TotalBytes(Bytes),
99-
RemainingBytes(Rem), Cursor(C), isFull(F) {}
99+
RemainingBytes(Rem), Cursor(C), IsFull(F) {}
100100
Buffer() = delete;
101101
Buffer(const Buffer &) = delete;
102102
Buffer &operator=(const Buffer &) = delete;
@@ -152,8 +152,8 @@ class OmptTracingBufferMgr {
152152
void *FlushCursor;
153153
BufPtr FlushBuf;
154154
FlushInfo() = default;
155-
FlushInfo(uint64_t id, void *cr, BufPtr buf)
156-
: FlushId{id}, FlushCursor{cr}, FlushBuf{buf} {}
155+
FlushInfo(uint64_t Id, void *CR, BufPtr Buf)
156+
: FlushId{Id}, FlushCursor{CR}, FlushBuf{Buf} {}
157157
};
158158

159159
/*
@@ -171,8 +171,8 @@ class OmptTracingBufferMgr {
171171
void *FlushCursor;
172172
BufPtr FlushBuf;
173173
BufferFlushStatus FlushStatus;
174-
FlushMd(void *cr, BufPtr buf, BufferFlushStatus status)
175-
: FlushCursor{cr}, FlushBuf{buf}, FlushStatus{status} {}
174+
FlushMd(void *CR, BufPtr Buf, BufferFlushStatus Status)
175+
: FlushCursor{CR}, FlushBuf{Buf}, FlushStatus{Status} {}
176176
FlushMd() = delete;
177177
};
178178

@@ -232,20 +232,20 @@ class OmptTracingBufferMgr {
232232
void flushBuffer(FlushInfo);
233233

234234
// Dispatch a buffer-completion callback with a range of trace records
235-
void dispatchCallback(int64_t DeviceId, void *buffer, void *first_cursor,
236-
void *last_cursor);
235+
void dispatchCallback(int64_t DeviceId, void *Buffer, void *FirstCursor,
236+
void *LastCursor);
237237

238238
// Add a last cursor
239-
void addLastCursor(void *cursor) {
239+
void addLastCursor(void *Cursor) {
240240
std::unique_lock<std::mutex> Lock(LastCursorMutex);
241-
LastCursors.emplace(cursor);
241+
LastCursors.emplace(Cursor);
242242
}
243243

244244
// Remove a last cursor
245-
void removeLastCursor(void *cursor) {
245+
void removeLastCursor(void *Cursor) {
246246
std::unique_lock<std::mutex> Lock(LastCursorMutex);
247-
assert(LastCursors.find(cursor) != LastCursors.end());
248-
LastCursors.erase(cursor);
247+
assert(LastCursors.find(Cursor) != LastCursors.end());
248+
LastCursors.erase(Cursor);
249249
}
250250

251251
// Given a trace record pointer, initialize its metadata
@@ -257,7 +257,7 @@ class OmptTracingBufferMgr {
257257

258258
// Reserve a candidate buffer for flushing, preventing other helper threads
259259
// from accessing it
260-
FlushInfo findAndReserveFlushedBuf(uint64_t id);
260+
FlushInfo findAndReserveFlushedBuf(uint64_t FlushId);
261261

262262
// Unreserve a buffer so that other helper threads can process it
263263
void unreserveFlushedBuf(const FlushInfo &);
@@ -266,10 +266,10 @@ class OmptTracingBufferMgr {
266266
void destroyFlushedBuf(const FlushInfo &);
267267

268268
// Add a new buffer by an OpenMP thread so that a helper thread can process it
269-
uint64_t addNewFlushEntry(BufPtr buf, void *cursor);
269+
uint64_t addNewFlushEntry(BufPtr Buf, void *Cursor);
270270

271271
// Get the next trace record
272-
void *getNextTR(void *tr);
272+
void *getNextTR(void *TR);
273273

274274
// Given a buffer, return the latest cursor
275275
void *getBufferCursor(BufPtr);
@@ -295,45 +295,45 @@ class OmptTracingBufferMgr {
295295

296296
// Given a thread number, set the corresponding bit in the flush
297297
// tracker. The caller must hold the flush lock.
298-
void setThreadFlush(uint32_t thd_num) {
299-
ThreadFlushTracker |= (1 << thd_num);
298+
void setThreadFlush(uint32_t ThreadNum) {
299+
ThreadFlushTracker |= (1 << ThreadNum);
300300
}
301301

302302
// Reset this thread's flush bit. The caller must hold the flush lock
303303
void resetThisThreadFlush() {
304-
std::thread::id id = std::this_thread::get_id();
305-
assert(HelperThreadIdMap.find(id) != HelperThreadIdMap.end());
306-
ThreadFlushTracker &= ~(1 << HelperThreadIdMap[id]);
304+
std::thread::id ID = std::this_thread::get_id();
305+
assert(HelperThreadIdMap.find(ID) != HelperThreadIdMap.end());
306+
ThreadFlushTracker &= ~(1 << HelperThreadIdMap[ID]);
307307
}
308308

309309
// Given a thread number, set the corresponding bit in the shutdown
310310
// tracker. The caller must hold the flush lock.
311-
void setThreadShutdown(uint32_t thd_num) {
312-
ThreadShutdownTracker |= (1 << thd_num);
311+
void setThreadShutdown(uint32_t ThreadNum) {
312+
ThreadShutdownTracker |= (1 << ThreadNum);
313313
}
314314

315315
// Reset this thread's shutdown bit. The caller must hold the flush
316316
// lock
317317
void resetThisThreadShutdown() {
318-
std::thread::id id = std::this_thread::get_id();
319-
assert(HelperThreadIdMap.find(id) != HelperThreadIdMap.end());
320-
ThreadShutdownTracker &= ~(1 << HelperThreadIdMap[id]);
318+
std::thread::id ID = std::this_thread::get_id();
319+
assert(HelperThreadIdMap.find(ID) != HelperThreadIdMap.end());
320+
ThreadShutdownTracker &= ~(1 << HelperThreadIdMap[ID]);
321321
}
322322

323323
// Return true if this thread's flush bit is set. The caller must
324324
// hold the flush lock
325325
bool isThisThreadFlushWaitedUpon() {
326-
std::thread::id id = std::this_thread::get_id();
327-
assert(HelperThreadIdMap.find(id) != HelperThreadIdMap.end());
328-
return (ThreadFlushTracker & (1 << HelperThreadIdMap[id])) != 0;
326+
std::thread::id ID = std::this_thread::get_id();
327+
assert(HelperThreadIdMap.find(ID) != HelperThreadIdMap.end());
328+
return (ThreadFlushTracker & (1 << HelperThreadIdMap[ID])) != 0;
329329
}
330330

331331
// Return true if this thread's shutdown bit is set. The caller must
332332
// hold the flush lock
333333
bool isThisThreadShutdownWaitedUpon() {
334-
std::thread::id id = std::this_thread::get_id();
335-
assert(HelperThreadIdMap.find(id) != HelperThreadIdMap.end());
336-
return (ThreadShutdownTracker & (1 << HelperThreadIdMap[id])) != 0;
334+
std::thread::id ID = std::this_thread::get_id();
335+
assert(HelperThreadIdMap.find(ID) != HelperThreadIdMap.end());
336+
return (ThreadShutdownTracker & (1 << HelperThreadIdMap[ID])) != 0;
337337
}
338338

339339
// The caller must not hold the flush lock

offload/libomptarget/OpenMP/OMPT/OmptTracingBuffer.cpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
#include <limits>
2323

2424
// When set to true, helper threads terminate their work
25-
static bool done_tracing{false};
25+
static bool DoneTracing{false};
2626

2727
// Unique buffer id in creation order
28-
static std::atomic<uint64_t> buf_id{0};
28+
static std::atomic<uint64_t> BufId{0};
2929

3030
// Unique id in buffer flush order
31-
static std::atomic<uint64_t> flush_id{0};
31+
static std::atomic<uint64_t> FlushId{0};
3232

3333
thread_local OmptTracingBufferMgr::BufPtr
3434
OmptTracingBufferMgr::ArrayOfBufPtr[MAX_NUM_DEVICES];
3535

36-
static uint64_t get_and_inc_buf_id() { return buf_id++; }
36+
static uint64_t get_and_inc_buf_id() { return BufId++; }
3737

38-
static uint64_t get_and_inc_flush_id() { return flush_id++; }
39-
static uint64_t get_flush_id() { return flush_id; }
38+
static uint64_t get_and_inc_flush_id() { return FlushId++; }
39+
static uint64_t get_flush_id() { return FlushId; }
4040

4141
/*
4242
* Used by OpenMP threads for assigning space for a trace record. If
@@ -97,7 +97,7 @@ void *OmptTracingBufferMgr::assignCursor(ompt_callbacks_t Type,
9797
// because the helper thread uses this info to decide whether a buffer
9898
// can be scheduled for removal. In the worst case, the buffer will be
9999
// removed late.
100-
DeviceBuf->isFull.store(true, std::memory_order_release);
100+
DeviceBuf->IsFull.store(true, std::memory_order_release);
101101
}
102102
}
103103
void *NewBuffer = nullptr;
@@ -115,7 +115,7 @@ void *OmptTracingBufferMgr::assignCursor(ompt_callbacks_t Type,
115115
NewBufId, DeviceId, /*Start=*/NewBuffer, TotalBytes,
116116
/*RemainingBytes=*/TotalBytes - RecSize,
117117
/*Cursor=*/NewBuffer,
118-
/*isFull=*/false);
118+
/*IsFull=*/false);
119119

120120
// Initialize trace record status before publishing it to helper threads.
121121
initTraceRecordMetaData(new_buf->Cursor.load(std::memory_order_acquire));
@@ -142,7 +142,7 @@ void *OmptTracingBufferMgr::assignCursor(ompt_callbacks_t Type,
142142

143143
/*
144144
* Called by an OpenMP thread when a buffer fills up and should be
145-
* flushed. This function assigns a new flush_id to the buffer, adds
145+
* flushed. This function assigns a new FlushId to the buffer, adds
146146
* to the flush-related metadata and wakes up a helper thread to
147147
* dispatch a buffer-completion callback. This function should be
148148
* called without holding any lock.
@@ -191,15 +191,15 @@ void OmptTracingBufferMgr::driveCompletion() {
191191
while (true) {
192192
bool should_signal_workers = false;
193193
std::unique_lock<std::mutex> flush_lock(FlushMutex);
194-
if (done_tracing) {
194+
if (DoneTracing) {
195195
// An upper layer serializes flush_trace and stop_trace. In
196-
// addition, before done_tracing is set, a flush is performed as
196+
// addition, before DoneTracing is set, a flush is performed as
197197
// part of stop_trace. So assert that no flush is in progress.
198198
assert(ThreadFlushTracker == 0);
199199
break;
200200
}
201201
FlushCv.wait(flush_lock, [this] {
202-
return done_tracing ||
202+
return DoneTracing ||
203203
(!Id2FlushMdMap.empty() &&
204204
llvm::omp::target::ompt::TracingActive) ||
205205
isThisThreadFlushWaitedUpon();
@@ -225,7 +225,7 @@ void OmptTracingBufferMgr::driveCompletion() {
225225
}
226226
bool is_last_helper = false;
227227
std::unique_lock<std::mutex> flush_lock(FlushMutex);
228-
assert(done_tracing && "Helper thread exiting but not yet done");
228+
assert(DoneTracing && "Helper thread exiting but not yet done");
229229
assert(isThisThreadShutdownWaitedUpon() &&
230230
"Helper thread exiting but not waited upon");
231231
resetThisThreadShutdown();
@@ -362,28 +362,28 @@ void OmptTracingBufferMgr::flushBuffer(FlushInfo flush_info) {
362362
}
363363

364364
// Given a range of trace records, dispatch a buffer-completion callback
365-
void OmptTracingBufferMgr::dispatchCallback(int64_t DeviceId, void *buffer,
366-
void *first_cursor,
367-
void *last_cursor) {
368-
assert(first_cursor != nullptr && last_cursor != nullptr &&
365+
void OmptTracingBufferMgr::dispatchCallback(int64_t DeviceId, void *Buffer,
366+
void *FirstCursor,
367+
void *LastCursor) {
368+
assert(FirstCursor != nullptr && LastCursor != nullptr &&
369369
"Callback with nullptr");
370-
addLastCursor(last_cursor);
370+
addLastCursor(LastCursor);
371371

372372
// This is best effort.
373373
// There is a small window when the buffer-completion callback may
374374
// be invoked even after tracing has been disabled.
375375
// Note that we don't want to hold a lock when dispatching the callback.
376376
if (llvm::omp::target::ompt::isTracedDevice(DeviceId)) {
377377
DP("Dispatch callback w/ range (inclusive) to be flushed: %p -> %p\n",
378-
first_cursor, last_cursor);
378+
FirstCursor, LastCursor);
379379
llvm::omp::target::ompt::ompt_callback_buffer_complete(
380-
DeviceId, buffer,
380+
DeviceId, Buffer,
381381
/* bytes returned in this callback */
382-
(char *)getNextTR(last_cursor) - (char *)first_cursor,
383-
(ompt_buffer_cursor_t)first_cursor, false /* buffer_owned */);
382+
(char *)getNextTR(LastCursor) - (char *)FirstCursor,
383+
(ompt_buffer_cursor_t)FirstCursor, false /* buffer_owned */);
384384
}
385385

386-
removeLastCursor(last_cursor);
386+
removeLastCursor(LastCursor);
387387
}
388388

389389
// Dispatch a buffer-completion callback with buffer_owned set so that
@@ -438,15 +438,15 @@ OmptTracingBufferMgr::TRStatus OmptTracingBufferMgr::getTRStatus(void *Rec) {
438438
std::memory_order_acquire);
439439
}
440440

441-
void *OmptTracingBufferMgr::getNextTR(void *Rec) {
442-
size_t rec_size = getTRSize();
441+
void *OmptTracingBufferMgr::getNextTR(void *TR) {
442+
size_t RecSize = getTRSize();
443443
// warning: no overflow check done
444-
return (char *)Rec + rec_size;
444+
return (char *)TR + RecSize;
445445
}
446446

447447
bool OmptTracingBufferMgr::isBufferFull(const FlushInfo &flush_info) {
448448
std::unique_lock<std::mutex> buf_lock(BufferMgrMutex);
449-
return flush_info.FlushBuf->isFull;
449+
return flush_info.FlushBuf->IsFull;
450450
}
451451

452452
void *OmptTracingBufferMgr::getBufferCursor(BufPtr buf) {
@@ -484,10 +484,10 @@ bool OmptTracingBufferMgr::isBufferOwned(const FlushInfo &flush_info) {
484484
* list of buffers to be flushed.
485485
*/
486486
OmptTracingBufferMgr::FlushInfo
487-
OmptTracingBufferMgr::findAndReserveFlushedBuf(uint64_t flush_id) {
487+
OmptTracingBufferMgr::findAndReserveFlushedBuf(uint64_t FlushId) {
488488
std::unique_lock<std::mutex> flush_lock(FlushMutex);
489489
MapId2Md::iterator flush_itr;
490-
if (flush_id == std::numeric_limits<uint64_t>::max()) {
490+
if (FlushId == std::numeric_limits<uint64_t>::max()) {
491491
// Reserve the first waiting buffer and return it
492492
if (Id2FlushMdMap.empty())
493493
return FlushInfo();
@@ -500,7 +500,7 @@ OmptTracingBufferMgr::findAndReserveFlushedBuf(uint64_t flush_id) {
500500
if (flush_itr == Id2FlushMdMap.end())
501501
return FlushInfo();
502502
} else {
503-
flush_itr = Id2FlushMdMap.find(flush_id);
503+
flush_itr = Id2FlushMdMap.find(FlushId);
504504
if (flush_itr == Id2FlushMdMap.end() ||
505505
flush_itr->second.FlushStatus == Flush_processing)
506506
return FlushInfo();
@@ -562,16 +562,16 @@ void OmptTracingBufferMgr::destroyFlushedBuf(const FlushInfo &flush_info) {
562562
* Generate a new flush id and add the buffer to the flush metadata
563563
* maps. This function must be called while holding the flush lock.
564564
*/
565-
uint64_t OmptTracingBufferMgr::addNewFlushEntry(BufPtr buf, void *cursor) {
566-
assert(FlushBufPtr2IdMap.find(buf) == FlushBufPtr2IdMap.end());
567-
uint64_t flush_id = get_and_inc_flush_id();
568-
FlushBufPtr2IdMap.emplace(buf, flush_id);
569-
assert(Id2FlushMdMap.find(flush_id) == Id2FlushMdMap.end());
570-
Id2FlushMdMap.emplace(flush_id, FlushMd(cursor, buf, Flush_waiting));
565+
uint64_t OmptTracingBufferMgr::addNewFlushEntry(BufPtr Buf, void *Cursor) {
566+
assert(FlushBufPtr2IdMap.find(Buf) == FlushBufPtr2IdMap.end());
567+
uint64_t FlushId = get_and_inc_flush_id();
568+
FlushBufPtr2IdMap.emplace(Buf, FlushId);
569+
assert(Id2FlushMdMap.find(FlushId) == Id2FlushMdMap.end());
570+
Id2FlushMdMap.emplace(FlushId, FlushMd(Cursor, Buf, Flush_waiting));
571571

572-
DP("Added new flush id %lu cursor %p buf %p\n", flush_id, cursor, buf->Start);
572+
DP("Added new flush id %lu cursor %p buf %p\n", FlushId, Cursor, Buf->Start);
573573

574-
return flush_id;
574+
return FlushId;
575575
}
576576

577577
/*
@@ -674,7 +674,7 @@ void OmptTracingBufferMgr::init() {
674674
ArrayOfBufPtr[i] = nullptr;
675675
ThreadFlushTracker = 0;
676676
ThreadShutdownTracker = 0;
677-
done_tracing = false; // TODO make it a class member
677+
DoneTracing = false; // TODO make it a class member
678678
}
679679

680680
void OmptTracingBufferMgr::startHelperThreads() {
@@ -683,7 +683,7 @@ void OmptTracingBufferMgr::startHelperThreads() {
683683
// repeated calls to start-trace.
684684
std::unique_lock<std::mutex> flush_lock(FlushMutex);
685685
if (!HelperThreadIdMap.empty()) {
686-
assert(!done_tracing && "Helper threads exist but tracing is done");
686+
assert(!DoneTracing && "Helper threads exist but tracing is done");
687687
return;
688688
}
689689
init();
@@ -692,7 +692,7 @@ void OmptTracingBufferMgr::startHelperThreads() {
692692

693693
bool OmptTracingBufferMgr::areHelperThreadsAvailable() {
694694
std::unique_lock<std::mutex> flush_lock(FlushMutex);
695-
if (done_tracing // If another thread called stop, assume there are no threads
695+
if (DoneTracing // If another thread called stop, assume there are no threads
696696
|| HelperThreadIdMap.empty() // Threads were never started
697697
) {
698698
// Don't assert on HelperThreadIdMap since shutdown by another
@@ -713,11 +713,11 @@ void OmptTracingBufferMgr::shutdownHelperThreads() {
713713
assert(ThreadShutdownTracker == 0);
714714

715715
// Set the done flag which helper threads will look at
716-
done_tracing = true;
716+
DoneTracing = true;
717717
// Wait to make sure all helper threads exit
718718
for (uint32_t i = 0; i < OMPT_NUM_HELPER_THREADS; ++i)
719719
setThreadShutdown(i);
720-
// Signal indicating that done_tracing is set
720+
// Signal indicating that DoneTracing is set
721721
FlushCv.notify_all();
722722
ThreadShutdownCv.wait(flush_lock,
723723
[this] { return ThreadShutdownTracker == 0; });

0 commit comments

Comments
 (0)