-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
[Core] Cleanups to USB suspend logic #21537
base: develop
Are you sure you want to change the base?
Conversation
@@ -534,40 +530,35 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) { | |||
} | |||
qmkusbConfigureHookI(&drivers.array[i].driver); | |||
} | |||
osalSysUnlockFromISR(); | |||
if (last_suspend_state) { | |||
usb_event_queue_enqueue(USB_EVENT_WAKEUP); | |||
} |
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.
One remaining problem here is that last_suspend_state
is set in usb_event_queue_task()
(and without any locking too). If usb_event_queue_task()
does not get called in time (which may happen if someone sticks a large delay into some code), we may potentially get here with a stale value for last_suspend_state
, and therefore lose the wakeup event in case the wakeup goes through the full reconfiguration. Although getting that case after the other changes in the PR would probably be harder than before (with the older code you could get this broken state for any resume that ends up reconfiguring devices, because USB_EVENT_SUSPEND
was not processed in time).
The options here are:
- Move all handling of
last_suspend_state
intousb_event_cb()
(set it onUSB_EVENT_SUSPEND
andUSB_EVENT_WAKEUP
, and also after generating theUSB_EVENT_WAKEUP
event in theUSB_EVENT_CONFIGURED
path). - Move all handling of
last_suspend_state
intousb_event_queue_task()
(ifUSB_EVENT_CONFIGURED
comes afterUSB_EVENT_SUSPEND
, but withoutUSB_EVENT_WAKEUP
, perform wakeup processing too).
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.
Thanks for spotting! I did the first approach and moved it into the callback and hopefully didn't miss anything.
c963338
to
6916f10
Compare
case USB_EVENT_UNCONFIGURED: | ||
/* Falls into.*/ |
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.
maybe keep these comments for readability?
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.
Hmmn, I'm not convinced that it actually adds readability. Though that is ofc subjective.
f4f713a
to
6a88a07
Compare
Having issues with the current code on macos, will update this comment with more context asap. |
suspend_wakeup_init isn't called from an ISR context anymore, thus we can use the regular clear_keyboard function in this context, which will also send a report to the host to reset all keys which might still be registered as held.
Otherwise a incoming USB_EVENT_SUSPEND event might not be processed before falling into the sleeping loop.
The queue is written from an ISR context and read from the main thread which can lead to race conditions if the main thread is pre-empted while accessing the queue. Therefore all interactions are moved into critical sections.
As this was previously accessed from both ISR and main thread, which can lead to race conditions as well.
...at this point the USB driver is already suspended so the message will only be printed after resuming the operation, which is kind of pointless.
6a88a07
to
9abba9d
Compare
Thank you for your contribution! |
Thank you for your contribution! |
Description
This is a followup on #19780.
TBA.
Types of Changes
Issues Fixed or Closed by This PR
Checklist