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 https://opensource.org/licenses/CDDL-1.0. 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 26 #ifndef _SYS_TASKQ_H 27 #define _SYS_TASKQ_H 28 29 #ifdef _KERNEL 30 31 #include <sys/types.h> 32 #include <sys/proc.h> 33 #include <sys/queue.h> 34 #include <sys/taskqueue.h> 35 #include <sys/thread.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #define TASKQ_NAMELEN 31 42 43 typedef struct taskq { 44 struct taskqueue *tq_queue; 45 int tq_nthreads; 46 } taskq_t; 47 48 typedef uintptr_t taskqid_t; 49 typedef void (task_func_t)(void *); 50 51 typedef struct taskq_ent { 52 union { 53 struct task tqent_task; 54 struct timeout_task tqent_timeout_task; 55 }; 56 task_func_t *tqent_func; 57 void *tqent_arg; 58 taskqid_t tqent_id; 59 LIST_ENTRY(taskq_ent) tqent_hash; 60 uint_t tqent_type; 61 volatile uint_t tqent_rc; 62 } taskq_ent_t; 63 64 /* 65 * Public flags for taskq_create(): bit range 0-15 66 */ 67 #define TASKQ_PREPOPULATE 0x0001 /* Prepopulate with threads and data */ 68 #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ 69 #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ 70 #define TASKQ_THREADS_CPU_PCT 0x0008 /* number of threads as % of ncpu */ 71 #define TASKQ_DC_BATCH 0x0010 /* Taskq uses SDC in batch mode */ 72 73 /* 74 * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as 75 * KM_SLEEP/KM_NOSLEEP. 76 */ 77 #define TQ_SLEEP 0x00 /* Can block for memory */ 78 #define TQ_NOSLEEP 0x01 /* cannot block for memory; may fail */ 79 #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 80 #define TQ_NOALLOC 0x04 /* cannot allocate memory; may fail */ 81 #define TQ_FRONT 0x08 /* Put task at the front of the queue */ 82 83 #define TASKQID_INVALID ((taskqid_t)0) 84 85 extern taskq_t *system_taskq; 86 /* Global dynamic task queue for long delay */ 87 extern taskq_t *system_delay_taskq; 88 89 extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 90 extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, 91 uint_t, clock_t); 92 extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, 93 taskq_ent_t *); 94 extern int taskq_empty_ent(taskq_ent_t *); 95 extern void taskq_init_ent(taskq_ent_t *); 96 taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 97 taskq_t *taskq_create_synced(const char *, int, pri_t, int, int, uint_t, 98 kthread_t ***); 99 taskq_t *taskq_create_instance(const char *, int, int, pri_t, int, int, uint_t); 100 taskq_t *taskq_create_proc(const char *, int, pri_t, int, int, 101 struct proc *, uint_t); 102 taskq_t *taskq_create_sysdc(const char *, int, int, int, 103 struct proc *, uint_t, uint_t); 104 void nulltask(void *); 105 extern void taskq_destroy(taskq_t *); 106 extern void taskq_wait_id(taskq_t *, taskqid_t); 107 extern void taskq_wait_outstanding(taskq_t *, taskqid_t); 108 extern void taskq_wait(taskq_t *); 109 extern int taskq_cancel_id(taskq_t *, taskqid_t); 110 extern int taskq_member(taskq_t *, kthread_t *); 111 extern taskq_t *taskq_of_curthread(void); 112 void taskq_suspend(taskq_t *); 113 int taskq_suspended(taskq_t *); 114 void taskq_resume(taskq_t *); 115 116 #ifdef __cplusplus 117 } 118 #endif 119 120 #endif /* _KERNEL */ 121 122 #ifdef _STANDALONE 123 typedef void taskq_t; 124 typedef int taskq_ent_t; 125 #define taskq_init_ent(x) 126 #endif /* _STANDALONE */ 127 128 #endif /* _SYS_TASKQ_H */ 129