FreeBSD/Linux Kernel Cross Reference
sys/sys/savar.h
1 /* $NetBSD: savar.h,v 1.15.14.1 2005/10/21 17:39:40 riz Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Internal data usd by the scheduler activation implementation
41 */
42
43 #ifndef _SYS_SAVAR_H
44 #define _SYS_SAVAR_H
45
46 #include <sys/lock.h>
47 #include <sys/tree.h>
48 #include <sys/queue.h>
49
50 union sau_state {
51 struct {
52 ucontext_t ss_ctx;
53 struct sa_t ss_sa;
54 } ss_captured;
55 struct {
56 struct lwp *ss_lwp;
57 } ss_deferred;
58 };
59
60 struct sadata_upcall {
61 SIMPLEQ_ENTRY(sadata_upcall) sau_next;
62 int sau_flags;
63 int sau_type;
64 size_t sau_argsize;
65 void *sau_arg;
66 void (*sau_argfreefunc)(void *);
67 stack_t sau_stack;
68 union sau_state sau_event;
69 union sau_state sau_interrupted;
70 };
71
72 #define SAU_FLAG_DEFERRED_EVENT 0x1
73 #define SAU_FLAG_DEFERRED_INTERRUPTED 0x2
74
75 #define SA_UPCALL_TYPE_MASK 0x00FF
76
77 #define SA_UPCALL_DEFER_EVENT 0x1000
78 #define SA_UPCALL_DEFER_INTERRUPTED 0x2000
79 #define SA_UPCALL_DEFER (SA_UPCALL_DEFER_EVENT | \
80 SA_UPCALL_DEFER_INTERRUPTED)
81
82 struct sastack {
83 stack_t sast_stack;
84 SPLAY_ENTRY(sastack) sast_node;
85 unsigned int sast_gen;
86 };
87
88 struct sadata_vp {
89 int savp_id; /* "virtual processor" identifier */
90 SLIST_ENTRY(sadata_vp) savp_next; /* link to next sadata_vp */
91 struct simplelock savp_lock; /* lock on these fields */
92 struct lwp *savp_lwp; /* lwp on "virtual processor" */
93 struct lwp *savp_blocker; /* recently blocked lwp */
94 struct lwp *savp_wokenq_head; /* list of woken lwps */
95 struct lwp **savp_wokenq_tailp; /* list of woken lwps */
96 vaddr_t savp_faultaddr; /* page fault address */
97 vaddr_t savp_ofaultaddr; /* old page fault address */
98 LIST_HEAD(, lwp) savp_lwpcache; /* list of available lwps */
99 int savp_ncached; /* list length */
100 SIMPLEQ_HEAD(, sadata_upcall) savp_upcalls; /* pending upcalls */
101 };
102
103 struct sadata {
104 struct simplelock sa_lock; /* lock on these fields */
105 int sa_flag; /* SA_* flags */
106 sa_upcall_t sa_upcall; /* upcall entry point */
107 int sa_concurrency; /* current concurrency */
108 int sa_maxconcurrency; /* requested concurrency */
109 SPLAY_HEAD(sasttree, sastack) sa_stackstree; /* tree of upcall stacks */
110 struct sastack *sa_stacknext; /* next free stack */
111 ssize_t sa_stackinfo_offset; /* offset from ss_sp to stackinfo data */
112 int sa_nstacks; /* number of upcall stacks */
113 SLIST_HEAD(, sadata_vp) sa_vps; /* list of "virtual processors" */
114 };
115
116 #define SA_FLAG_ALL SA_FLAG_PREEMPT
117
118 extern struct pool sadata_pool; /* memory pool for sadata structures */
119 extern struct pool saupcall_pool; /* memory pool for pending upcalls */
120 extern struct pool sastack_pool; /* memory pool for sastack structs */
121 extern struct pool savp_pool; /* memory pool for sadata_vp structures */
122
123 #ifdef _KERNEL
124 #include <sys/mallocvar.h>
125
126 MALLOC_DECLARE(M_SA);
127 #endif
128
129 #define SA_MAXNUMSTACKS 16 /* Maximum number of upcall stacks per VP. */
130
131 struct sadata_upcall *sadata_upcall_alloc(int);
132 void sadata_upcall_free(struct sadata_upcall *);
133
134 void sa_release(struct proc *);
135 void sa_switch(struct lwp *, struct sadata_upcall *, int);
136 void sa_preempt(struct lwp *);
137 void sa_yield(struct lwp *);
138 int sa_upcall(struct lwp *, int, struct lwp *, struct lwp *, size_t, void *,
139 void (*)(void *));
140
141 void sa_putcachelwp(struct proc *, struct lwp *);
142 struct lwp *sa_getcachelwp(struct sadata_vp *);
143
144
145 void sa_unblock_userret(struct lwp *);
146 void sa_upcall_userret(struct lwp *);
147 void cpu_upcall(struct lwp *, int, int, int, void *, void *, void *, sa_upcall_t);
148
149 #endif /* !_SYS_SAVAR_H */
Cache object: 4287922401c824600e37c4ae23b97f9d
|