-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
rp2: Run USB stack task exclusively from core 0. #8836
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
Conversation
I did want to see if it's possible to run the TinyUSB ISR code from the IRQ itself, which would completely remove the hook code from the VM. But that is a task for later. For now the fix here looks OK.
Yes, and I guess one of those is if core1 writes out to the USB CDC (
Not that I can think of. This call is not time critical, so as long as it's eventually called it should be OK.
Doing it more generally does sound good. But bouncing it in MICROPY_VM_HOOK_POLL may be expensive. Would need to profile it. |
Instead of bouncing a lock, maybe we can have a single, global flag which is set by either core to indicate that it wants to synchronise? Then there can be a single uniform check of this flag in MICROPY_VM_HOOK_POLL, that is independent of which core is running the code. |
ports/rp2/mpconfigport.h
Outdated
@@ -238,7 +238,7 @@ extern const struct _mod_network_nic_type_t mod_network_nic_type_wiznet5k; | |||
extern void mp_handle_pending(bool); \ | |||
mp_handle_pending(true); \ | |||
best_effort_wfe_or_timeout(make_timeout_time_ms(1)); \ | |||
MICROPY_HW_USBDEV_TASK_HOOK \ | |||
if (get_core_num() == 0) { MICROPY_HW_USBDEV_TASK_HOOK } \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other calls to MICROPY_HW_USBDEV_TASK_HOOK
which I think also need to be handled this way.
I'll do a refactor first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #8863.
Please rebase on latest master. |
The goal is to avoid a situation where core 1 is shut down while holding the tinyusb spinlock, which could happen during soft reset if mp_thread_deinit is called while core1 is running tud_task(). This also fixes a latent race where the two cores are competing to decrement and compare `vm_hook_divisor` with no mem fence or atomic protection -- only core0 will now do this. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Done. #8845 should probably be merged first though. |
Thanks. Yes I agree 8845 should be merged first (but see comments on that PR). |
Merged in daff597 |
Add support for the PicoMo board
The goal is to avoid a situation where core 1 is shut down while holding
the tinyusb spinlock, which could happen during soft reset if
mp_thread_deinit is called while core1 is running tud_task().
This also fixes a latent race where the two cores are competing to
decrement and compare
vm_hook_divisor
with no mem fence or atomicprotection -- only core0 will now do this.
This addresses the first comment on #8494 (comment)
It's easy to reproduce with exactly the minimal example from #8494. If I copy that over as main.py, then I get a lock up about 4 times out of 5 on soft reset at the repl.
Some notes for discussion: