@@ -48,6 +48,7 @@ namespace NActors {
48
48
, ThreadName (threadName)
49
49
, TimePerMailbox (timePerMailbox)
50
50
, EventsPerMailbox (eventsPerMailbox)
51
+ , ActorSystemIndex (TActorTypeOperator::GetActorSystemIndex ())
51
52
{
52
53
Ctx.Switch (
53
54
ExecutorPool,
@@ -75,6 +76,7 @@ namespace NActors {
75
76
, EventsPerMailbox (eventsPerMailbox)
76
77
, SoftProcessingDurationTs (softProcessingDurationTs)
77
78
, SharedStats (poolCount)
79
+ , ActorSystemIndex (TActorTypeOperator::GetActorSystemIndex ())
78
80
{
79
81
Ctx.Switch (
80
82
ExecutorPool,
@@ -189,7 +191,6 @@ namespace NActors {
189
191
Ctx.HPStart = GetCycleCountFast ();
190
192
Ctx.ExecutedEvents = 0 ;
191
193
}
192
- NHPTimer::STime hpprev = Ctx.HPStart ;
193
194
194
195
IActor* actor = nullptr ;
195
196
const std::type_info* actorType = nullptr ;
@@ -198,10 +199,14 @@ namespace NActors {
198
199
bool firstEvent = true ;
199
200
bool preempted = false ;
200
201
bool wasWorking = false ;
202
+ NHPTimer::STime hpnow = Ctx.HPStart ;
203
+ NHPTimer::STime hpprev = TlsThreadContext->StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
204
+ Ctx.AddElapsedCycles (ActorSystemIndex, hpnow - hpprev);
205
+ hpprev = Ctx.HPStart ;
206
+
201
207
for (; Ctx.ExecutedEvents < Ctx.EventsPerMailbox ; ++Ctx.ExecutedEvents ) {
202
208
if (TAutoPtr<IEventHandle> evExt = mailbox->Pop ()) {
203
209
mailbox->ProcessEvents (mailbox);
204
- NHPTimer::STime hpnow;
205
210
recipient = evExt->GetRecipientRewrite ();
206
211
TActorContext ctx (*mailbox, *this , hpprev, recipient);
207
212
TlsActivationContext = &ctx; // ensure dtor (if any) is called within actor system
@@ -239,9 +244,14 @@ namespace NActors {
239
244
if (activityType != prevActivityType) {
240
245
prevActivityType = activityType;
241
246
NProfiling::TMemoryTagScope::Reset (activityType);
247
+ TlsThreadContext->ElapsingActorActivity .store (activityType, std::memory_order_release);
242
248
}
243
249
244
250
actor->Receive (ev);
251
+
252
+ hpnow = GetCycleCountFast ();
253
+ hpprev = TlsThreadContext->StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
254
+
245
255
mailbox->ProcessEvents (mailbox);
246
256
actor->OnDequeueEvent ();
247
257
@@ -256,7 +266,6 @@ namespace NActors {
256
266
if (mailbox->IsEmpty ()) // was not-free and become free, we must reclaim mailbox
257
267
reclaimAsFree = true ;
258
268
259
- hpnow = GetCycleCountFast ();
260
269
NHPTimer::STime elapsed = Ctx.AddEventProcessingStats (hpprev, hpnow, activityType, CurrentActorScheduledEventsCounter);
261
270
if (elapsed > 1000000 ) {
262
271
LwTraceSlowEvent (ev.Get (), evTypeForTracing, actorType, Ctx.PoolId , CurrentRecipient, NHPTimer::GetSeconds (elapsed) * 1000.0 );
@@ -277,10 +286,10 @@ namespace NActors {
277
286
Ctx.IncrementNonDeliveredEvents ();
278
287
}
279
288
hpnow = GetCycleCountFast ();
289
+ hpprev = TlsThreadContext->StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
290
+ Ctx.AddElapsedCycles (ActorSystemIndex, hpnow - hpprev);
280
291
}
281
292
282
- hpprev = hpnow;
283
-
284
293
if (TlsThreadContext->CapturedType == ESendingType::Tail) {
285
294
AtomicStore (&mailbox->ScheduleMoment , hpnow);
286
295
Ctx.IncrementMailboxPushedOutByTailSending ();
@@ -360,6 +369,7 @@ namespace NActors {
360
369
break ; // empty queue, leave
361
370
}
362
371
}
372
+ TlsThreadContext->ElapsingActorActivity .store (ActorSystemIndex, std::memory_order_release);
363
373
364
374
NProfiling::TMemoryTagScope::Reset (0 );
365
375
TlsActivationContext = nullptr ;
@@ -495,8 +505,11 @@ namespace NActors {
495
505
ThreadDisableBalloc ();
496
506
#endif
497
507
498
- TThreadContext threadCtx;
499
- TlsThreadContext = &threadCtx;
508
+ TlsThreadCtx.WorkerCtx = &Ctx;
509
+ TlsThreadCtx.ActorSystemIndex = ActorSystemIndex;
510
+ TlsThreadCtx.ElapsingActorActivity = ActorSystemIndex;
511
+ TlsThreadCtx.StartOfElapsingTime = GetCycleCountFast ();
512
+ TlsThreadContext = &TlsThreadCtx;
500
513
if (ThreadName) {
501
514
::SetCurrentThreadName (ThreadName);
502
515
}
@@ -529,8 +542,11 @@ namespace NActors {
529
542
ThreadDisableBalloc ();
530
543
#endif
531
544
532
- TThreadContext threadCtx;
533
- TlsThreadContext = &threadCtx;
545
+ TlsThreadCtx.WorkerCtx = &Ctx;
546
+ TlsThreadCtx.ActorSystemIndex = ActorSystemIndex;
547
+ TlsThreadCtx.ElapsingActorActivity = ActorSystemIndex;
548
+ TlsThreadCtx.StartOfElapsingTime = GetCycleCountFast ();
549
+ TlsThreadContext = &TlsThreadCtx;
534
550
if (ThreadName) {
535
551
::SetCurrentThreadName (ThreadName);
536
552
}
@@ -551,7 +567,7 @@ namespace NActors {
551
567
}
552
568
553
569
if (!wasWorking && !StopFlag.load (std::memory_order_relaxed)) {
554
- TlsThreadContext-> Timers . Reset ();
570
+ ThreadCtx-> UnsetWork ();
555
571
ThreadCtx->Wait (0 , &StopFlag);
556
572
}
557
573
@@ -760,10 +776,26 @@ namespace NActors {
760
776
}
761
777
762
778
void TGenericExecutorThread::GetCurrentStats (TExecutorThreadStats& statsCopy) const {
779
+ NHPTimer::STime hpnow = GetCycleCountFast ();
780
+ ui64 activityType = TlsThreadCtx.ElapsingActorActivity .load (std::memory_order_acquire);
781
+ NHPTimer::STime hpprev = TlsThreadCtx.StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
782
+ if (activityType == Max<ui64>()) {
783
+ Ctx.AddParkedCycles (hpnow - hpprev);
784
+ } else {
785
+ Ctx.AddElapsedCycles (activityType, hpnow - hpprev);
786
+ }
763
787
Ctx.GetCurrentStats (statsCopy);
764
788
}
765
789
766
790
void TGenericExecutorThread::GetSharedStats (i16 poolId, TExecutorThreadStats &statsCopy) const {
791
+ NHPTimer::STime hpnow = GetCycleCountFast ();
792
+ ui64 activityType = TlsThreadCtx.ElapsingActorActivity .load (std::memory_order_acquire);
793
+ NHPTimer::STime hpprev = TlsThreadCtx.StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
794
+ if (activityType == Max<ui64>()) {
795
+ Ctx.AddParkedCycles (hpnow - hpprev);
796
+ } else {
797
+ Ctx.AddElapsedCycles (activityType, hpnow - hpprev);
798
+ }
767
799
statsCopy = TExecutorThreadStats ();
768
800
statsCopy.Aggregate (SharedStats[poolId]);
769
801
}
0 commit comments