2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Copyright (c) Peter Wemm <peter@netplex.com.au> All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $
58 * $DragonFly: src/sys/sys/globaldata.h,v 1.45 2006/06/07 03:02:11 dillon Exp $
61 #ifndef _SYS_GLOBALDATA_H_
62 #define _SYS_GLOBALDATA_H_
64 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
66 #ifndef _SYS_STDINT_H_
67 #include <sys/stdint.h> /* __int types */
70 #include <sys/time.h> /* struct timeval */
72 #ifndef _SYS_VMMETER_H_
73 #include <sys/vmmeter.h> /* struct vmmeter */
75 #ifndef _SYS_THREAD_H_
76 #include <sys/thread.h> /* struct thread */
78 #ifndef _SYS_SLABALLOC_H_
79 #include <sys/slaballoc.h> /* SLGlobalData */
81 #ifndef _SYS_SYSTIMER_H_
82 #include <sys/systimer.h> /* fine-grained system timers */
84 #ifndef _SYS_NCHSTATS_H_
85 #include <sys/nchstats.h>
89 * This structure maps out the global data that needs to be kept on a
90 * per-cpu basis. genassym uses this to generate offsets for the assembler
91 * code. The machine-dependant portions of this file can be found in
92 * <machine/globaldata.h>, but only MD code should retrieve it.
94 * The SMP parts are setup in pmap.c and locore.s for the BSP, and
95 * mp_machdep.c sets up the data for the AP's to "see" when they awake.
96 * The reason for doing it via a struct is so that an array of pointers
97 * to each CPU's data can be set up for things like "check curproc on all
100 * NOTE! this structure needs to remain compatible between module accessors
101 * and the kernel, so we can't throw in lots of #ifdef's.
103 * gd_reqflags serves serveral purposes, but it is primarily an interrupt
104 * rollup flag used by the task switcher and spl mechanisms to decide that
105 * further checks are necessary. Interrupts are typically managed on a
106 * per-processor basis at least until you leave a critical section, but
107 * may then be scheduled to other cpus.
109 * gd_vme_avail and gd_vme_base cache free vm_map_entry structures for use
110 * in various vm_map related operations. gd_vme_avail is *NOT* a count of
111 * the number of structures in the cache but is instead a count of the number
112 * of unreserved structures in the cache. See vm_map_entry_reserve().
123 struct privatespace *gd_prvspace; /* self-reference */
124 struct thread *gd_curthread;
125 int gd_tdfreecount; /* new thread cache */
126 __uint32_t gd_reqflags; /* (see note above) */
128 lwkt_queue gd_tdallq; /* all threads */
129 lwkt_queue gd_tdfreeq; /* new thread cache */
130 lwkt_queue gd_tdrunq[32]; /* runnable threads */
131 __uint32_t gd_runqmask; /* which queues? */
133 cpumask_t gd_cpumask; /* mask = 1<<cpuid */
134 cpumask_t gd_other_cpus; /* mask of 'other' cpus */
135 struct timeval gd_stattv;
136 int gd_intr_nesting_level; /* (for interrupts) */
137 struct vmmeter gd_cnt;
138 struct lwkt_ipiq *gd_ipiq; /* array[ncpu] of ipiq's */
139 struct lwkt_ipiq gd_cpusyncq; /* ipiq for cpu synchro */
142 struct thread gd_unused02B;
143 struct thread gd_idlethread;
144 SLGlobalData gd_slab; /* slab allocator */
145 int gd_trap_nesting_level; /* track traps */
146 int gd_vme_avail; /* vm_map_entry reservation */
147 struct vm_map_entry *gd_vme_base; /* vm_map_entry reservation */
148 struct systimerq gd_systimerq; /* per-cpu system timers */
150 sysclock_t gd_unused03;
151 struct systimer gd_hardclock; /* scheduler periodic */
152 struct systimer gd_statclock; /* statistics periodic */
153 struct systimer gd_schedclock; /* scheduler periodic */
154 volatile __uint32_t gd_time_seconds; /* uptime in seconds */
155 volatile sysclock_t gd_cpuclock_base; /* cpuclock relative base */
157 struct pipe *gd_pipeq; /* cache pipe structures */
158 struct nchstats *gd_nchstats; /* namecache effectiveness */
159 int gd_pipeqcount; /* number of structures */
163 struct tslpque *gd_tsleep_hash; /* tsleep/wakeup support */
164 struct spinlock *gd_spinlock_rd; /* Shared spinlock held */
165 int gd_spinlocks_wr; /* Exclusive spinlocks held */
166 void *gd_reserved[13]; /* future fields */
167 /* extended by <machine/globaldata.h> */
170 typedef struct globaldata *globaldata_t;
173 #define RQB_INTPEND 1
174 #define RQB_AST_OWEUPC 2
175 #define RQB_AST_SIGNAL 3
176 #define RQB_AST_USER_RESCHED 4
177 #define RQB_AST_LWKT_RESCHED 5
178 #define RQB_AST_UPCALL 6
180 #define RQF_IPIQ (1 << RQB_IPIQ)
181 #define RQF_INTPEND (1 << RQB_INTPEND)
182 #define RQF_AST_OWEUPC (1 << RQB_AST_OWEUPC)
183 #define RQF_AST_SIGNAL (1 << RQB_AST_SIGNAL)
184 #define RQF_AST_USER_RESCHED (1 << RQB_AST_USER_RESCHED)
185 #define RQF_AST_LWKT_RESCHED (1 << RQB_AST_LWKT_RESCHED)
186 #define RQF_AST_UPCALL (1 << RQB_AST_UPCALL)
187 #define RQF_AST_MASK (RQF_AST_OWEUPC|RQF_AST_SIGNAL|\
188 RQF_AST_USER_RESCHED|RQF_AST_LWKT_RESCHED|\
190 #define RQF_IDLECHECK_MASK (RQF_IPIQ|RQF_INTPEND)
195 struct globaldata *globaldata_find(int cpu);
196 int is_globaldata_space(vm_offset_t saddr, vm_offset_t eaddr);