runtime: time.Sleep can return before the duration ends
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go, wasm
- Lĩnh vực
- embedded-iot, operating-systems
Hướng nghiên cứu
The rounding is in nanosecondsToTicks, shown in src/runtime/runtime_rp2.go, and the same pattern is said to exist in the other tick-based port files. ticks() and the scheduler's wakeup computation are the second source of error. Start by reading those three functions and checking how time.Sleep reaches them. Done means sleeps never return early on the affected ports, for example a 500 ns sleep waits at least one tick, while ports that keep nanoseconds are unchanged.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The time.Sleep documentation says: "Sleep pauses the current goroutine for at least the duration d." On TinyGo, a sleep can end too early when the duration is not a whole number of runtime ticks.
The cause is in nanosecondsToTicks. Each port converts nanoseconds to ticks with an integer division that rounds down. For example, src/runtime/runtime_rp2.go has:
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns / 1000)
}
Thus, with a 1 µs tick:
- time.Sleep(500 * time.Nanosecond) gives 0 ticks, so it does not sleep.
- time.Sleep(1500 * time.Nanosecond) gives 1 tick, so it sleeps for less than 1.5 µs.
The error is up to one tick. The tick size is different on each port:
| Tick | Ports |
|---|---|
| ~30.5 µs (32768 Hz RTC) | nrf, atsamd21, atsamd51, fe310, avrtiny |
| 10 µs | tkey |
| 1 µs | ra4m1, rp2040, rp2350, mimxrt1062, nxpmk66f18 |
| 25 ns to 100 ns | esp32, esp32s3, stm32, riscv-qemu, windows |
On nrf, time.Sleep(20 * time.Microsecond) gives 0 ticks, so it returns at once.
There is a second source of error. ticks() also rounds down. The scheduler sets the wakeup to ticks() plus the sleep in ticks. If the sleep starts late in a tick, the wakeup comes up to one tick early.
Ports that keep timeUnit in nanoseconds (unix, wasm, avr, mgba, arm7tdmi) do not round in nanosecondsToTicks.
- Ngôn ngữ chính
- Go
- Star
- 17.8k
- Fork
- 1.1k
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 380
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tinygo-org/tinygo
-
avr: SPI Mode2 runs as mode 1Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
tinygo-org/tinygo#6727 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
tinygo-org/tinygo#6711 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Builds are not reproducible: cgo snippet paths in debug infoCó thể đã có người làm @tridev-tej đã nhận 1 ngày trước. Đang mởenhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
tinygo-org/tinygo#6619 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Fix the targets that tinygo build -target rejectsCó thể đã có người làm @narguis đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
tinygo-org/tinygo#6617 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
tinygo-org/tinygo#6312 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của tinygo-org/tinygo
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sresarehumantoo/cc-artex#456 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ollama/ollama#20021 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
factory:subtask
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
release
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
github/gh-aw-mcpg#17603 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
bboerst/stratum-work#351 ·
Maintainer thường phản hồi trong vòng 1 ngày