TASKQ(9F) Kernel Functions for Drivers TASKQ(9F)
taskq, ddi_taskq_create, ddi_taskq_destroy, ddi_taskq_dispatch,
ddi_taskq_wait, ddi_taskq_suspend, ddi_taskq_suspended, ddi_taskq_resume
- Kernel task queue operations
#include <sys/sunddi.h> ddi_taskq_t *ddi_taskq_create
, const char *name
, int nthreads
, pri_t pri
, uint_t cflags
); void ddi_taskq_destroy
); int ddi_taskq_dispatch
, void (* func)
(void *), void *arg
, uint_t dflags
); void ddi_taskq_wait
); void ddi_taskq_suspend
); boolean_t ddi_taskq_suspended
); void ddi_taskq_resume
illumos DDI specific (illumos DDI)
Pointer to the device's dev_info structure. May be NULL for
kernel modules that do not have an associated dev_info
Descriptive string. Only alphanumeric characters can be used
in name and spaces are not allowed. The name should be
Number of threads servicing the task queue. Note that the
request ordering is guaranteed (tasks are processed in the
order scheduled) if the taskq
is created with a single
servicing thread. pri
Priority of threads servicing the task queue. Drivers and
modules should specify TASKQ_DEFAULTPRI. cflags
Should pass 0 as flags. func
Callback function to call. arg
Argument to the callback function. dflags
Allow sleeping (blocking) until memory is
Return DDI_FAILURE immediately if memory is
not available. tq
Pointer to a task queue (ddi_taskq_t *). tp
Pointer to a thread structure.
A kernel task queue is a mechanism for general-purpose asynchronous task
scheduling that enables tasks to be performed at a later time by another
thread. There are several reasons why you may utilize asynchronous task
1. You have a task that isn't time-critical, but a current code
path that is.
2. You have a task that may require grabbing locks that a thread
3. You have a task that needs to block (for example, to wait for
memory), but you have a thread that cannot block in its
4. You have a code path that can't complete because of a specific
condition, but also can't sleep or fail. In this case, the
task is immediately queued and then is executed after the
5. A task queue is just a simple way to launch multiple tasks in
A task queue consists of a list of tasks, together with one or more
threads to service the list. If a task queue has a single service thread,
all tasks are guaranteed to execute in the order they were dispatched.
Otherwise they can be executed in any order. Note that since tasks are
placed on a list, execution of one task should not depend on the
execution of another task or a deadlock may occur.
function creates a task queue instance.
function places taskq
on the list for later
execution. The dflag
argument specifies whether it is allowed sleep
waiting for memory. DDI_SLEEP dispatches can sleep and are guaranteed to
succeed. DDI_NOSLEEP dispatches are guaranteed not to sleep but may fail
) if resources are not available.
function waits for any scheduled tasks to
complete, then destroys the taskq
. The caller should guarantee that no
new tasks are scheduled for the closing taskq
function waits for all previously scheduled tasks to
complete. Note that this function does not stop any new task dispatches.
function suspends all task execution until ddi_taskq_resume()
is called. Although ddi_taskq_suspend()
suspend pending tasks, there are no guarantees that they will be
suspended. The only guarantee is that all tasks dispatched after ddi_taskq_suspend()
will not be executed. Because it will trigger a
deadlock, the ddi_taskq_suspend()
function should never be called by a
task executing on a taskq
function returns B_TRUE
otherwise. It is intended to ASSERT that the task queue is
function resumes task queue execution.
function creates an opaque handle that is used for
all other taskq
operations. It returns a taskq
pointer on success and
NULL on failure.
function returns DDI_FAILURE
if it can't
dispatch a task and returns DDI_SUCCESS
if dispatch succeeded.
function returns B_TRUE
All functions may be called from the user or kernel contexts.
Additionally, the ddi_taskq_dispatch
function may be called from the
interrupt context only if the DDI_NOSLEEP flag is set.
January 23, 2023 TASKQ(9F)