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

runtime: don't call sleepTicks with a negative duration #4569

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions builder/sizes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func TestBinarySize(t *testing.T) {
// This is a small number of very diverse targets that we want to test.
tests := []sizeTest{
// microcontrollers
{"hifive1b", "examples/echo", 4568, 280, 0, 2268},
{"microbit", "examples/serial", 2868, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 6104, 1484, 116, 6832},
{"hifive1b", "examples/echo", 4580, 280, 0, 2268},
{"microbit", "examples/serial", 2888, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 6124, 1484, 116, 6832},

// TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the
Expand Down
22 changes: 10 additions & 12 deletions src/runtime/runtime_mimxrt1062_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,17 @@ func ticks() timeUnit {
}

func sleepTicks(duration timeUnit) {
if duration >= 0 {
curr := ticks()
last := curr + duration // 64-bit overflow unlikely
for curr < last {
cycles := timeUnit((last - curr) / pitCyclesPerMicro)
if cycles > 0xFFFFFFFF {
cycles = 0xFFFFFFFF
}
if !timerSleep(uint32(cycles)) {
return // return early due to interrupt
}
curr = ticks()
curr := ticks()
last := curr + duration // 64-bit overflow unlikely
for curr < last {
cycles := timeUnit((last - curr) / pitCyclesPerMicro)
if cycles > 0xFFFFFFFF {
cycles = 0xFFFFFFFF
}
if !timerSleep(uint32(cycles)) {
return // return early due to interrupt
}
curr = ticks()
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/runtime/runtime_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func nanosecondsToTicks(ns int64) timeUnit {
}

func sleepTicks(d timeUnit) {
if d <= 0 {
return
}

if hasScheduler {
// With scheduler, sleepTicks may return early if an interrupt or
// event fires - so scheduler can schedule any go routines now
Expand Down
16 changes: 9 additions & 7 deletions src/runtime/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,15 @@ func scheduler(returnAtDeadlock bool) {
println("--- timer waiting:", tim, tim.whenTicks())
}
}
sleepTicks(timeLeft)
if asyncScheduler {
// The sleepTicks function above only sets a timeout at which
// point the scheduler will be called again. It does not really
// sleep. So instead of sleeping, we return and expect to be
// called again.
break
if timeLeft > 0 {
sleepTicks(timeLeft)
if asyncScheduler {
// The sleepTicks function above only sets a timeout at
// which point the scheduler will be called again. It does
// not really sleep. So instead of sleeping, we return and
// expect to be called again.
break
}
}
continue
}
Expand Down
Loading