]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/taskq.h
Linux 4.8 compat: rw_semaphore atomic_long_t count
[mirror_spl.git] / include / sys / taskq.h
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>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
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.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
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
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #ifndef _SPL_TASKQ_H
26 #define _SPL_TASKQ_H
27
28 #include <linux/module.h>
29 #include <linux/gfp.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/kthread.h>
33 #include <sys/types.h>
34 #include <sys/thread.h>
35 #include <sys/rwlock.h>
36
37 #define TASKQ_NAMELEN 31
38
39 #define TASKQ_PREPOPULATE 0x00000001
40 #define TASKQ_CPR_SAFE 0x00000002
41 #define TASKQ_DYNAMIC 0x00000004
42 #define TASKQ_THREADS_CPU_PCT 0x00000008
43 #define TASKQ_DC_BATCH 0x00000010
44 #define TASKQ_ACTIVE 0x80000000
45
46 /*
47 * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
48 * KM_SLEEP/KM_NOSLEEP. TQ_NOQUEUE/TQ_NOALLOC are set particularly
49 * large so as not to conflict with already used GFP_* defines.
50 */
51 #define TQ_SLEEP 0x00000000
52 #define TQ_NOSLEEP 0x00000001
53 #define TQ_PUSHPAGE 0x00000002
54 #define TQ_NOQUEUE 0x01000000
55 #define TQ_NOALLOC 0x02000000
56 #define TQ_NEW 0x04000000
57 #define TQ_FRONT 0x08000000
58
59 /*
60 * spin_lock(lock) and spin_lock_nested(lock,0) are equivalent,
61 * so TQ_LOCK_DYNAMIC must not evaluate to 0
62 */
63 typedef enum tq_lock_role {
64 TQ_LOCK_GENERAL = 0,
65 TQ_LOCK_DYNAMIC = 1,
66 } tq_lock_role_t;
67
68 typedef unsigned long taskqid_t;
69 typedef void (task_func_t)(void *);
70
71 typedef struct taskq {
72 spinlock_t tq_lock; /* protects taskq_t */
73 char *tq_name; /* taskq name */
74 int tq_instance; /* instance of tq_name */
75 struct list_head tq_thread_list; /* list of all threads */
76 struct list_head tq_active_list; /* list of active threads */
77 int tq_nactive; /* # of active threads */
78 int tq_nthreads; /* # of existing threads */
79 int tq_nspawn; /* # of threads being spawned */
80 int tq_maxthreads; /* # of threads maximum */
81 int tq_pri; /* priority */
82 int tq_minalloc; /* min taskq_ent_t pool size */
83 int tq_maxalloc; /* max taskq_ent_t pool size */
84 int tq_nalloc; /* cur taskq_ent_t pool size */
85 uint_t tq_flags; /* flags */
86 taskqid_t tq_next_id; /* next pend/work id */
87 taskqid_t tq_lowest_id; /* lowest pend/work id */
88 struct list_head tq_free_list; /* free taskq_ent_t's */
89 struct list_head tq_pend_list; /* pending taskq_ent_t's */
90 struct list_head tq_prio_list; /* priority pending taskq_ent_t's */
91 struct list_head tq_delay_list; /* delayed taskq_ent_t's */
92 struct list_head tq_taskqs; /* all taskq_t's */
93 wait_queue_head_t tq_work_waitq; /* new work waitq */
94 wait_queue_head_t tq_wait_waitq; /* wait waitq */
95 tq_lock_role_t tq_lock_class; /* class when taking tq_lock */
96 } taskq_t;
97
98 typedef struct taskq_ent {
99 spinlock_t tqent_lock;
100 wait_queue_head_t tqent_waitq;
101 struct timer_list tqent_timer;
102 struct list_head tqent_list;
103 taskqid_t tqent_id;
104 task_func_t *tqent_func;
105 void *tqent_arg;
106 taskq_t *tqent_taskq;
107 uintptr_t tqent_flags;
108 unsigned long tqent_birth;
109 } taskq_ent_t;
110
111 #define TQENT_FLAG_PREALLOC 0x1
112 #define TQENT_FLAG_CANCEL 0x2
113
114 typedef struct taskq_thread {
115 struct list_head tqt_thread_list;
116 struct list_head tqt_active_list;
117 struct task_struct *tqt_thread;
118 taskq_t *tqt_tq;
119 taskqid_t tqt_id;
120 taskq_ent_t *tqt_task;
121 uintptr_t tqt_flags;
122 } taskq_thread_t;
123
124 /* Global system-wide dynamic task queue available for all consumers */
125 extern taskq_t *system_taskq;
126
127 /* List of all taskqs */
128 extern struct list_head tq_list;
129 extern struct rw_semaphore tq_list_sem;
130
131 extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
132 extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *,
133 uint_t, clock_t);
134 extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
135 taskq_ent_t *);
136 extern int taskq_empty_ent(taskq_ent_t *);
137 extern void taskq_init_ent(taskq_ent_t *);
138 extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
139 extern void taskq_destroy(taskq_t *);
140 extern void taskq_wait_id(taskq_t *, taskqid_t);
141 extern void taskq_wait_outstanding(taskq_t *, taskqid_t);
142 extern void taskq_wait(taskq_t *);
143 extern int taskq_cancel_id(taskq_t *, taskqid_t);
144 extern int taskq_member(taskq_t *, kthread_t *);
145
146 #define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \
147 taskq_create(name, nthreads, pri, min, max, flags)
148 #define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \
149 taskq_create(name, nthreads, maxclsyspri, min, max, flags)
150
151 int spl_taskq_init(void);
152 void spl_taskq_fini(void);
153
154 #endif /* _SPL_TASKQ_H */