xref: /freebsd/sys/sys/gtaskqueue.h (revision 9b10f59a10b7adff0a5ea3b0fd182d521c3da643)
123ac9029SStephen Hurd /*-
2*9b10f59aSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*9b10f59aSPedro F. Giffuni  *
423ac9029SStephen Hurd  * Copyright (c) 2014 Jeffrey Roberson <jeff@freebsd.org>
523ac9029SStephen Hurd  * Copyright (c) 2016 Matthew Macy <mmacy@nextbsd.org>
623ac9029SStephen Hurd  * All rights reserved.
723ac9029SStephen Hurd  *
823ac9029SStephen Hurd  * Redistribution and use in source and binary forms, with or without
923ac9029SStephen Hurd  * modification, are permitted provided that the following conditions
1023ac9029SStephen Hurd  * are met:
1123ac9029SStephen Hurd  * 1. Redistributions of source code must retain the above copyright
1223ac9029SStephen Hurd  *    notice, this list of conditions and the following disclaimer.
1323ac9029SStephen Hurd  * 2. Redistributions in binary form must reproduce the above copyright
1423ac9029SStephen Hurd  *    notice, this list of conditions and the following disclaimer in the
1523ac9029SStephen Hurd  *    documentation and/or other materials provided with the distribution.
1623ac9029SStephen Hurd  *
1723ac9029SStephen Hurd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1823ac9029SStephen Hurd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1923ac9029SStephen Hurd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2023ac9029SStephen Hurd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2123ac9029SStephen Hurd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2223ac9029SStephen Hurd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323ac9029SStephen Hurd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2423ac9029SStephen Hurd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2523ac9029SStephen Hurd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2623ac9029SStephen Hurd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2723ac9029SStephen Hurd  * SUCH DAMAGE.
2823ac9029SStephen Hurd  *
2923ac9029SStephen Hurd  * $FreeBSD$
3023ac9029SStephen Hurd  */
3123ac9029SStephen Hurd 
3223ac9029SStephen Hurd #ifndef _SYS_GTASKQUEUE_H_
3323ac9029SStephen Hurd #define _SYS_GTASKQUEUE_H_
3423ac9029SStephen Hurd #include <sys/taskqueue.h>
3523ac9029SStephen Hurd 
3623ac9029SStephen Hurd #ifndef _KERNEL
371d64db52SConrad Meyer #error "no user-serviceable parts inside"
3823ac9029SStephen Hurd #endif
3923ac9029SStephen Hurd 
4023ac9029SStephen Hurd struct gtaskqueue;
4123ac9029SStephen Hurd typedef void (*gtaskqueue_enqueue_fn)(void *context);
4223ac9029SStephen Hurd 
4323ac9029SStephen Hurd /*
4423ac9029SStephen Hurd  * Taskqueue groups.  Manages dynamic thread groups and irq binding for
4523ac9029SStephen Hurd  * device and other tasks.
4623ac9029SStephen Hurd  */
4723ac9029SStephen Hurd 
4823ac9029SStephen Hurd void	gtaskqueue_block(struct gtaskqueue *queue);
4923ac9029SStephen Hurd void	gtaskqueue_unblock(struct gtaskqueue *queue);
5023ac9029SStephen Hurd 
5123ac9029SStephen Hurd int	gtaskqueue_cancel(struct gtaskqueue *queue, struct gtask *gtask);
5223ac9029SStephen Hurd void	gtaskqueue_drain(struct gtaskqueue *queue, struct gtask *task);
5323ac9029SStephen Hurd void	gtaskqueue_drain_all(struct gtaskqueue *queue);
5423ac9029SStephen Hurd 
5523ac9029SStephen Hurd int grouptaskqueue_enqueue(struct gtaskqueue *queue, struct gtask *task);
5623ac9029SStephen Hurd void	taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *grptask,
5723ac9029SStephen Hurd 	    void *uniq, int irq, char *name);
5823ac9029SStephen Hurd int		taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *grptask,
5923ac9029SStephen Hurd 		void *uniq, int cpu, int irq, char *name);
6023ac9029SStephen Hurd void	taskqgroup_detach(struct taskqgroup *qgroup, struct grouptask *gtask);
6123ac9029SStephen Hurd struct taskqgroup *taskqgroup_create(char *name);
6223ac9029SStephen Hurd void	taskqgroup_destroy(struct taskqgroup *qgroup);
63ab2e3f79SStephen Hurd int	taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride);
6423ac9029SStephen Hurd 
6523ac9029SStephen Hurd #define TASK_ENQUEUED			0x1
6623ac9029SStephen Hurd #define TASK_SKIP_WAKEUP		0x2
6723ac9029SStephen Hurd 
6823ac9029SStephen Hurd 
6923ac9029SStephen Hurd #define GTASK_INIT(task, flags, priority, func, context) do {	\
7023ac9029SStephen Hurd 	(task)->ta_flags = flags;				\
7123ac9029SStephen Hurd 	(task)->ta_priority = (priority);		\
7223ac9029SStephen Hurd 	(task)->ta_func = (func);			\
7323ac9029SStephen Hurd 	(task)->ta_context = (context);			\
7423ac9029SStephen Hurd } while (0)
7523ac9029SStephen Hurd 
7623ac9029SStephen Hurd #define	GROUPTASK_INIT(gtask, priority, func, context)	\
7723ac9029SStephen Hurd 	GTASK_INIT(&(gtask)->gt_task, TASK_SKIP_WAKEUP, priority, func, context)
7823ac9029SStephen Hurd 
7923ac9029SStephen Hurd #define	GROUPTASK_ENQUEUE(gtask)			\
8023ac9029SStephen Hurd 	grouptaskqueue_enqueue((gtask)->gt_taskqueue, &(gtask)->gt_task)
8123ac9029SStephen Hurd 
8223ac9029SStephen Hurd #define TASKQGROUP_DECLARE(name)			\
8323ac9029SStephen Hurd extern struct taskqgroup *qgroup_##name
8423ac9029SStephen Hurd 
85ab2e3f79SStephen Hurd #define TASKQGROUP_DEFINE(name, cnt, stride)				\
8623ac9029SStephen Hurd 									\
8723ac9029SStephen Hurd struct taskqgroup *qgroup_##name;					\
8823ac9029SStephen Hurd 									\
8923ac9029SStephen Hurd static void								\
9023ac9029SStephen Hurd taskqgroup_define_##name(void *arg)					\
9123ac9029SStephen Hurd {									\
9223ac9029SStephen Hurd 	qgroup_##name = taskqgroup_create(#name);			\
9323ac9029SStephen Hurd }									\
94ab2e3f79SStephen Hurd 									\
959657edd7SConrad Meyer SYSINIT(taskqgroup_##name, SI_SUB_TASKQ, SI_ORDER_FIRST,		\
96ab2e3f79SStephen Hurd 	taskqgroup_define_##name, NULL);				\
97ab2e3f79SStephen Hurd 									\
98ab2e3f79SStephen Hurd static void								\
99ab2e3f79SStephen Hurd taskqgroup_adjust_##name(void *arg)					\
100ab2e3f79SStephen Hurd {									\
101ab2e3f79SStephen Hurd 	taskqgroup_adjust(qgroup_##name, (cnt), (stride));		\
102ab2e3f79SStephen Hurd }									\
103ab2e3f79SStephen Hurd 									\
104ab2e3f79SStephen Hurd SYSINIT(taskqgroup_adj_##name, SI_SUB_SMP, SI_ORDER_ANY,		\
105ab2e3f79SStephen Hurd 	taskqgroup_adjust_##name, NULL)
106d23d2945SSean Bruno 
10723ac9029SStephen Hurd TASKQGROUP_DECLARE(net);
108d945ed64SSean Bruno TASKQGROUP_DECLARE(softirq);
10923ac9029SStephen Hurd 
11023ac9029SStephen Hurd #endif /* !_SYS_GTASKQUEUE_H_ */
111