FreeBSD kernel kern code
subr_taskqueue.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/interrupt.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/taskqueue.h>
#include <sys/unistd.h>
#include <machine/stdarg.h>
Include dependency graph for subr_taskqueue.c:

Go to the source code of this file.

Data Structures

struct  taskqueue_busy
 
struct  taskqueue
 

Macros

#define TQ_FLAGS_ACTIVE   (1 << 0)
 
#define TQ_FLAGS_BLOCKED   (1 << 1)
 
#define TQ_FLAGS_PENDING   (1 << 2)
 
#define DT_CALLOUT_ARMED   (1 << 0)
 
#define TQ_LOCK(tq)
 
#define TQ_UNLOCK(tq)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_TASKQUEUE,"taskqueue","Task Queues")
 
void _timeout_task_init (struct taskqueue *queue, struct timeout_task *timeout_task, int priority, task_fn_t func, void *context)
 
static __inline int TQ_SLEEP (struct taskqueue *tq, void *p, struct mtx *m, int pri, const char *wm, int t)
 
static struct taskqueue_taskqueue_create (const char *name __unused, int mflags, taskqueue_enqueue_fn enqueue, void *context, int mtxflags, const char *mtxname)
 
struct taskqueuetaskqueue_create (const char *name, int mflags, taskqueue_enqueue_fn enqueue, void *context)
 
static void taskqueue_terminate (struct thread **pp, struct taskqueue *tq)
 
void taskqueue_free (struct taskqueue *queue)
 
static int taskqueue_enqueue_locked (struct taskqueue *queue, struct task *task)
 
int taskqueue_enqueue (struct taskqueue *queue, struct task *task)
 
static void taskqueue_timeout_func (void *arg)
 
int taskqueue_enqueue_timeout (struct taskqueue *queue, struct timeout_task *timeout_task, int ticks)
 
static void taskqueue_drain_running (struct taskqueue *queue)
 
void taskqueue_block (struct taskqueue *queue)
 
void taskqueue_unblock (struct taskqueue *queue)
 
static void taskqueue_run_locked (struct taskqueue *queue)
 
void taskqueue_run (struct taskqueue *queue)
 
static int task_is_running (struct taskqueue *queue, struct task *task)
 
static int taskqueue_cancel_locked (struct taskqueue *queue, struct task *task, u_int *pendp)
 
int taskqueue_cancel (struct taskqueue *queue, struct task *task, u_int *pendp)
 
int taskqueue_cancel_timeout (struct taskqueue *queue, struct timeout_task *timeout_task, u_int *pendp)
 
void taskqueue_drain (struct taskqueue *queue, struct task *task)
 
void taskqueue_drain_all (struct taskqueue *queue)
 
void taskqueue_drain_timeout (struct taskqueue *queue, struct timeout_task *timeout_task)
 
static void taskqueue_swi_enqueue (void *context)
 
static void taskqueue_swi_run (void *dummy)
 
static void taskqueue_swi_giant_enqueue (void *context)
 
static void taskqueue_swi_giant_run (void *dummy)
 
int taskqueue_start_threads (struct taskqueue **tqp, int count, int pri, const char *name,...)
 
void taskqueue_thread_loop (void *arg)
 
void taskqueue_thread_enqueue (void *context)
 
 TASKQUEUE_DEFINE (swi, taskqueue_swi_enqueue, NULL, swi_add(NULL,"task queue", taskqueue_swi_run, NULL, SWI_TQ, INTR_MPSAFE,&taskqueue_ih))
 
 TASKQUEUE_DEFINE (swi_giant, taskqueue_swi_giant_enqueue, NULL, swi_add(NULL,"Giant taskq", taskqueue_swi_giant_run, NULL, SWI_TQ_GIANT, 0,&taskqueue_giant_ih))
 
 TASKQUEUE_DEFINE_THREAD (thread)
 
struct taskqueuetaskqueue_create_fast (const char *name, int mflags, taskqueue_enqueue_fn enqueue, void *context)
 
int taskqueue_enqueue_fast (struct taskqueue *queue, struct task *task)
 
static void taskqueue_fast_enqueue (void *context)
 
static void taskqueue_fast_run (void *dummy)
 
 TASKQUEUE_FAST_DEFINE (fast, taskqueue_fast_enqueue, NULL, swi_add(NULL,"fast taskq", taskqueue_fast_run, NULL, SWI_TQ_FAST, INTR_MPSAFE,&taskqueue_fast_ih))
 
