17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
52e0c549Jonathan Adams * Common Development and Distribution License (the "License").
62e0c549Jonathan Adams * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
222e0c549Jonathan Adams * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
24b819ceaGordon Ross *
25b819ceaGordon Ross * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
264c99eccTim Kordas * Copyright 2018, Joyent, Inc.
277c478bdstevel@tonic-gate */
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#ifndef	_SYS_TASKQ_H
307c478bdstevel@tonic-gate#define	_SYS_TASKQ_H
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#include <sys/types.h>
337c478bdstevel@tonic-gate#include <sys/thread.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#ifdef	__cplusplus
367c478bdstevel@tonic-gateextern "C" {
377c478bdstevel@tonic-gate#endif
387c478bdstevel@tonic-gate
397c478bdstevel@tonic-gate#define	TASKQ_NAMELEN	31
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gatetypedef struct taskq taskq_t;
427c478bdstevel@tonic-gatetypedef uintptr_t taskqid_t;
437c478bdstevel@tonic-gatetypedef void (task_func_t)(void *);
447c478bdstevel@tonic-gate
4535a5a35Jonathan Adamsstruct proc;
4635a5a35Jonathan Adams
477c478bdstevel@tonic-gate/*
487c478bdstevel@tonic-gate * Public flags for taskq_create(): bit range 0-15
497c478bdstevel@tonic-gate */
507c478bdstevel@tonic-gate#define	TASKQ_PREPOPULATE	0x0001	/* Prepopulate with threads and data */
517c478bdstevel@tonic-gate#define	TASKQ_CPR_SAFE		0x0002	/* Use CPR safe protocol */
527c478bdstevel@tonic-gate#define	TASKQ_DYNAMIC		0x0004	/* Use dynamic thread scheduling */
532e0c549Jonathan Adams#define	TASKQ_THREADS_CPU_PCT	0x0008	/* number of threads as % of ncpu */
5435a5a35Jonathan Adams#define	TASKQ_DC_BATCH		0x0010	/* Taskq uses SDC in batch mode */
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate/*
577c478bdstevel@tonic-gate * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
587c478bdstevel@tonic-gate * KM_SLEEP/KM_NOSLEEP.
597c478bdstevel@tonic-gate */
607c478bdstevel@tonic-gate#define	TQ_SLEEP	0x00	/* Can block for memory */
617c478bdstevel@tonic-gate#define	TQ_NOSLEEP	0x01	/* cannot block for memory; may fail */
627c478bdstevel@tonic-gate#define	TQ_NOQUEUE	0x02	/* Do not enqueue if can't dispatch */
637c478bdstevel@tonic-gate#define	TQ_NOALLOC	0x04	/* cannot allocate memory; may fail */
6435a5a35Jonathan Adams#define	TQ_FRONT	0x08	/* Put task at the front of the queue */
657c478bdstevel@tonic-gate
66fc8ae2eToomas Soome#define	TASKQID_INVALID	((taskqid_t)0)
67fc8ae2eToomas Soome
68b819ceaGordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gateextern taskq_t *system_taskq;
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gateextern void	taskq_init(void);
732e0c549Jonathan Adamsextern void	taskq_mp_init(void);
747c478bdstevel@tonic-gate
757c478bdstevel@tonic-gateextern taskq_t	*taskq_create(const char *, int, pri_t, int, int, uint_t);
767c478bdstevel@tonic-gateextern taskq_t	*taskq_create_instance(const char *, int, int, pri_t, int,
777c478bdstevel@tonic-gate    int, uint_t);
7835a5a35Jonathan Adamsextern taskq_t	*taskq_create_proc(const char *, int, pri_t, int, int,
7935a5a35Jonathan Adams    struct proc *, uint_t);
8035a5a35Jonathan Adamsextern taskq_t	*taskq_create_sysdc(const char *, int, int, int,
8135a5a35Jonathan Adams    struct proc *, uint_t, uint_t);
827c478bdstevel@tonic-gateextern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
837c478bdstevel@tonic-gateextern void	nulltask(void *);
847c478bdstevel@tonic-gateextern void	taskq_destroy(taskq_t *);
857c478bdstevel@tonic-gateextern void	taskq_wait(taskq_t *);
86a3874b8Toomas Soomevoid	taskq_wait_id(taskq_t *, taskqid_t);
874c99eccTim Kordasextern boolean_t taskq_empty(taskq_t *);
887c478bdstevel@tonic-gateextern void	taskq_suspend(taskq_t *);
897c478bdstevel@tonic-gateextern int	taskq_suspended(taskq_t *);
907c478bdstevel@tonic-gateextern void	taskq_resume(taskq_t *);
917c478bdstevel@tonic-gateextern int	taskq_member(taskq_t *, kthread_t *);
927c478bdstevel@tonic-gate
937c478bdstevel@tonic-gate#endif	/* _KERNEL */
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gate#ifdef	__cplusplus
967c478bdstevel@tonic-gate}
977c478bdstevel@tonic-gate#endif
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gate#endif	/* _SYS_TASKQ_H */
100