xref: /titanic_44/usr/src/uts/common/sys/taskq_impl.h (revision 24db46411fd54f70c35b94bb952eb7ba040e43b4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_TASKQ_IMPL_H
28 #define	_SYS_TASKQ_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/taskq.h>
33 #include <sys/vmem.h>
34 #include <sys/kstat.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 typedef struct taskq_bucket taskq_bucket_t;
41 
42 typedef struct taskq_ent {
43 	struct taskq_ent	*tqent_next;
44 	struct taskq_ent	*tqent_prev;
45 	task_func_t		*tqent_func;
46 	void			*tqent_arg;
47 	taskq_bucket_t		*tqent_bucket;
48 	kthread_t		*tqent_thread;
49 	kcondvar_t		tqent_cv;
50 } taskq_ent_t;
51 
52 /*
53  * Taskq Statistics fields are not protected by any locks.
54  */
55 typedef struct tqstat {
56 	uint_t		tqs_hits;
57 	uint_t		tqs_misses;
58 	uint_t		tqs_overflow;	/* no threads to allocate   */
59 	uint_t		tqs_tcreates;	/* threads created 	*/
60 	uint_t		tqs_tdeaths;	/* threads died		*/
61 	uint_t		tqs_maxthreads;	/* max # of alive threads */
62 	uint_t		tqs_nomem;	/* # of times there were no memory */
63 	uint_t		tqs_disptcreates;
64 } tqstat_t;
65 
66 /*
67  * Per-CPU hash bucket manages taskq_bent_t structures using freelist.
68  */
69 struct taskq_bucket {
70 	kmutex_t	tqbucket_lock;
71 	taskq_t		*tqbucket_taskq;	/* Enclosing taskq */
72 	taskq_ent_t	tqbucket_freelist;
73 	uint_t		tqbucket_nalloc;	/* # of allocated entries */
74 	uint_t		tqbucket_nfree;		/* # of free entries */
75 	kcondvar_t	tqbucket_cv;
76 	ushort_t	tqbucket_flags;
77 	hrtime_t	tqbucket_totaltime;
78 	tqstat_t	tqbucket_stat;
79 };
80 
81 /*
82  * Bucket flags.
83  */
84 #define	TQBUCKET_CLOSE		0x01
85 #define	TQBUCKET_SUSPEND	0x02
86 
87 /*
88  * taskq implementation flags: bit range 16-31
89  */
90 #define	TASKQ_ACTIVE		0x00010000
91 #define	TASKQ_SUSPENDED		0x00020000
92 #define	TASKQ_NOINSTANCE	0x00040000
93 
94 struct taskq {
95 	char		tq_name[TASKQ_NAMELEN + 1];
96 	kmutex_t	tq_lock;
97 	krwlock_t	tq_threadlock;
98 	kcondvar_t	tq_dispatch_cv;
99 	kcondvar_t	tq_wait_cv;
100 	uint_t		tq_flags;
101 	int		tq_active;
102 	int		tq_nthreads;
103 	int		tq_nalloc;
104 	int		tq_minalloc;
105 	int		tq_maxalloc;
106 	taskq_ent_t	*tq_freelist;
107 	taskq_ent_t	tq_task;
108 	int		tq_maxsize;
109 	pri_t		tq_pri;		/* Scheduling priority	    */
110 	taskq_bucket_t	*tq_buckets;	/* Per-cpu array of buckets */
111 	int		tq_instance;
112 	uint_t		tq_nbuckets;	/* # of buckets	(2^n)	    */
113 	union {
114 		kthread_t *_tq_thread;
115 		kthread_t **_tq_threadlist;
116 	}		tq_thr;
117 	/*
118 	 * Statistics.
119 	 */
120 	kstat_t		*tq_kstat;	/* Exported statistics */
121 	hrtime_t	tq_totaltime;	/* Time spent processing tasks */
122 	int		tq_tasks;	/* Total # of tasks posted */
123 	int		tq_executed;	/* Total # of tasks executed */
124 	int		tq_maxtasks;	/* Max number of tasks in the queue */
125 	int		tq_tcreates;
126 	int		tq_tdeaths;
127 };
128 
129 #define	tq_thread tq_thr._tq_thread
130 #define	tq_threadlist tq_thr._tq_threadlist
131 
132 #ifdef	__cplusplus
133 }
134 #endif
135 
136 #endif	/* _SYS_TASKQ_IMPL_H */
137