int taskqueue_member (struct taskqueue *queue, struct thread *td)
 

Variables

static void * taskqueue_giant_ih
 
static void * taskqueue_ih
 
static void * taskqueue_fast_ih
 

Macro Definition Documentation

#define DT_CALLOUT_ARMED   (1 << 0)
#define TQ_FLAGS_ACTIVE   (1 << 0)

Definition at line 68 of file subr_taskqueue.c.

Referenced by _taskqueue_create(), taskqueue_free(), and taskqueue_thread_loop().

#define TQ_FLAGS_BLOCKED   (1 << 1)

Definition at line 69 of file subr_taskqueue.c.

Referenced by taskqueue_block(), taskqueue_enqueue_locked(), and taskqueue_unblock().

#define TQ_FLAGS_PENDING   (1 << 2)

Definition at line 70 of file subr_taskqueue.c.

Referenced by taskqueue_enqueue_locked(), and taskqueue_unblock().

#define TQ_LOCK (   tq)
Value:
do { \
if ((tq)->tq_spin) \
mtx_lock_spin(&(tq)->tq_mutex); \
else \
mtx_lock(&(tq)->tq_mutex); \
} while (0)

Definition at line 74 of file subr_taskqueue.c.

Referenced by taskqueue_block(), taskqueue_cancel(), taskqueue_cancel_timeout(), taskqueue_drain(), taskqueue_drain_all(), taskqueue_enqueue(), taskqueue_enqueue_timeout(), taskqueue_free(), taskqueue_run(), taskqueue_run_locked(), taskqueue_thread_loop(), and taskqueue_unblock().

#define TQ_UNLOCK (   tq)
Value:
do { \
if ((tq)->tq_spin) \
mtx_unlock_spin(&(tq)->tq_mutex); \
else \
mtx_unlock(&(tq)->tq_mutex); \
} while (0)

Definition at line 82 of file subr_taskqueue.c.

Referenced by taskqueue_block(), taskqueue_cancel(), taskqueue_cancel_timeout(), taskqueue_drain(), taskqueue_drain_all(), taskqueue_enqueue(), taskqueue_enqueue_timeout(), taskqueue_run(), taskqueue_run_locked(), taskqueue_thread_loop(), and taskqueue_unblock().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static struct taskqueue* _taskqueue_create ( const char *name  __unused,
int  mflags,
taskqueue_enqueue_fn  enqueue,
void *  context,
int  mtxflags,
const char *  mtxname 
)
static

Definition at line 111 of file subr_taskqueue.c.

References malloc(), mtx_init(), and TQ_FLAGS_ACTIVE.

Referenced by taskqueue_create(), and taskqueue_create_fast().

Here is the call graph for this function:

Here is the caller graph for this function:

void _timeout_task_init ( struct taskqueue queue,
struct timeout_task *  timeout_task,
int  priority,
task_fn_t  func,
void *  context 
)

Definition at line 91 of file subr_taskqueue.c.

static MALLOC_DEFINE ( M_TASKQUEUE  ,
"taskqueue"  ,
"Task Queues"   
)
static
static int task_is_running ( struct taskqueue queue,
struct task *  task 
)
static

Definition at line 342 of file subr_taskqueue.c.

References taskqueue_busy::tb_running.

Referenced by taskqueue_cancel_locked(), and taskqueue_drain().

Here is the caller graph for this function:

void taskqueue_block ( struct taskqueue queue)

Definition at line 277 of file subr_taskqueue.c.

References TQ_FLAGS_BLOCKED, TQ_LOCK, and TQ_UNLOCK.

int taskqueue_cancel ( struct taskqueue queue,
struct task *  task,
u_int *  pendp 
)

Definition at line 368 of file subr_taskqueue.c.

References taskqueue_cancel_locked(), TQ_LOCK, and TQ_UNLOCK.

Here is the call graph for this function:

static int taskqueue_cancel_locked ( struct taskqueue queue,
struct task *  task,
u_int *  pendp 
)
static

Definition at line 355 of file subr_taskqueue.c.

References task_is_running().

Referenced by taskqueue_cancel(), and taskqueue_cancel_timeout().

Here is the call graph for this function:

Here is the caller graph for this function:

int taskqueue_cancel_timeout ( struct taskqueue queue,
struct timeout_task *  timeout_task,
u_int *  pendp 
)

Definition at line 380 of file subr_taskqueue.c.

References DT_CALLOUT_ARMED, taskqueue_cancel_locked(), TQ_LOCK, and TQ_UNLOCK.

