Overlay patch 0015: _timing for the windows port; the wasm bridge's call signature - #24
Merged
Merged
Conversation
…e's call signature 0015 gives micropython.exe a wake source: a _timing module whose timer-queue thread sets a flag the main thread notices between bytecodes, in sleeps and in the console wait, then hands the callback to mp_sched_schedule from its own context. multimer's native source is its only caller. In the windows profiles; compile-checked with mingw and smoked under wine (the VM-hook and sleep paths; the console and pipe waits need a real Windows console). The wasm bridge called external_call_depth_dec with no argument; v1.29.0 takes the object to keep rooted. The call went through an invoke wrapper with the wrong signature, so every timer callback in the direct wasm build ended in "null function or function signature mismatch" (fatal under node, a console error in a page). It passes mp_const_none now.
This was referenced Sep 26, 2026
…event, 1 ms timer resolution The cloud's first version used a timer-queue timer and 10 ms wait slices; on a real Windows console it fell to the 15.6 ms system tick (a 10 ms multimer timer: 348/500 idle, 339 busy, 20 a second at the prompt). Now one waitable timer, high resolution where Windows offers it, on a helper thread signals an event that MICROPY_INTERNAL_WFE, the console wait and the piped stdin path block on, and init() asks for the 1 ms resolution as SDL does. Same bench: 507/500 idle and busy, 0.5 ms median jitter, 4 ms p99 lateness, about 100 a second at the prompt. mp_timing_poll keeps a deadline pending when the scheduler queue is full, so a full queue cannot stop every timer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two things the timing redesign (PyDevices/pydevices#101) needs from the interpreter overlay.
Patch 0015, the windows port.
micropython.exehas no signals, nomachine.Timerand no threads in the VM, so nothing could wake the main thread on a deadline: multimer's oldwin32provider needed the thread in an alertable wait, which the REPL's console read is not, and a plaintime.sleepstarved it. The patch adds a_timingmodule: one high-resolution waitable timer, waited on by a helper thread that only sets a flag and signals an event when the deadline passes; the main thread notices the flag between bytecodes, inmp_event_wait_msand in the console wait, and hands the callback tomp_sched_schedulefrom its own context, so the callback runs at a bytecode boundary exactly as a board's softmachine.Timercallback does. The port's waits (MICROPY_INTERNAL_WFE, the console wait inmp_hal_stdin_rx_chr, the piped-stdin path of 0013) block on that event, so a sleep or a REPL waiting for a key wakes the moment a deadline passes;init()also requests Windows' 1 ms timer resolution, as SDL does. Measured on a real Windows console:report()sayssource=native, a 10 ms timer delivers 507/500 idle and busy with 0.5 ms median jitter and 4 ms p99 lateness, and about 100 callbacks a second at an idle-iprompt (the earlier timer-queue draft pinned to the 15.6 ms system tick: 348/500, 20 a second at the prompt). Justification for an overlay patch: no Python-level route delivers on the main thread of a build without threads, and the REPL goal is the charter's first requirement. In thewindows-fullandwindows-networkedprofiles.The wasm bridge.
usermods/wasmbridge/mod_wasm_bridge.ccalledexternal_call_depth_dec()with no argument where v1.29.0 takes one, so every timer callback in the direct wasm build ended in "null function or function signature mismatch" (fatal under node, a console error in a page). Fixed. The portal's and workbench's vendored runtime were built before the fix and want anmp-wasmrebuild after this merges.Rebased over #23 with no conflict. Companions: PyDevices/lvgl-bindings#22, PyDevices/pydevices-examples#149. Draft until the Windows phase is in the ledger.