Skip to content

Commit

Permalink
Use lf_sleep instead of busywait
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Nov 7, 2024
1 parent 1082131 commit 75df70f
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions core/threaded/scheduler_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,17 @@ void execute_inst_DU(lf_scheduler_t* scheduler, size_t worker_number, operand_t
instant_t current_time = lf_time_physical();
instant_t wakeup_time = *src + op2.imm;
LF_PRINT_DEBUG("DU wakeup time: %lld, base: %lld, offset: %lld", wakeup_time, *src, op2.imm);
// Check if we need to sleep.
instant_t current_time;
_lf_clock_gettime(&current_time);
instant_t wait_interval = wakeup_time - current_time;
// LF_PRINT_DEBUG("*** start_time: %lld, wakeup_time: %lld, op1: %lld, op2: %lld, current_physical_time: %lld\n", start_time, wakeup_time, *src, op2.imm, lf_time_physical());
LF_PRINT_DEBUG("*** [Line %zu] Worker %zu delaying, current_physical_time: %lld, wakeup_time: %lld, wait_interval: %lld", *pc, worker_number, current_time, wakeup_time, wait_interval);
LF_PRINT_DEBUG(
"*** [Line %zu] Worker %zu delaying, current_physical_time: %lld, wakeup_time: %lld, wait_interval: %lld", *pc,
worker_number, current_time, wakeup_time, wait_interval);
if (wait_interval > 0) {
// Approach 1: Only spin when the wait interval is less than SPIN_WAIT_THRESHOLD.
if (wait_interval < SPIN_WAIT_THRESHOLD) {
// Spin wait if the wait interval is less than 1 ms.
while (lf_time_physical() < wakeup_time);
} else {
// Otherwise sleep.
_lf_interruptable_sleep_until_locked(scheduler->env, wakeup_time);
}
// Approach 2: Spin wait.
// while (lf_time_physical() < wakeup_time);
// Recalculate the wakeup time for max accuracy.
_lf_clock_gettime(&current_time);
lf_sleep(wakeup_time - current_time);
}
LF_PRINT_DEBUG("*** [Line %zu] Worker %zu done delaying", *pc, worker_number);
*pc += 1; // Increment pc.
Expand Down

0 comments on commit 75df70f

Please sign in to comment.