Here is the call graph for this function:

struct taskqueue* taskqueue_create ( const char *  name,
int  mflags,
taskqueue_enqueue_fn  enqueue,
void *  context 
)

Definition at line 133 of file subr_taskqueue.c.

References _taskqueue_create().

Referenced by firmware_modevent().

Here is the call graph for this function:

Here is the caller graph for this function:

struct taskqueue* taskqueue_create_fast ( const char *  name,
int  mflags,
taskqueue_enqueue_fn  enqueue,
void *  context 
)

Definition at line 571 of file subr_taskqueue.c.

References _taskqueue_create().

Here is the call graph for this function:

TASKQUEUE_DEFINE ( swi  ,
taskqueue_swi_enqueue  ,
NULL  ,
swi_add(NULL,"task queue", taskqueue_swi_run, NULL, SWI_TQ, INTR_MPSAFE,&taskqueue_ih  
)
TASKQUEUE_DEFINE ( swi_giant  ,
taskqueue_swi_giant_enqueue  ,
NULL  ,
swi_add(NULL,"Giant taskq", taskqueue_swi_giant_run, NULL, SWI_TQ_GIANT, 0,&taskqueue_giant_ih  
)
TASKQUEUE_DEFINE_THREAD ( thread  )
void taskqueue_drain ( struct taskqueue queue,
struct task *  task 
)

Definition at line 401 of file subr_taskqueue.c.

References task_is_running(), TQ_LOCK, TQ_SLEEP(), and TQ_UNLOCK.

Referenced by aio_proc_rundown(), firmware_modevent(), and taskqueue_drain_timeout().

Here is the call graph for this function:

Here is the caller graph for this function:

void taskqueue_drain_all ( struct taskqueue queue)

Definition at line 414 of file subr_taskqueue.c.

References taskqueue_drain_running(), TQ_LOCK, TQ_SLEEP(), and TQ_UNLOCK.

Here is the call graph for this function:

static void taskqueue_drain_running ( struct taskqueue queue)
static

Definition at line 268 of file subr_taskqueue.c.

References TQ_SLEEP().

Referenced by taskqueue_drain_all().

Here is the call graph for this function:

Here is the caller graph for this function:

void taskqueue_drain_timeout ( struct taskqueue queue,
struct timeout_task *  timeout_task 
)

Definition at line 433 of file subr_taskqueue.c.

References taskqueue_drain().

Here is the call graph for this function:

int taskqueue_enqueue ( struct taskqueue queue,
struct task *  task 
)
int taskqueue_enqueue_fast ( struct taskqueue queue,
struct task *  task 
)

Definition at line 580 of file subr_taskqueue.c.

References taskqueue_enqueue().

Here is the call graph for this function:

static int taskqueue_enqueue_locked ( struct taskqueue queue,
struct task *  task 
)
static

Definition at line 168 of file subr_taskqueue.c.

References TQ_FLAGS_BLOCKED, and TQ_FLAGS_PENDING.

Referenced by taskqueue_enqueue(), taskqueue_enqueue_timeout(), and taskqueue_timeout_func().

Here is the caller graph for this function:

int taskqueue_enqueue_timeout ( struct taskqueue queue,
struct timeout_task *  timeout_task,
int  ticks 
)

Definition at line 236 of file subr_taskqueue.c.

References DT_CALLOUT_ARMED, taskqueue_enqueue_locked(), taskqueue_timeout_func(), ticks, TQ_LOCK, and TQ_UNLOCK.

Referenced by uipc_detach().

Here is the call graph for this function:

Here is the caller graph for this function:

TASKQUEUE_FAST_DEFINE ( fast  ,
taskqueue_fast_enqueue  ,
NULL  ,
swi_add(NULL,"fast taskq", taskqueue_fast_run, NULL, SWI_TQ_FAST, INTR_MPSAFE,&taskqueue_fast_ih  
)
static void taskqueue_fast_enqueue ( void *  context)
static

Definition at line 588 of file subr_taskqueue.c.

References swi_sched().

Here is the call graph for this function:

static void taskqueue_fast_run ( void *  dummy)
static

Definition at line 594 of file subr_taskqueue.c.

References taskqueue_run().

Here is the call graph for this function:

void taskqueue_free ( struct taskqueue queue)

Definition at line 154 of file subr_taskqueue.c.

References free(), mtx_destroy(), taskqueue_terminate(), TQ_FLAGS_ACTIVE, and TQ_LOCK.

Referenced by aio_unload(), and firmware_modevent().

Here is the call graph for this function:

Here is the caller graph for this function:

int taskqueue_member ( struct taskqueue queue,
struct thread *  td 
)

Definition at line 604 of file subr_taskqueue.c.

void taskqueue_run ( struct taskqueue queue)

Definition at line 333 of file subr_taskqueue.c.

References taskqueue_run_locked(), TQ_LOCK, and TQ_UNLOCK.

Referenced by taskqueue_fast_run(), taskqueue_swi_giant_run(), and taskqueue_swi_run().

Here is the call graph for this function:

Here is the caller graph for this function:

static void taskqueue_run_locked ( struct taskqueue queue)
static

Definition at line 299 of file subr_taskqueue.c.

References taskqueue_busy::tb_running, TQ_LOCK, TQ_UNLOCK, and wakeup().

Referenced by taskqueue_run(), and taskqueue_thread_loop().

Here is the call graph for this function:

Here is the caller graph for this function:

int taskqueue_start_threads ( struct taskqueue **  tqp,
int  count,
int  pri,
const char *  name,
  ... 
)

Definition at line 466 of file subr_taskqueue.c.

References count, kthread_add(), malloc(), printf(), sched_add(), sched_prio(), taskqueue_thread_loop(), and vsnprintf().

Referenced by firmware_modevent().

Here is the call graph for this function:

Here is the caller graph for this function:

static void taskqueue_swi_enqueue ( void *  context)
static

Definition at line 442 of file subr_taskqueue.c.

References swi_sched(), and taskqueue_ih.

Here is the call graph for this function:

static void taskqueue_swi_giant_enqueue ( void *  context)
static

Definition at line 454 of file subr_taskqueue.c.

References swi_sched(), and taskqueue_giant_ih.

Here is the call graph for this function:

static void taskqueue_swi_giant_run ( void *  dummy)
static

Definition at line 460 of file subr_taskqueue.c.

References taskqueue_run().

Here is the call graph for this function:

static void taskqueue_swi_run ( void *  dummy)
static

Definition at line 448 of file subr_taskqueue.c.

References taskqueue_run().

Here is the call graph for this function:

static void taskqueue_terminate ( struct thread **  pp,
struct taskqueue tq 
)
static

Definition at line 144 of file subr_taskqueue.c.

References TQ_SLEEP(), and wakeup().

Referenced by taskqueue_free().

Here is the call graph for this function:

Here is the caller graph for this function:

void taskqueue_thread_enqueue ( void *  context)

Definition at line 549 of file subr_taskqueue.c.

References wakeup_one().

Referenced by firmware_modevent().

Here is the call graph for this function:

Here is the caller graph for this function:

void taskqueue_thread_loop ( void *  arg)

Definition at line 521 of file subr_taskqueue.c.

References kthread_exit(), taskqueue_run_locked(), TQ_FLAGS_ACTIVE, TQ_LOCK, TQ_SLEEP(), TQ_UNLOCK, and wakeup_one().

Referenced by taskqueue_start_threads().

Here is the call graph for this function:

Here is the caller graph for this function:

static void taskqueue_timeout_func ( void *  arg)
static

Definition at line 222 of file subr_taskqueue.c.

References DT_CALLOUT_ARMED, and taskqueue_enqueue_locked().

Referenced by taskqueue_enqueue_timeout().

Here is the call graph for this function:

Here is the caller graph for this function:

void taskqueue_unblock ( struct taskqueue queue)

Definition at line 286 of file subr_taskqueue.c.

References TQ_FLAGS_BLOCKED, TQ_FLAGS_PENDING, TQ_LOCK, and TQ_UNLOCK.

static __inline int TQ_SLEEP ( struct taskqueue tq,
void *  p,
struct mtx *  m,
int  pri,
const char *  wm,
int  t 
)
static

Definition at line 102 of file subr_taskqueue.c.

References msleep_spin().

Referenced by taskqueue_drain(), taskqueue_drain_all(), taskqueue_drain_running(), taskqueue_terminate(), and taskqueue_thread_loop().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

void* taskqueue_fast_ih
static

Definition at line 585 of file subr_taskqueue.c.

void* taskqueue_giant_ih
static

Definition at line 47 of file subr_taskqueue.c.

Referenced by taskqueue_swi_giant_enqueue().

void* taskqueue_ih
static

Definition at line 48 of file subr_taskqueue.c.

Referenced by taskqueue_swi_enqueue().