author | Garrett D'Amore <garrett@nexenta.com> |
Wed, 27 Jul 2011 07:13:44 -0700 | |
changeset 13414 | b42c1f0432b6 |
parent 11854 | 5351ddd19d45 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
9515
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
0 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
11854
5351ddd19d45
6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents:
11173
diff
changeset
|
22 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
0 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
13414
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
25 |
/* |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
26 |
* Copyright 2011 Nexenta Systems, Inc. All rights reserved. |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
27 |
*/ |
0 | 28 |
|
29 |
#ifndef _SYS_TASKQ_IMPL_H |
|
30 |
#define _SYS_TASKQ_IMPL_H |
|
31 |
||
32 |
#include <sys/taskq.h> |
|
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
33 |
#include <sys/inttypes.h> |
0 | 34 |
#include <sys/vmem.h> |
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
35 |
#include <sys/list.h> |
0 | 36 |
#include <sys/kstat.h> |
37 |
||
38 |
#ifdef __cplusplus |
|
39 |
extern "C" { |
|
40 |
#endif |
|
41 |
||
42 |
typedef struct taskq_bucket taskq_bucket_t; |
|
43 |
||
44 |
typedef struct taskq_ent { |
|
45 |
struct taskq_ent *tqent_next; |
|
46 |
struct taskq_ent *tqent_prev; |
|
47 |
task_func_t *tqent_func; |
|
48 |
void *tqent_arg; |
|
13414
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
49 |
union { |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
50 |
taskq_bucket_t *tqent_bucket; |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
51 |
uintptr_t tqent_flags; |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
52 |
} tqent_un; |
0 | 53 |
kthread_t *tqent_thread; |
54 |
kcondvar_t tqent_cv; |
|
55 |
} taskq_ent_t; |
|
56 |
||
13414
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
57 |
#define TQENT_FLAG_PREALLOC 0x1 |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
58 |
|
0 | 59 |
/* |
60 |
* Taskq Statistics fields are not protected by any locks. |
|
61 |
*/ |
|
62 |
typedef struct tqstat { |
|
63 |
uint_t tqs_hits; |
|
64 |
uint_t tqs_misses; |
|
65 |
uint_t tqs_overflow; /* no threads to allocate */ |
|
66 |
uint_t tqs_tcreates; /* threads created */ |
|
67 |
uint_t tqs_tdeaths; /* threads died */ |
|
68 |
uint_t tqs_maxthreads; /* max # of alive threads */ |
|
69 |
uint_t tqs_nomem; /* # of times there were no memory */ |
|
70 |
uint_t tqs_disptcreates; |
|
71 |
} tqstat_t; |
|
72 |
||
73 |
/* |
|
74 |
* Per-CPU hash bucket manages taskq_bent_t structures using freelist. |
|
75 |
*/ |
|
76 |
struct taskq_bucket { |
|
77 |
kmutex_t tqbucket_lock; |
|
78 |
taskq_t *tqbucket_taskq; /* Enclosing taskq */ |
|
79 |
taskq_ent_t tqbucket_freelist; |
|
80 |
uint_t tqbucket_nalloc; /* # of allocated entries */ |
|
81 |
uint_t tqbucket_nfree; /* # of free entries */ |
|
82 |
kcondvar_t tqbucket_cv; |
|
83 |
ushort_t tqbucket_flags; |
|
84 |
hrtime_t tqbucket_totaltime; |
|
85 |
tqstat_t tqbucket_stat; |
|
86 |
}; |
|
87 |
||
88 |
/* |
|
89 |
* Bucket flags. |
|
90 |
*/ |
|
91 |
#define TQBUCKET_CLOSE 0x01 |
|
92 |
#define TQBUCKET_SUSPEND 0x02 |
|
93 |
||
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
94 |
#define TASKQ_INTERFACE_FLAGS 0x0000ffff /* defined in <sys/taskq.h> */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
95 |
|
0 | 96 |
/* |
97 |
* taskq implementation flags: bit range 16-31 |
|
98 |
*/ |
|
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
99 |
#define TASKQ_CHANGING 0x00010000 /* nthreads != target */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
100 |
#define TASKQ_SUSPENDED 0x00020000 /* taskq is suspended */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
101 |
#define TASKQ_NOINSTANCE 0x00040000 /* no instance number */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
102 |
#define TASKQ_THREAD_CREATED 0x00080000 /* a thread has been created */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
103 |
#define TASKQ_DUTY_CYCLE 0x00100000 /* using the SDC class */ |
0 | 104 |
|
105 |
struct taskq { |
|
106 |
char tq_name[TASKQ_NAMELEN + 1]; |
|
107 |
kmutex_t tq_lock; |
|
108 |
krwlock_t tq_threadlock; |
|
109 |
kcondvar_t tq_dispatch_cv; |
|
110 |
kcondvar_t tq_wait_cv; |
|
9515
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
111 |
kcondvar_t tq_exit_cv; |
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
112 |
pri_t tq_pri; /* Scheduling priority */ |
0 | 113 |
uint_t tq_flags; |
114 |
int tq_active; |
|
115 |
int tq_nthreads; |
|
9515
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
116 |
int tq_nthreads_target; |
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
117 |
int tq_nthreads_max; |
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
118 |
int tq_threads_ncpus_pct; |
0 | 119 |
int tq_nalloc; |
120 |
int tq_minalloc; |
|
121 |
int tq_maxalloc; |
|
11854
5351ddd19d45
6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents:
11173
diff
changeset
|
122 |
kcondvar_t tq_maxalloc_cv; |
5351ddd19d45
6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents:
11173
diff
changeset
|
123 |
int tq_maxalloc_wait; |
0 | 124 |
taskq_ent_t *tq_freelist; |
125 |
taskq_ent_t tq_task; |
|
126 |
int tq_maxsize; |
|
127 |
taskq_bucket_t *tq_buckets; /* Per-cpu array of buckets */ |
|
128 |
int tq_instance; |
|
129 |
uint_t tq_nbuckets; /* # of buckets (2^n) */ |
|
130 |
union { |
|
131 |
kthread_t *_tq_thread; |
|
132 |
kthread_t **_tq_threadlist; |
|
133 |
} tq_thr; |
|
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
134 |
|
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
135 |
list_node_t tq_cpupct_link; /* linkage for taskq_cpupct_list */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
136 |
struct proc *tq_proc; /* process for taskq threads */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
137 |
int tq_cpupart; /* cpupart id bound to */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
138 |
uint_t tq_DC; /* duty cycle for SDC */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
139 |
|
0 | 140 |
/* |
141 |
* Statistics. |
|
142 |
*/ |
|
143 |
kstat_t *tq_kstat; /* Exported statistics */ |
|
144 |
hrtime_t tq_totaltime; /* Time spent processing tasks */ |
|
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
145 |
uint64_t tq_tasks; /* Total # of tasks posted */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
9515
diff
changeset
|
146 |
uint64_t tq_executed; /* Total # of tasks executed */ |
0 | 147 |
int tq_maxtasks; /* Max number of tasks in the queue */ |
148 |
int tq_tcreates; |
|
149 |
int tq_tdeaths; |
|
150 |
}; |
|
151 |
||
13414
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
152 |
/* Special form of taskq dispatch that uses preallocated entries. */ |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
153 |
void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, taskq_ent_t *); |
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
154 |
|
b42c1f0432b6
734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents:
11854
diff
changeset
|
155 |
|
0 | 156 |
#define tq_thread tq_thr._tq_thread |
157 |
#define tq_threadlist tq_thr._tq_threadlist |
|
158 |
||
9515
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
159 |
/* The MAX guarantees we have at least one thread */ |
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
160 |
#define TASKQ_THREADS_PCT(ncpus, pct) MAX(((ncpus) * (pct)) / 100, 1) |
d3b739d9d043
6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
0
diff
changeset
|
161 |
|
0 | 162 |
#ifdef __cplusplus |
163 |
} |
|
164 |
#endif |
|
165 |
||
166 |
#endif /* _SYS_TASKQ_IMPL_H */ |