USB_ADD_TASK(9)

πŸ“¦ in nixpkgs unstable

πŸ’– 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 call usb_add_task() again, it will not schedule multiple executions. The task structure must already be initialised by usb_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. Calling usb_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 calling usb_rem_task() followed by usb_wait_task().
  • usb_init_task() β€” this macro prepares the task structure task to be used in future calls to usb_add_task(), usb_rem_task(), usb_wait_task(), and usb_rem_wait_task(). The task will be prepared to call the function fn with the argument specified by arg. 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 πŸ’œ

usb(4), task_add(9)


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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms