1c1cb2cd8Shaad /* 2c1cb2cd8Shaad * CDDL HEADER START 3c1cb2cd8Shaad * 4c1cb2cd8Shaad * The contents of this file are subject to the terms of the 5f59c7639Shaad * Common Development and Distribution License (the "License"). 6f59c7639Shaad * You may not use this file except in compliance with the License. 7c1cb2cd8Shaad * 8c1cb2cd8Shaad * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9c1cb2cd8Shaad * or http://www.opensolaris.org/os/licensing. 10c1cb2cd8Shaad * See the License for the specific language governing permissions 11c1cb2cd8Shaad * and limitations under the License. 12c1cb2cd8Shaad * 13c1cb2cd8Shaad * When distributing Covered Code, include this CDDL HEADER in each 14c1cb2cd8Shaad * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15c1cb2cd8Shaad * If applicable, add the following below this CDDL HEADER, with the 16c1cb2cd8Shaad * fields enclosed by brackets "[]" replaced with your own identifying 17c1cb2cd8Shaad * information: Portions Copyright [yyyy] [name of copyright owner] 18c1cb2cd8Shaad * 19c1cb2cd8Shaad * CDDL HEADER END 20c1cb2cd8Shaad */ 21c1cb2cd8Shaad /* 22f59c7639Shaad * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23c1cb2cd8Shaad * Use is subject to license terms. 24c1cb2cd8Shaad */ 25c1cb2cd8Shaad 26c1cb2cd8Shaad #ifndef _SYS_TASKQ_H 27c1cb2cd8Shaad #define _SYS_TASKQ_H 28c1cb2cd8Shaad 29c1cb2cd8Shaad #include <sys/types.h> 303227e6cfSchs #include <sys/proc.h> 31ba2539a9Schs #ifdef __FreeBSD__ 323227e6cfSchs #include <sys/taskqueue.h> 33ba2539a9Schs #endif 34c1cb2cd8Shaad 35c1cb2cd8Shaad #ifdef __cplusplus 36c1cb2cd8Shaad extern "C" { 37c1cb2cd8Shaad #endif 38c1cb2cd8Shaad 39c1cb2cd8Shaad #define TASKQ_NAMELEN 31 40c1cb2cd8Shaad 41ba2539a9Schs #ifdef __FreeBSD__ 423227e6cfSchs struct taskqueue; 433227e6cfSchs struct taskq { 443227e6cfSchs struct taskqueue *tq_queue; 453227e6cfSchs }; 463227e6cfSchs typedef struct taskq_ent { 473227e6cfSchs struct task tqent_task; 483227e6cfSchs task_func_t *tqent_func; 493227e6cfSchs void *tqent_arg; 503227e6cfSchs } taskq_ent_t; 51ba2539a9Schs #endif 52ba2539a9Schs 53ba2539a9Schs typedef struct taskq taskq_t; 54ba2539a9Schs typedef uintptr_t taskqid_t; 55ba2539a9Schs typedef void (task_func_t)(void *); 563227e6cfSchs 57*db54d209Shannken #ifdef __NetBSD__ 58*db54d209Shannken typedef struct taskq_ent { 59*db54d209Shannken SIMPLEQ_ENTRY(taskq_ent) tqent_list; /* Task queue. */ 60*db54d209Shannken task_func_t *tqent_func; /* Function to run. */ 61*db54d209Shannken void *tqent_arg; /* Argument to function above. */ 62*db54d209Shannken unsigned tqent_dynamic:1; /* Must kmem_free() if true. */ 63*db54d209Shannken unsigned tqent_queued:1; /* Queued and waiting to run if true. */ 64*db54d209Shannken } taskq_ent_t; 65*db54d209Shannken #endif 66*db54d209Shannken 67f59c7639Shaad struct proc; 68f59c7639Shaad 69c1cb2cd8Shaad /* 70c1cb2cd8Shaad * Public flags for taskq_create(): bit range 0-15 71c1cb2cd8Shaad */ 72c1cb2cd8Shaad #define TASKQ_PREPOPULATE 0x0001 /* Prepopulate with threads and data */ 73c1cb2cd8Shaad #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ 74c1cb2cd8Shaad #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ 75f59c7639Shaad #define TASKQ_THREADS_CPU_PCT 0x0008 /* number of threads as % of ncpu */ 76f59c7639Shaad #define TASKQ_DC_BATCH 0x0010 /* Taskq uses SDC in batch mode */ 77c1cb2cd8Shaad 78c1cb2cd8Shaad /* 79c1cb2cd8Shaad * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as 80c1cb2cd8Shaad * KM_SLEEP/KM_NOSLEEP. 81c1cb2cd8Shaad */ 82c1cb2cd8Shaad #define TQ_SLEEP 0x00 /* Can block for memory */ 83c1cb2cd8Shaad #define TQ_NOSLEEP 0x01 /* cannot block for memory; may fail */ 84c1cb2cd8Shaad #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 85c1cb2cd8Shaad #define TQ_NOALLOC 0x04 /* cannot allocate memory; may fail */ 86f59c7639Shaad #define TQ_FRONT 0x08 /* Put task at the front of the queue */ 87c1cb2cd8Shaad 88c1cb2cd8Shaad #ifdef _KERNEL 89c1cb2cd8Shaad 90c1cb2cd8Shaad extern taskq_t *system_taskq; 91c1cb2cd8Shaad 923227e6cfSchs void taskq_init(void); 933227e6cfSchs void taskq_mp_init(void); 94c1cb2cd8Shaad 953227e6cfSchs taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 963227e6cfSchs taskq_t *taskq_create_instance(const char *, int, int, pri_t, int, int, uint_t); 973227e6cfSchs taskq_t *taskq_create_proc(const char *, int, pri_t, int, int, 98f59c7639Shaad struct proc *, uint_t); 993227e6cfSchs taskq_t *taskq_create_sysdc(const char *, int, int, int, 100f59c7639Shaad struct proc *, uint_t, uint_t); 1013227e6cfSchs taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 102*db54d209Shannken #if defined(__FreeBSD__) || defined(__NetBSD__) 1033227e6cfSchs void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, 1043227e6cfSchs taskq_ent_t *); 105ba2539a9Schs #endif 1063227e6cfSchs void nulltask(void *); 1073227e6cfSchs void taskq_destroy(taskq_t *); 1083227e6cfSchs void taskq_wait(taskq_t *); 1093227e6cfSchs void taskq_suspend(taskq_t *); 1103227e6cfSchs int taskq_suspended(taskq_t *); 1113227e6cfSchs void taskq_resume(taskq_t *); 1123227e6cfSchs int taskq_member(taskq_t *, kthread_t *); 113c1cb2cd8Shaad 114c1cb2cd8Shaad #endif /* _KERNEL */ 115c1cb2cd8Shaad 116c1cb2cd8Shaad #ifdef __cplusplus 117c1cb2cd8Shaad } 118c1cb2cd8Shaad #endif 119c1cb2cd8Shaad 120c1cb2cd8Shaad #endif /* _SYS_TASKQ_H */ 121