Repository navigation
Install the link's UART from core 1, so its interrupt runs there - #48
Conversation
uart_driver_install() allocates the UART's interrupt on the core it is called from, and link_open() is called from app_main, on core 0, which is Wi-Fi's (sdkconfig.defaults). Every byte from the console was taken by an interrupt that waited behind Wi-Fi's own and its task's, and then woke the link task across on core 1. The driver is now installed from a short task pinned to LINK_CORE, at the link's priority, and link_open() waits for it; the rest of the UART's setup is unchanged. The interrupt and the task it wakes now share the core that is the link's alone. This holds on ESP-IDF 5.5 as on 6. It is fix 3 of the ESP-IDF 6 latency work for the 1541 Ultimate's WiFi modules (JC-000/1541ultimate, 6ee42b3), noted in Armitage64#17. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EHfcHBGKaU1123LfntqHtg
ESP-IDF 6 moved FreeRTOS's queue and task functions, and the ring buffer's, to flash by default (CONFIG_FREERTOS_IN_IRAM and CONFIG_RINGBUF_IN_IRAM are off); ESP-IDF 5 has them in RAM. Each of the console's requests goes through them: the link task is woken by the UART's event queue, reads the request from the driver's receive ring buffer and writes the reply to its transmit one, and a call to any of them can wait on a flash cache miss. Set both, for about 10 KB of RAM. On the 1541 Ultimate's U64 WiFi bridge (classic ESP32, ESP-IDF 6.0.3) these two put the request latency back in the range of the ESP-IDF 5 build: p50/p90/p99 35.8/82.5/155.8 ms, against 40.8/102.2/202.7 ms without them (JC-000/1541ultimate, 4b3f7aa). Fixes 1 and 2 of the list in Armitage64#17. ESP-IDF 5.5 has no such options and passes over them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EHfcHBGKaU1123LfntqHtg
|
Thanks for this. I built both commits on ESP-IDF 5.5.5 and 6.0.3, for One change is needed on the
Either of these works:
The |
|
Smoke test of the
This commit is good to merge. These tests show it does no harm. They don't show it helps, because The |
This reverts commit a6dc84b. It comes out of this branch at the maintainer's request and goes with the move to ESP-IDF 6 (Armitage64#17) instead. On ESP-IDF 5.5.5, which the releases are built with, it does nothing: CONFIG_FREERTOS_IN_IRAM is a hidden option that is already y, and CONFIG_RINGBUF_IN_IRAM does not exist, so the build warns of an unknown kconfig symbol. This leaves the branch with only the change to link.c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One conflict, in firmware/main/link.c: main's PAL work changed link_open(void) to link_open(uint8_t region), next to this branch's install_on_link_core(). The helper (its semaphore, install_task and install_on_link_core) stays just before link_open(), which keeps main's signature and body, with main's uart_driver_install() call in that body replaced by install_on_link_core() as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for building both commits and for the StickS3 run.
Written with Claude Opus 5.5 in Claude Code. |
|
Smoke test of the merged head (6793340) on a StickS3 with a real NES, ESP-IDF 5.5.5:
Against the run of 5791a5b: the slowest reply is 305 µs, up from 299 µs, and both are well under 500 µs. The link task has 416 bytes less stack left, about what the PAL work merged from Not tested: netplay, a PAL console, the Plus2, ESP-IDF 6. The work taken out of this PR is tracked in #17, for the move to ESP-IDF 6 (this comment):
So the IDF 6 PR offered above can be opened against that work when the branch exists. |
What
The link's UART interrupt now runs on core 1 (
firmware/main/link.c).uart_driver_install()allocates the UART's interrupt on the core it is called from, andlink_open()is called fromapp_main, on core 0. The driver is now installed from a short task pinned toLINK_CORE(core 1), at the link's priority, andlink_open()waits on a semaphore until it is done. The rest of the UART setup is unchanged.This is the PR's only change. It does not depend on the ESP-IDF version: on both 5.5.5 and 6.0.3,
uart_driver_install()callsesp_intr_alloc_intrstatus()in the caller's context, so the interrupt is bound to the calling core.Why
Core 0 is Wi-Fi's (
sdkconfig.defaults). With the interrupt there, each byte from the console was taken on Wi-Fi's core and then woke the link task across on core 1. Now the interrupt and the task it wakes are on the same core, the link's.This comes from the ESP-IDF 6 Wi-Fi latency work on the 1541 Ultimate's U64 Wi-Fi module (GideonZ/1541ultimate#996, "Performance"), noted in #17. There it was one of six changes and was not measured on its own, so what it does here is not known yet (see Testing).
The other changes from that work are listed in the #17 comment. None of them are in this PR. Raising the UART FIFO thresholds would work against the link, which takes an interrupt for every byte. The Wi-Fi and lwIP IRAM options cost internal RAM and would need their own measurements.
Changes since the review
sdkconfig.defaultscommit is reverted by a new commit, as preferred in the review. It setCONFIG_FREERTOS_IN_IRAMandCONFIG_RINGBUF_IN_IRAM, which only do anything on ESP-IDF 6. On 5.5.5, FreeRTOS is in IRAM already through a hidden option that defaults toy, the ring buffer is in IRAM becauseRINGBUF_PLACE_FUNCTIONS_INTO_FLASHdefaults ton, andRINGBUF_IN_IRAMdoes not exist, so the build warned about it. The two options go with the move to ESP-IDF 6 (Move the firmware to ESP-IDF 6 before Mbed TLS 3.6 ends (March 2027) #17), where they can be measured against 6.x's defaults. I don't see an ESP-IDF 6 branch on GitHub yet; when there is one, I'll open a PR against it with both options, as a fresh commit with a corrected comment.mainis merged in to clear the conflict inlink.c.main's PAL work changedlink_open(void)tolink_open(uint8_t region). The merge keeps that signature and callsinstall_on_link_core()where the directuart_driver_install()call was. Nothing else changed.turnaround_usitem is gone from the test plan (see below).Testing
Builds, by Armitage64, on the two original commits: ESP-IDF 5.5.5 and 6.0.3,
esp32andesp32s3. All four passed. (Their IRAM figures included the two options that are now reverted, so they don't apply to this head.)Builds of this head:
The three configurations
release.ymlbuilds, with itsidf.pycommands, in theespressif/idfDocker images. Each is compared with a build ofmain(16696aa) on the same ESP-IDF version.mainesp32esp32s3esp32s3genericesp32s3esp32esp32s3esp32s3genericesp32s3Flash code grows by about 170 to 200 bytes. On 5.5.5 there is no longer an
unknown kconfig symbolwarning, and nothing inlink.cwarns on either version.The 6.0.3 builds, of this head and of
main, neededesp_driver_uartadded toREQUIRESinfirmware/main/CMakeLists.txt, as found in the #17 trial: without itmaindoesn't build on 6.0.3 either. I added that line locally for those builds only. It is not in this PR.Hardware, by Armitage64: StickS3 with a real NES, ESP-IDF 5.5.5, commit 5791a5b (before the merge with
main):These results show the change does no harm. They don't show a gain. As Armitage64 pointed out,
turnaround_usstarts inlink_taskafterxQueueReceivereturns, so the UART interrupt and the wake to core 1 happen before its clock starts, and it can't see the part this change moves. A gain would have to be measured on the wire, from a request's last stop bit to the reply's first start bit, with Wi-Fi busy. That measurement has not been done.Not tested: the merged head on hardware (the hardware results above are for 5791a5b), a PAL console with this change, the StickC Plus2 (classic ESP32), and ESP-IDF 6.0.3 on hardware.
🤖 Generated with Claude Code