Skip to content

Commit d8776f2

Browse files
committed
move Y_LIKELY to AddElapsedCycles and AddParkedCycles
1 parent 407562e commit d8776f2

File tree

4 files changed

+27
-40
lines changed

4 files changed

+27
-40
lines changed

ydb/library/actors/core/executor_pool_io.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,15 @@ namespace NActors {
3939
NHPTimer::STime hpnow = GetCycleCountFast();
4040
NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfElapsingTime(hpnow);
4141
TlsThreadContext->ElapsingActorActivity.store(Max<ui64>(), std::memory_order_release);
42-
if (Y_LIKELY(hpprev < hpnow)) {
43-
wctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
44-
}
42+
wctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
4543

4644
if (threadCtx.WaitingPad.Park())
4745
return 0;
4846

4947
hpnow = GetCycleCountFast();
5048
hpprev = TlsThreadContext->UpdateStartOfElapsingTime(hpnow);
5149
TlsThreadContext->ElapsingActorActivity.store(ActorSystemIndex, std::memory_order_release);
52-
if (Y_LIKELY(hpprev < hpnow)) {
53-
wctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
54-
}
50+
wctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
5551
}
5652

5753
while (!StopFlag.load(std::memory_order_acquire)) {

ydb/library/actors/core/executor_thread.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ namespace NActors {
201201
bool wasWorking = false;
202202
NHPTimer::STime hpnow = Ctx.HPStart;
203203
NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfElapsingTime(hpnow);
204-
if (Y_LIKELY(hpprev < hpnow)) {
205-
Ctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
206-
}
204+
Ctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
207205
NHPTimer::STime eventStart = Ctx.HPStart;
208206

209207
for (; Ctx.ExecutedEvents < Ctx.EventsPerMailbox; ++Ctx.ExecutedEvents) {
@@ -268,9 +266,9 @@ namespace NActors {
268266
if (mailbox->IsEmpty()) // was not-free and become free, we must reclaim mailbox
269267
reclaimAsFree = true;
270268

271-
if (Y_LIKELY(hpprev < hpnow)) {
272-
Ctx.AddEventProcessingStats(hpprev, hpnow, activityType, CurrentActorScheduledEventsCounter);
273-
}
269+
270+
Ctx.AddElapsedCycles(activityType, hpnow - hpprev);
271+
Ctx.AddEventProcessingStats(eventStart, hpnow, activityType, CurrentActorScheduledEventsCounter);
274272
NHPTimer::STime elapsed = hpnow - eventStart;
275273
if (elapsed > 1000000) {
276274
LwTraceSlowEvent(ev.Get(), evTypeForTracing, actorType, Ctx.PoolId, CurrentRecipient, NHPTimer::GetSeconds(elapsed) * 1000.0);
@@ -292,9 +290,7 @@ namespace NActors {
292290
}
293291
hpnow = GetCycleCountFast();
294292
hpprev = TlsThreadContext->UpdateStartOfElapsingTime(hpnow);
295-
if (Y_LIKELY(hpprev < hpnow)) {
296-
Ctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
297-
}
293+
Ctx.AddElapsedCycles(ActorSystemIndex, hpnow - hpprev);
298294
}
299295
eventStart = hpnow;
300296

@@ -786,12 +782,10 @@ namespace NActors {
786782
NHPTimer::STime hpnow = GetCycleCountFast();
787783
ui64 activityType = TlsThreadCtx.ElapsingActorActivity.load(std::memory_order_acquire);
788784
NHPTimer::STime hpprev = TlsThreadCtx.UpdateStartOfElapsingTime(hpnow);
789-
if (Y_LIKELY(hpprev < hpnow)) {
790-
if (activityType == Max<ui64>()) {
791-
Ctx.AddParkedCycles(hpnow - hpprev);
792-
} else {
793-
Ctx.AddElapsedCycles(activityType, hpnow - hpprev);
794-
}
785+
if (activityType == Max<ui64>()) {
786+
Ctx.AddParkedCycles(hpnow - hpprev);
787+
} else {
788+
Ctx.AddElapsedCycles(activityType, hpnow - hpprev);
795789
}
796790
Ctx.GetCurrentStats(statsCopy);
797791
}
@@ -800,12 +794,10 @@ namespace NActors {
800794
NHPTimer::STime hpnow = GetCycleCountFast();
801795
ui64 activityType = TlsThreadCtx.ElapsingActorActivity.load(std::memory_order_acquire);
802796
NHPTimer::STime hpprev = TlsThreadCtx.UpdateStartOfElapsingTime(hpnow);
803-
if (Y_LIKELY(hpprev < hpnow)) {
804-
if (activityType == Max<ui64>()) {
805-
Ctx.AddParkedCycles(hpnow - hpprev);
806-
} else {
807-
Ctx.AddElapsedCycles(activityType, hpnow - hpprev);
808-
}
797+
if (activityType == Max<ui64>()) {
798+
Ctx.AddParkedCycles(hpnow - hpprev);
799+
} else {
800+
Ctx.AddElapsedCycles(activityType, hpnow - hpprev);
809801
}
810802
statsCopy = TExecutorThreadStats();
811803
statsCopy.Aggregate(SharedStats[poolId]);

ydb/library/actors/core/executor_thread_ctx.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,13 @@ namespace NActors {
9999
NHPTimer::STime hpnow = GetCycleCountFast();
100100
NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfElapsingTime(hpnow);
101101
TlsThreadContext->ElapsingActorActivity.store(Max<ui64>(), std::memory_order_release);
102-
if (Y_LIKELY(hpprev < hpnow)) {
103-
TlsThreadContext->WorkerCtx->AddElapsedCycles(TlsThreadContext->ActorSystemIndex, hpnow - hpprev);
104-
}
102+
TlsThreadContext->WorkerCtx->AddElapsedCycles(TlsThreadContext->ActorSystemIndex, hpnow - hpprev);
105103
do {
106104
if (WaitingPad.Park()) // interrupted
107105
return true;
108106
hpnow = GetCycleCountFast();
109107
hpprev = TlsThreadContext->UpdateStartOfElapsingTime(hpnow);
110-
if (Y_LIKELY(hpprev < hpnow)) {
111-
TlsThreadContext->WorkerCtx->AddParkedCycles(hpnow - hpprev);
112-
}
108+
TlsThreadContext->WorkerCtx->AddParkedCycles(hpnow - hpprev);
113109
state = GetState<TWaitState>();
114110
} while (static_cast<EThreadState>(state) == EThreadState::Sleep && !stopFlag->load(std::memory_order_relaxed));
115111
TlsThreadContext->ElapsingActorActivity.store(TlsThreadContext->ActorSystemIndex, std::memory_order_release);

ydb/library/actors/core/worker_context.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ namespace NActors {
6161
}
6262

6363
void AddElapsedCycles(ui32 activityType, i64 elapsed) {
64-
Y_DEBUG_ABORT_UNLESS(activityType < Stats->MaxActivityType());
65-
RelaxedStore(&Stats->ElapsedTicks, RelaxedLoad(&Stats->ElapsedTicks) + elapsed);
66-
RelaxedStore(&Stats->ElapsedTicksByActivity[activityType], RelaxedLoad(&Stats->ElapsedTicksByActivity[activityType]) + elapsed);
64+
if (Y_LIKELY(elapsed > 0)) {
65+
Y_DEBUG_ABORT_UNLESS(activityType < Stats->MaxActivityType());
66+
RelaxedStore(&Stats->ElapsedTicks, RelaxedLoad(&Stats->ElapsedTicks) + elapsed);
67+
RelaxedStore(&Stats->ElapsedTicksByActivity[activityType], RelaxedLoad(&Stats->ElapsedTicksByActivity[activityType]) + elapsed);
68+
}
6769
}
6870

6971
void AddParkedCycles(i64 elapsed) {
70-
RelaxedStore(&Stats->ParkedTicks, RelaxedLoad(&Stats->ParkedTicks) + elapsed);
72+
if (Y_LIKELY(elapsed > 0)) {
73+
RelaxedStore(&Stats->ParkedTicks, RelaxedLoad(&Stats->ParkedTicks) + elapsed);
74+
}
7175
}
7276

7377
void AddBlockedCycles(i64 elapsed) {
@@ -127,7 +131,7 @@ namespace NActors {
127131
return usecDeliv;
128132
}
129133

130-
i64 AddEventProcessingStats(i64 deliveredTs, i64 processedTs, ui32 activityType, ui64 scheduled) {
134+
i64 AddEventProcessingStats(i64 deliveredTs, i64 processedTs, ui32 activityType) {
131135
i64 elapsed = processedTs - deliveredTs;
132136
ui64 usecElapsed = NHPTimer::GetSeconds(elapsed) * 1000000;
133137
activityType = (activityType >= Stats->MaxActivityType()) ? 0 : activityType;
@@ -136,8 +140,7 @@ namespace NActors {
136140
RelaxedStore(&Stats->ReceivedEvents, RelaxedLoad(&Stats->ReceivedEvents) + 1);
137141
RelaxedStore(&Stats->ReceivedEventsByActivity[activityType], RelaxedLoad(&Stats->ReceivedEventsByActivity[activityType]) + 1);
138142
RelaxedStore(&Stats->ScheduledEventsByActivity[activityType], RelaxedLoad(&Stats->ScheduledEventsByActivity[activityType]) + scheduled);
139-
AddElapsedCycles(activityType, elapsed);
140-
return elapsed;
143+
return std::max<i64>(0, elapsed);
141144
}
142145

143146
void UpdateActorsStats(size_t dyingActorsCnt) {

0 commit comments

Comments
 (0)