Skip to content

Commit d845da0

Browse files
jhawthornivoanjoluke-gru
committed
Force reset running time in timer interrupt
Co-authored-by: Ivo Anjo <ivo.anjo@datadoghq.com> Co-authored-by: Luke Gruber <luke.gru@gmail.com>
1 parent 55c9c75 commit d845da0

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

ractor_core.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,16 @@ rb_ractor_sleeper_thread_num(rb_ractor_t *r)
277277
}
278278

279279
static inline void
280-
rb_ractor_thread_switch(rb_ractor_t *cr, rb_thread_t *th)
280+
rb_ractor_thread_switch(rb_ractor_t *cr, rb_thread_t *th, bool always_reset)
281281
{
282282
RUBY_DEBUG_LOG("th:%d->%u%s",
283283
cr->threads.running_ec ? (int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
284284
rb_th_serial(th), cr->threads.running_ec == th->ec ? " (same)" : "");
285285

286+
if (cr->threads.running_ec != th->ec || always_reset) {
287+
th->running_time_us = 0;
288+
}
289+
286290
if (cr->threads.running_ec != th->ec) {
287291
if (0) {
288292
ruby_debug_printf("rb_ractor_thread_switch ec:%p->%p\n",
@@ -293,10 +297,6 @@ rb_ractor_thread_switch(rb_ractor_t *cr, rb_thread_t *th)
293297
return;
294298
}
295299

296-
if (cr->threads.running_ec != th->ec) {
297-
th->running_time_us = 0;
298-
}
299-
300300
cr->threads.running_ec = th->ec;
301301

302302
VM_ASSERT(cr == GET_RACTOR());

thread.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static inline void blocking_region_end(rb_thread_t *th, struct rb_blocking_regio
173173

174174
#define THREAD_BLOCKING_END(th) \
175175
thread_sched_to_running((sched), (th)); \
176-
rb_ractor_thread_switch(th->ractor, th); \
176+
rb_ractor_thread_switch(th->ractor, th, false); \
177177
} while(0)
178178

179179
#ifdef __GNUC__
@@ -1470,7 +1470,7 @@ rb_thread_schedule_limits(uint32_t limits_us)
14701470

14711471
RB_VM_SAVE_MACHINE_CONTEXT(th);
14721472
thread_sched_yield(TH_SCHED(th), th);
1473-
rb_ractor_thread_switch(th->ractor, th);
1473+
rb_ractor_thread_switch(th->ractor, th, true);
14741474

14751475
RUBY_DEBUG_LOG("switch %s", "done");
14761476
}
@@ -1518,7 +1518,7 @@ blocking_region_end(rb_thread_t *th, struct rb_blocking_region_buffer *region)
15181518
unregister_ubf_list(th);
15191519

15201520
thread_sched_to_running(TH_SCHED(th), th);
1521-
rb_ractor_thread_switch(th->ractor, th);
1521+
rb_ractor_thread_switch(th->ractor, th, false);
15221522

15231523
th->blocking_region_buffer = 0;
15241524
rb_ractor_blocking_threads_dec(th->ractor, __FILE__, __LINE__);

thread_pthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ thread_sched_wait_running_turn(struct rb_thread_sched *sched, rb_thread_t *th, b
859859

860860
RUBY_DEBUG_LOG("(nt) wakeup %s", sched->running == th ? "success" : "failed");
861861
if (th == sched->running) {
862-
rb_ractor_thread_switch(th->ractor, th);
862+
rb_ractor_thread_switch(th->ractor, th, false);
863863
}
864864
}
865865
else {

0 commit comments

Comments
 (0)