8000 port/rp2: Make tickless, remove 1ms timeout when idle. by projectgus · Pull Request #12837 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@projectgus
Copy link
Contributor
@projectgus projectgus commented Oct 31, 2023

The main motivation for doing this was to reduce the latency when the system is woken by a USB interrupt. The best_effort_wfe_or_timeout() function calls into the pico-sdk dynamic timer framework which sets up a new dynamic timer instance each time, and then has to tear it down before continuing after a WFE.

Testing Python interrupt latency it seems to improved by about 12us (from average of 46us to 34us running a Pin IRQ). C-based "scheduled nodes" should see even lower latency.

Test code was:

import machine
from machine import Pin

i = Pin(2, Pin.IN, Pin.PULL_UP)
o = Pin(3, Pin.OUT)

def handler(_):
    o(1)
    print('!')
    o(0)

i.irq(handler, Pin.IRQ_FALLING)

while True:
    machine.idle()

With latency measured using logic analyzer:

LA Capture of the above in pulseview

(Channel 0 is "i", Channel is "o". Please excuse noisy CH0, was triggering with a button. Time 0 is the first falling edge of channel 0.)

The risk with this change is that it exposes cases where a driver expects execution to continue without an interrupt. Alternative is to enable the standard ARM SysTick interrupt to wake the CPU at tick intervals. (There is a branch with SysTick enabled and working, but testing shows tickless is just as functional.)

This work was funded through GitHub Sponsors.

@dpgeorge
Copy link
Member

Thanks. I think we should make this change and then if there are any cases of missed events, add SEV in the appropriate place.

The main motivation for doing this was to reduce the latency when the
system is woken by a USB interrupt.  The best_effort_wfe_or_timeout()
function calls into the pico-sdk dynamic timer framework which sets up a
new dynamic timer instance each time, and then has to tear it down before
continuing after a WFE.

Testing Python interrupt latency, it seems to be improved by about 12us
(from average of 46us to 34us running a Pin IRQ).  C-based "scheduled
nodes" should see even lower latency.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0