]>
Commit | Line | Data |
---|---|---|
ec06701b | 1 | /* |
716154c5 BB |
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 | 22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
ec06701b | 23 | */ |
715f6251 | 24 | |
09b414e8 | 25 | #ifndef _SPL_TASKQ_H |
ec06701b | 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> |
ec06701b | 33 | #include <linux/wait_compat.h> |
f4b37741 | 34 | #include <sys/types.h> |
925ca8cc | 35 | #include <sys/thread.h> |
ec06701b | 36 | #include <sys/rwlock.h> |
f1ca4da6 | 37 | |
ec06701b | 38 | #define TASKQ_NAMELEN 31 |
f1ca4da6 | 39 | |
ec06701b AX |
40 | #define TASKQ_PREPOPULATE 0x00000001 |
41 | #define TASKQ_CPR_SAFE 0x00000002 | |
42 | #define TASKQ_DYNAMIC 0x00000004 | |
43 | #define TASKQ_THREADS_CPU_PCT 0x00000008 | |
44 | #define TASKQ_DC_BATCH 0x00000010 | |
45 | #define TASKQ_ACTIVE 0x80000000 | |
f1ca4da6 | 46 | |
f1ca4da6 | 47 | /* |
48 | * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as | |
bcd68186 | 49 | * KM_SLEEP/KM_NOSLEEP. TQ_NOQUEUE/TQ_NOALLOC are set particularly |
50 | * large so as not to conflict with already used GFP_* defines. | |
f1ca4da6 | 51 | */ |
ec06701b AX |
52 | #define TQ_SLEEP 0x00000000 |
53 | #define TQ_NOSLEEP 0x00000001 | |
54 | #define TQ_PUSHPAGE 0x00000002 | |
55 | #define TQ_NOQUEUE 0x01000000 | |
56 | #define TQ_NOALLOC 0x02000000 | |
57 | #define TQ_NEW 0x04000000 | |
58 | #define TQ_FRONT 0x08000000 | |
59 | ||
60 | /* | |
61 | * Reserved taskqid values. | |
62 | */ | |
63 | #define TASKQID_INVALID ((taskqid_t)0) | |
64 | #define TASKQID_INITIAL ((taskqid_t)1) | |
65 | ||
66 | /* | |
67 | * spin_lock(lock) and spin_lock_nested(lock,0) are equivalent, | |
68 | * so TQ_LOCK_DYNAMIC must not evaluate to 0 | |
69 | */ | |
70 | typedef enum tq_lock_role { | |
71 | TQ_LOCK_GENERAL = 0, | |
72 | TQ_LOCK_DYNAMIC = 1, | |
73 | } tq_lock_role_t; | |
bcd68186 | 74 | |
d9acd930 BB |
75 | typedef unsigned long taskqid_t; |
76 | typedef void (task_func_t)(void *); | |
77 | ||
bcd68186 | 78 | typedef struct taskq { |
ec06701b AX |
79 | spinlock_t tq_lock; /* protects taskq_t */ |
80 | char *tq_name; /* taskq name */ | |
81 | int tq_instance; /* instance of tq_name */ | |
82 | struct list_head tq_thread_list; /* list of all threads */ | |
83 | struct list_head tq_active_list; /* list of active threads */ | |
84 | int tq_nactive; /* # of active threads */ | |
85 | int tq_nthreads; /* # of existing threads */ | |
86 | int tq_nspawn; /* # of threads being spawned */ | |
87 | int tq_maxthreads; /* # of threads maximum */ | |
88 | int tq_pri; /* priority */ | |
89 | int tq_minalloc; /* min taskq_ent_t pool size */ | |
90 | int tq_maxalloc; /* max taskq_ent_t pool size */ | |
91 | int tq_nalloc; /* cur taskq_ent_t pool size */ | |
92 | uint_t tq_flags; /* flags */ | |
93 | taskqid_t tq_next_id; /* next pend/work id */ | |
94 | taskqid_t tq_lowest_id; /* lowest pend/work id */ | |
95 | struct list_head tq_free_list; /* free taskq_ent_t's */ | |
96 | struct list_head tq_pend_list; /* pending taskq_ent_t's */ | |
97 | struct list_head tq_prio_list; /* priority pending taskq_ent_t's */ | |
98 | struct list_head tq_delay_list; /* delayed taskq_ent_t's */ | |
99 | struct list_head tq_taskqs; /* all taskq_t's */ | |
100 | spl_wait_queue_head_t tq_work_waitq; /* new work waitq */ | |
101 | spl_wait_queue_head_t tq_wait_waitq; /* wait waitq */ | |
102 | tq_lock_role_t tq_lock_class; /* class when taking tq_lock */ | |
bcd68186 | 103 | } taskq_t; |
f1ca4da6 | 104 | |
d9acd930 BB |
105 | typedef struct taskq_ent { |
106 | spinlock_t tqent_lock; | |
ec06701b | 107 | spl_wait_queue_head_t tqent_waitq; |
d9acd930 BB |
108 | struct timer_list tqent_timer; |
109 | struct list_head tqent_list; | |
110 | taskqid_t tqent_id; | |
111 | task_func_t *tqent_func; | |
112 | void *tqent_arg; | |
113 | taskq_t *tqent_taskq; | |
114 | uintptr_t tqent_flags; | |
ec06701b | 115 | unsigned long tqent_birth; |
d9acd930 BB |
116 | } taskq_ent_t; |
117 | ||
ec06701b AX |
118 | #define TQENT_FLAG_PREALLOC 0x1 |
119 | #define TQENT_FLAG_CANCEL 0x2 | |
d9acd930 | 120 | |
2c02b71b | 121 | typedef struct taskq_thread { |
472a34ca BB |
122 | struct list_head tqt_thread_list; |
123 | struct list_head tqt_active_list; | |
124 | struct task_struct *tqt_thread; | |
125 | taskq_t *tqt_tq; | |
126 | taskqid_t tqt_id; | |
d9acd930 | 127 | taskq_ent_t *tqt_task; |
472a34ca | 128 | uintptr_t tqt_flags; |
2c02b71b PS |
129 | } taskq_thread_t; |
130 | ||
e9cb2b4f BB |
131 | /* Global system-wide dynamic task queue available for all consumers */ |
132 | extern taskq_t *system_taskq; | |
ec06701b AX |
133 | /* Global dynamic task queue for long delay */ |
134 | extern taskq_t *system_delay_taskq; | |
135 | ||
136 | /* List of all taskqs */ | |
137 | extern struct list_head tq_list; | |
138 | extern struct rw_semaphore tq_list_sem; | |
e9cb2b4f | 139 | |
aed8671c | 140 | extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); |
d9acd930 BB |
141 | extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, |
142 | uint_t, clock_t); | |
aed8671c BB |
143 | extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, |
144 | taskq_ent_t *); | |
145 | extern int taskq_empty_ent(taskq_ent_t *); | |
146 | extern void taskq_init_ent(taskq_ent_t *); | |
147 | extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); | |
148 | extern void taskq_destroy(taskq_t *); | |
149 | extern void taskq_wait_id(taskq_t *, taskqid_t); | |
f6188ddd | 150 | extern void taskq_wait_outstanding(taskq_t *, taskqid_t); |
aed8671c | 151 | extern void taskq_wait(taskq_t *); |
d9acd930 | 152 | extern int taskq_cancel_id(taskq_t *, taskqid_t); |
ec06701b | 153 | extern int taskq_member(taskq_t *, kthread_t *); |
aed8671c | 154 | |
ec06701b | 155 | #define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \ |
aed8671c | 156 | taskq_create(name, nthreads, pri, min, max, flags) |
ec06701b | 157 | #define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \ |
aed8671c | 158 | taskq_create(name, nthreads, maxclsyspri, min, max, flags) |
bcd68186 | 159 | |
e9cb2b4f BB |
160 | int spl_taskq_init(void); |
161 | void spl_taskq_fini(void); | |
162 | ||
09b414e8 | 163 | #endif /* _SPL_TASKQ_H */ |