]> git.proxmox.com Git - mirror_spl.git/blame - include/sys/taskq.h
Invert minclsyspri and maxclsyspri
[mirror_spl.git] / include / sys / taskq.h
CommitLineData
716154c5
BB
1/*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
715f6251 6 * UCRL-CODE-235197
7 *
716154c5 8 * This file is part of the SPL, Solaris Porting Layer.
3d6af2dd 9 * For details, see <http://zfsonlinux.org/>.
716154c5
BB
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
715f6251 15 *
716154c5 16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
715f6251 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
716154c5
BB
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23\*****************************************************************************/
715f6251 24
09b414e8 25#ifndef _SPL_TASKQ_H
26#define _SPL_TASKQ_H
f1ca4da6 27
f1b59d26 28#include <linux/module.h>
f1ca4da6 29#include <linux/gfp.h>
30#include <linux/slab.h>
31#include <linux/interrupt.h>
bcd68186 32#include <linux/kthread.h>
f4b37741 33#include <sys/types.h>
925ca8cc 34#include <sys/thread.h>
f1ca4da6 35
472a34ca 36#define TASKQ_NAMELEN 31
f1ca4da6 37
472a34ca
BB
38#define TASKQ_PREPOPULATE 0x00000001
39#define TASKQ_CPR_SAFE 0x00000002
40#define TASKQ_DYNAMIC 0x00000004
41#define TASKQ_THREADS_CPU_PCT 0x00000008
42#define TASKQ_DC_BATCH 0x00000010
f7a973d9 43#define TASKQ_ACTIVE 0x80000000
f1ca4da6 44
f1ca4da6 45/*
46 * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
bcd68186 47 * KM_SLEEP/KM_NOSLEEP. TQ_NOQUEUE/TQ_NOALLOC are set particularly
48 * large so as not to conflict with already used GFP_* defines.
f1ca4da6 49 */
472a34ca
BB
50#define TQ_SLEEP 0x00000000
51#define TQ_NOSLEEP 0x00000001
52#define TQ_PUSHPAGE 0x00000002
53#define TQ_NOQUEUE 0x01000000
54#define TQ_NOALLOC 0x02000000
55#define TQ_NEW 0x04000000
56#define TQ_FRONT 0x08000000
bcd68186 57
d9acd930
BB
58typedef unsigned long taskqid_t;
59typedef void (task_func_t)(void *);
60
bcd68186 61typedef struct taskq {
472a34ca
BB
62 spinlock_t tq_lock; /* protects taskq_t */
63 unsigned long tq_lock_flags; /* interrupt state */
f7a973d9 64 char *tq_name; /* taskq name */
472a34ca
BB
65 struct list_head tq_thread_list;/* list of all threads */
66 struct list_head tq_active_list;/* list of active threads */
67 int tq_nactive; /* # of active threads */
f7a973d9
BB
68 int tq_nthreads; /* # of existing threads */
69 int tq_nspawn; /* # of threads being spawned */
70 int tq_maxthreads; /* # of threads maximum */
472a34ca
BB
71 int tq_pri; /* priority */
72 int tq_minalloc; /* min task_t pool size */
73 int tq_maxalloc; /* max task_t pool size */
74 int tq_nalloc; /* cur task_t pool size */
75 uint_t tq_flags; /* flags */
76 taskqid_t tq_next_id; /* next pend/work id */
77 taskqid_t tq_lowest_id; /* lowest pend/work id */
78 struct list_head tq_free_list; /* free task_t's */
79 struct list_head tq_pend_list; /* pending task_t's */
80 struct list_head tq_prio_list; /* priority pending task_t's */
d9acd930 81 struct list_head tq_delay_list; /* delayed task_t's */
472a34ca
BB
82 wait_queue_head_t tq_work_waitq; /* new work waitq */
83 wait_queue_head_t tq_wait_waitq; /* wait waitq */
bcd68186 84} taskq_t;
f1ca4da6 85
d9acd930
BB
86typedef struct taskq_ent {
87 spinlock_t tqent_lock;
88 wait_queue_head_t tqent_waitq;
89 struct timer_list tqent_timer;
90 struct list_head tqent_list;
91 taskqid_t tqent_id;
92 task_func_t *tqent_func;
93 void *tqent_arg;
94 taskq_t *tqent_taskq;
95 uintptr_t tqent_flags;
96} taskq_ent_t;
97
98#define TQENT_FLAG_PREALLOC 0x1
99#define TQENT_FLAG_CANCEL 0x2
100
2c02b71b 101typedef struct taskq_thread {
472a34ca
BB
102 struct list_head tqt_thread_list;
103 struct list_head tqt_active_list;
104 struct task_struct *tqt_thread;
105 taskq_t *tqt_tq;
106 taskqid_t tqt_id;
d9acd930 107 taskq_ent_t *tqt_task;
472a34ca 108 uintptr_t tqt_flags;
2c02b71b
PS
109} taskq_thread_t;
110
e9cb2b4f
BB
111/* Global system-wide dynamic task queue available for all consumers */
112extern taskq_t *system_taskq;
113
aed8671c 114extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
d9acd930
BB
115extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *,
116 uint_t, clock_t);
aed8671c
BB
117extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
118 taskq_ent_t *);
119extern int taskq_empty_ent(taskq_ent_t *);
120extern void taskq_init_ent(taskq_ent_t *);
121extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
122extern void taskq_destroy(taskq_t *);
123extern void taskq_wait_id(taskq_t *, taskqid_t);
a876b030 124extern void taskq_wait_outstanding(taskq_t *, taskqid_t);
aed8671c 125extern void taskq_wait(taskq_t *);
d9acd930 126extern int taskq_cancel_id(taskq_t *, taskqid_t);
aed8671c
BB
127extern int taskq_member(taskq_t *, void *);
128
129#define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \
130 taskq_create(name, nthreads, pri, min, max, flags)
131#define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \
9dc5ffbe 132 taskq_create(name, nthreads, maxclsyspri, min, max, flags)
bcd68186 133
e9cb2b4f
BB
134int spl_taskq_init(void);
135void spl_taskq_fini(void);
136
09b414e8 137#endif /* _SPL_TASKQ_H */