]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/cddl/compat/opensolaris/sys/taskq_impl.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / cddl / compat / opensolaris / sys / taskq_impl.h
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  *
22  * $FreeBSD$
23  */
24 /*
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28
29 #ifndef _SYS_TASKQ_IMPL_H
30 #define _SYS_TASKQ_IMPL_H
31
32 #pragma ident   "@(#)taskq_impl.h       1.6     05/06/08 SMI"
33
34 #include <sys/mutex.h>
35 #include <sys/rwlock.h>
36 #include <sys/condvar.h>
37 #include <sys/taskq.h>
38
39 #ifdef  __cplusplus
40 extern "C" {
41 #endif
42
43 typedef struct taskq_bucket taskq_bucket_t;
44
45 typedef struct taskq_ent {
46         struct taskq_ent        *tqent_next;
47         struct taskq_ent        *tqent_prev;
48         task_func_t             *tqent_func;
49         void                    *tqent_arg;
50         taskq_bucket_t          *tqent_bucket;
51         kthread_t               *tqent_thread;
52         kcondvar_t              tqent_cv;
53 } taskq_ent_t;
54
55 /*
56  * Taskq Statistics fields are not protected by any locks.
57  */
58 typedef struct tqstat {
59         uint_t          tqs_hits;
60         uint_t          tqs_misses;
61         uint_t          tqs_overflow;   /* no threads to allocate   */
62         uint_t          tqs_tcreates;   /* threads created      */
63         uint_t          tqs_tdeaths;    /* threads died         */
64         uint_t          tqs_maxthreads; /* max # of alive threads */
65         uint_t          tqs_nomem;      /* # of times there were no memory */
66         uint_t          tqs_disptcreates;
67 } tqstat_t;
68
69 /*
70  * Per-CPU hash bucket manages taskq_bent_t structures using freelist.
71  */
72 struct taskq_bucket {
73         kmutex_t        tqbucket_lock;
74         taskq_t         *tqbucket_taskq;        /* Enclosing taskq */
75         taskq_ent_t     tqbucket_freelist;
76         uint_t          tqbucket_nalloc;        /* # of allocated entries */
77         uint_t          tqbucket_nfree;         /* # of free entries */
78         kcondvar_t      tqbucket_cv;
79         ushort_t        tqbucket_flags;
80         hrtime_t        tqbucket_totaltime;
81         tqstat_t        tqbucket_stat;
82 };
83
84 /*
85  * Bucket flags.
86  */
87 #define TQBUCKET_CLOSE          0x01
88 #define TQBUCKET_SUSPEND        0x02
89
90 /*
91  * taskq implementation flags: bit range 16-31
92  */
93 #define TASKQ_ACTIVE            0x00010000
94 #define TASKQ_SUSPENDED         0x00020000
95 #define TASKQ_NOINSTANCE        0x00040000
96
97 struct taskq {
98         char            tq_name[TASKQ_NAMELEN + 1];
99         kmutex_t        tq_lock;
100         krwlock_t       tq_threadlock;
101         kcondvar_t      tq_dispatch_cv;
102         kcondvar_t      tq_wait_cv;
103         uint_t          tq_flags;
104         int             tq_active;
105         int             tq_nthreads;
106         int             tq_nalloc;
107         int             tq_minalloc;
108         int             tq_maxalloc;
109         taskq_ent_t     *tq_freelist;
110         taskq_ent_t     tq_task;
111         int             tq_maxsize;
112         pri_t           tq_pri;         /* Scheduling priority      */
113         taskq_bucket_t  *tq_buckets;    /* Per-cpu array of buckets */
114         uint_t          tq_nbuckets;    /* # of buckets (2^n)       */
115         union {
116                 kthread_t *_tq_thread;
117                 kthread_t **_tq_threadlist;
118         }               tq_thr;
119         /*
120          * Statistics.
121          */
122         hrtime_t        tq_totaltime;   /* Time spent processing tasks */
123         int             tq_tasks;       /* Total # of tasks posted */
124         int             tq_executed;    /* Total # of tasks executed */
125         int             tq_maxtasks;    /* Max number of tasks in the queue */
126         int             tq_tcreates;
127         int             tq_tdeaths;
128 };
129
130 #define tq_thread tq_thr._tq_thread
131 #define tq_threadlist tq_thr._tq_threadlist
132
133 #ifdef  __cplusplus
134 }
135 #endif
136
137 #endif  /* _SYS_TASKQ_IMPL_H */