Skip to content

Commit e30d88f

Browse files
committed
ThreadFilter optim - fixes
- Fix removal of self in timerloop init it was not using a slotID but a thread ID - Add assertion to find other potential issues
1 parent 658097d commit e30d88f

File tree

6 files changed

+24
-122
lines changed

6 files changed

+24
-122
lines changed

ddprof-lib/src/main/cpp/branch_hints.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

ddprof-lib/src/main/cpp/javaApi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <assert.h>
1818

19-
#include "branch_hints.h"
19+
#include "arch_dd.h"
2020
#include "context.h"
2121
#include "counters.h"
2222
#include "engine.h"

ddprof-lib/src/main/cpp/threadFilter.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
// - These methods assume slot_id comes from registerThread() (undefined behavior otherwise)
2121

2222
#include "threadFilter.h"
23-
#include "branch_hints.h"
23+
#include "arch_dd.h"
2424

25+
#include <cassert>
2526
#include <cstdlib>
27+
#include <cstdio>
2628
#include <thread>
2729
#include <algorithm>
2830
#include <cstring>
@@ -181,10 +183,17 @@ void ThreadFilter::remove(SlotID slot_id) {
181183
int chunk_idx = slot_id >> kChunkShift;
182184
int slot_idx = slot_id & kChunkMask;
183185

186+
if (unlikely(chunk_idx >= kMaxChunks)) {
187+
assert(false, "Invalid slot_id=%d, chunk_idx=%d (max=%d), slot_idx=%d", slot_id, chunk_idx, kMaxChunks, slot_idx);
188+
return;
189+
}
190+
184191
ChunkStorage* chunk = _chunks[chunk_idx].load(std::memory_order_relaxed);
185-
if (likely(chunk != nullptr)) {
186-
chunk->slots[slot_idx].value.store(-1, std::memory_order_release);
192+
if (unlikely(chunk == nullptr)) {
193+
return;
187194
}
195+
196+
chunk->slots[slot_idx].value.store(-1, std::memory_order_release);
188197
}
189198

190199
void ThreadFilter::unregisterThread(SlotID slot_id) {

ddprof-lib/src/main/cpp/threadIdTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <atomic>
2121
#include <unordered_set>
22-
#include "branch_hints.h"
22+
#include "arch_dd.h"
2323

2424
// Simple fixed size thread ID table
2525
class ThreadIdTable {

ddprof-lib/src/main/cpp/wallClock.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "os.h"
2222
#include "profiler.h"
2323
#include "reservoirSampler.h"
24+
#include "thread.h"
2425
#include "threadFilter.h"
2526
#include "threadState.h"
2627
#include "tsc.h"
@@ -67,7 +68,15 @@ class BaseWallClock : public Engine {
6768
threads.reserve(reservoirSize);
6869
int self = OS::threadId();
6970
ThreadFilter* thread_filter = Profiler::instance()->threadFilter();
70-
thread_filter->remove(self);
71+
72+
// We don't want to profile ourselves in wall time
73+
ProfiledThread* current = ProfiledThread::current();
74+
if (current != nullptr) {
75+
int slot_id = current->filterSlotId();
76+
if (slot_id != -1) {
77+
thread_filter->remove(slot_id);
78+
}
79+
}
7180

7281
u64 startTime = TSC::ticks();
7382
WallClockEpochEvent epoch(startTime);

ddprof-lib/src/test/cpp/branch_hints_ut.cpp

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)