Skip to content

Commit 962a53e

Browse files
tmon-nordickartben
authored andcommitted
drivers: udc_dwc2: Avoid unnecessary context switches
DWC2 thread must acquire UDC mutex before accessing shared resources (peripheral registers and software data structures). Whenever software enqueues a buffer, the caller first obtains mutex, adds the buffer to the list, posts event to wake up DWC2 thread and releases mutex. If DWC2 thread has higher priority than the task currently holding a mutex, there will be two completely unnecessary task switches: DWC2 will switch in, try to obtain mutex, and then the control will be returned to the mutex holder. Avoid the unnecessary task switches by locking scheduler prior to obtaining the mutex and unlocking scheduler after releasing the mutex. Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
1 parent d65de42 commit 962a53e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/usb/udc/udc_dwc2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,12 +2318,14 @@ static int dwc2_driver_preinit(const struct device *dev)
23182318

23192319
static void udc_dwc2_lock(const struct device *dev)
23202320
{
2321+
k_sched_lock();
23212322
udc_lock_internal(dev, K_FOREVER);
23222323
}
23232324

23242325
static void udc_dwc2_unlock(const struct device *dev)
23252326
{
23262327
udc_unlock_internal(dev);
2328+
k_sched_unlock();
23272329
}
23282330

23292331
static void dwc2_on_bus_reset(const struct device *dev)

0 commit comments

Comments
 (0)