2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2014 Jeffrey Roberson <jeff@freebsd.org>
5 * Copyright (c) 2016 Matthew Macy <mmacy@mattmacy.io>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef _SYS_GTASKQUEUE_H_
33 #define _SYS_GTASKQUEUE_H_
34 #include <sys/taskqueue.h>
37 #error "no user-serviceable parts inside"
41 typedef void (*gtaskqueue_enqueue_fn)(void *context);
44 * Taskqueue groups. Manages dynamic thread groups and irq binding for
45 * device and other tasks.
48 void gtaskqueue_block(struct gtaskqueue *queue);
49 void gtaskqueue_unblock(struct gtaskqueue *queue);
51 int gtaskqueue_cancel(struct gtaskqueue *queue, struct gtask *gtask);
52 void gtaskqueue_drain(struct gtaskqueue *queue, struct gtask *task);
53 void gtaskqueue_drain_all(struct gtaskqueue *queue);
55 int grouptaskqueue_enqueue(struct gtaskqueue *queue, struct gtask *task);
56 void taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *grptask,
57 void *uniq, int irq, char *name);
58 int taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *grptask,
59 void *uniq, int cpu, int irq, char *name);
60 void taskqgroup_detach(struct taskqgroup *qgroup, struct grouptask *gtask);
61 struct taskqgroup *taskqgroup_create(char *name);
62 void taskqgroup_destroy(struct taskqgroup *qgroup);
63 int taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride);
65 #define TASK_ENQUEUED 0x1
66 #define TASK_SKIP_WAKEUP 0x2
69 #define GTASK_INIT(task, flags, priority, func, context) do { \
70 (task)->ta_flags = flags; \
71 (task)->ta_priority = (priority); \
72 (task)->ta_func = (func); \
73 (task)->ta_context = (context); \
76 #define GROUPTASK_INIT(gtask, priority, func, context) \
77 GTASK_INIT(&(gtask)->gt_task, TASK_SKIP_WAKEUP, priority, func, context)
79 #define GROUPTASK_ENQUEUE(gtask) \
80 grouptaskqueue_enqueue((gtask)->gt_taskqueue, &(gtask)->gt_task)
82 #define TASKQGROUP_DECLARE(name) \
83 extern struct taskqgroup *qgroup_##name
85 #define TASKQGROUP_DEFINE(name, cnt, stride) \
87 struct taskqgroup *qgroup_##name; \
90 taskqgroup_define_##name(void *arg) \
92 qgroup_##name = taskqgroup_create(#name); \
95 SYSINIT(taskqgroup_##name, SI_SUB_TASKQ, SI_ORDER_FIRST, \
96 taskqgroup_define_##name, NULL); \
99 taskqgroup_adjust_##name(void *arg) \
101 taskqgroup_adjust(qgroup_##name, (cnt), (stride)); \
104 SYSINIT(taskqgroup_adj_##name, SI_SUB_SMP, SI_ORDER_ANY, \
105 taskqgroup_adjust_##name, NULL)
107 TASKQGROUP_DECLARE(net);
108 TASKQGROUP_DECLARE(softirq);
110 #endif /* !_SYS_GTASKQUEUE_H_ */