USB_ADD_TASK(9)
π USB_ADD_TASK(9) π
okay so bestie, this is the USB_ADD_TASK(9) page from the Kernel Developer's Manual. It's all about USB task queues, and honestly? kind of iconic. Let's get into it. β¨
π NAME π
usb_add_task, usb_rem_task, usb_wait_task, usb_rem_wait_task, usb_init_task β USB task queues
β¨ SYNOPSIS β¨
#include <dev/usb/usbdi.h>
void
usb_add_task(struct usbd_device *dev, struct usb_task *task);
void
usb_rem_task(struct usbd_device *dev, struct usb_task *task);
void
usb_wait_task(struct usbd_device *dev, struct usb_task *task);
void
usb_rem_wait_task(struct usbd_device *dev, struct usb_task *task);
void
usb_init_task(struct usb_task *task, void (*fn)(void *), void *arg,
char type);
π DESCRIPTION π
The USB stack gives you an API to manage task execution in a thread context at the soonest opportunity. There are three different task queues, and they run on two separate threads. Every task executed through the USB task API is serialized with USB events such as device detachments. No cap.
usb_add_task()β enqueues a task to be executed by the task thread. If you callusb_add_task()again, it will not schedule multiple executions. The task structure must already be initialised byusb_init_task().usb_rem_task()β removes a scheduled task from its queue. If the work was already executed, or it has not been added to the task queue, the call will have no effect. Callingusb_rem_task()while the task is executing will not abort it.usb_wait_task()β sleeps until the given task is neither queued for execution nor currently running. It's giving "wait for it" energy, but literally.usb_rem_wait_task()β the equivalent of callingusb_rem_task()followed byusb_wait_task().usb_init_task()β this macro prepares the task structuretaskto be used in future calls tousb_add_task(),usb_rem_task(),usb_wait_task(), andusb_rem_wait_task(). Thetaskwill be prepared to call the functionfnwith the argument specified byarg. The type of the task decides which queue and thread will be used for its execution:
π¦ task types π¦
USB_TASK_TYPE_GENERICβ tasks used for general work that need to happen in a process context.USB_TASK_TYPE_EXPLOREβ device discovery tasks exploring the tree from the root.USB_TASK_TYPE_ABORTβ tasks of this type execute on a dedicated thread not shared with other USB task types.
Most drivers will only define tasks of type USB_TASK_TYPE_GENERIC.
β οΈ note that USB_TASK_TYPE_ABORT tasks are only used by host controller drivers and should never be used by drivers. Like, never ever. This is not a drill, bestie.
Once initialised, the task can be used repeatedly in the API functions listed above and does not need to be reinitialised unless the function called and/or its argument must change.
π CONTEXT π
usb_task_add() can be called from any context.
π SEE ALSO π
mwah π that's the whole page. Source/version: Debian. Date: January 19, 2021. go off, kernel dev bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2016 Adam Wolk <awolk@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms