xref: /illumos-gate/usr/src/uts/common/sys/taskq.h (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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 (the "License").
6  * You may not use this file except in compliance with the License.
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 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
26  * Copyright 2018, Joyent, Inc.
27  * Copyright 2023 RackTop Systems, Inc.
28  */
29 
30 #ifndef	_SYS_TASKQ_H
31 #define	_SYS_TASKQ_H
32 
33 #include <sys/types.h>
34 #include <sys/thread.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #define	TASKQ_NAMELEN	31
41 
42 typedef struct taskq taskq_t;
43 typedef uintptr_t taskqid_t;
44 typedef void (task_func_t)(void *);
45 
46 struct proc;
47 
48 /*
49  * Public flags for taskq_create(): bit range 0-15
50  */
51 #define	TASKQ_PREPOPULATE	0x0001	/* Prepopulate with threads and data */
52 #define	TASKQ_CPR_SAFE		0x0002	/* Use CPR safe protocol */
53 #define	TASKQ_DYNAMIC		0x0004	/* Use dynamic thread scheduling */
54 #define	TASKQ_THREADS_CPU_PCT	0x0008	/* number of threads as % of ncpu */
55 #define	TASKQ_DC_BATCH		0x0010	/* Taskq uses SDC in batch mode */
56 #define	TASKQ_THREADS_LWP	0x0020	/* create LWP threads */
57 
58 /*
59  * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
60  * KM_SLEEP/KM_NOSLEEP.
61  */
62 #define	TQ_SLEEP	0x00	/* Can block for memory */
63 #define	TQ_NOSLEEP	0x01	/* cannot block for memory; may fail */
64 #define	TQ_NOQUEUE	0x02	/* Do not enqueue if can't dispatch */
65 #define	TQ_NOALLOC	0x04	/* cannot allocate memory; may fail */
66 #define	TQ_FRONT	0x08	/* Put task at the front of the queue */
67 
68 #define	TASKQID_INVALID	((taskqid_t)0)
69 
70 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
71 
72 extern taskq_t *system_taskq;
73 
74 extern void	taskq_init(void);
75 extern void	taskq_mp_init(void);
76 
77 extern taskq_t	*taskq_create(const char *, int, pri_t, int, int, uint_t);
78 extern taskq_t	*taskq_create_instance(const char *, int, int, pri_t, int,
79     int, uint_t);
80 extern taskq_t	*taskq_create_proc(const char *, int, pri_t, int, int,
81     struct proc *, uint_t);
82 extern taskq_t	*taskq_create_sysdc(const char *, int, int, int,
83     struct proc *, uint_t, uint_t);
84 extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
85 extern void	nulltask(void *);
86 extern void	taskq_destroy(taskq_t *);
87 extern void	taskq_wait(taskq_t *);
88 void	taskq_wait_id(taskq_t *, taskqid_t);
89 extern boolean_t taskq_empty(taskq_t *);
90 extern void	taskq_suspend(taskq_t *);
91 extern int	taskq_suspended(taskq_t *);
92 extern void	taskq_resume(taskq_t *);
93 extern int	taskq_member(taskq_t *, kthread_t *);
94 
95 #endif	/* _KERNEL */
96 
97 #ifdef	__cplusplus
98 }
99 #endif
100 
101 #endif	/* _SYS_TASKQ_H */
102