Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STATIC SCHEDULER] Use lf_sleep instead of busywait #495

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions core/threaded/scheduler_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,27 +275,20 @@ void execute_inst_DU(lf_scheduler_t* scheduler, size_t worker_number, operand_t
int pc_orig = (int) *pc;
tracepoint_static_scheduler_DU_starts(worker_number, pc_orig);
#endif
// FIXME: There seems to be an overflow problem.
// When wakeup_time overflows but lf_time_physical() doesn't,
// _lf_interruptable_sleep_until_locked() terminates immediately.
reg_t *src = op1.reg;
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
Loading