Merge from vendor branch AWK:
[dragonfly.git] / sys / sys / globaldata.h
1 /*-
2  * Copyright (c) Peter Wemm <peter@netplex.com.au> All rights reserved.
3  * Copyright (c) 2003 Matthew Dillon <dillon@backplane.net> All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $
27  * $DragonFly: src/sys/sys/globaldata.h,v 1.31 2004/04/02 05:46:02 hmp Exp $
28  */
29
30 #ifndef _SYS_GLOBALDATA_H_
31 #define _SYS_GLOBALDATA_H_
32
33 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
34
35 #ifndef _SYS_STDINT_H_
36 #include <sys/stdint.h> /* __int types */
37 #endif
38 #ifndef _SYS_TIME_H_
39 #include <sys/time.h>   /* struct timeval */
40 #endif
41 #ifndef _SYS_VMMETER_H_
42 #include <sys/vmmeter.h> /* struct vmmeter */
43 #endif
44 #ifndef _SYS_THREAD_H_
45 #include <sys/thread.h> /* struct thread */
46 #endif
47 #ifndef _SYS_SLABALLOC_H_
48 #include <sys/slaballoc.h> /* SLGlobalData */
49 #endif
50 #ifndef _SYS_SYSTIMER_H_
51 #include <sys/systimer.h> /* fine-grained system timers */
52 #endif
53 #ifndef _SYS_NCHSTATS_H_
54 #include <sys/nchstats.h>
55 #endif
56
57 /*
58  * This structure maps out the global data that needs to be kept on a
59  * per-cpu basis.  genassym uses this to generate offsets for the assembler
60  * code.  The machine-dependant portions of this file can be found in
61  * <machine/globaldata.h>, but only MD code should retrieve it.
62  *
63  * The SMP parts are setup in pmap.c and locore.s for the BSP, and
64  * mp_machdep.c sets up the data for the AP's to "see" when they awake.
65  * The reason for doing it via a struct is so that an array of pointers
66  * to each CPU's data can be set up for things like "check curproc on all
67  * other processors"
68  *
69  * NOTE! this structure needs to remain compatible between module accessors
70  * and the kernel, so we can't throw in lots of #ifdef's.
71  *
72  * gd_reqflags serves serveral purposes, but it is primarily an interrupt
73  * rollup flag used by the task switcher and spl mechanisms to decide that
74  * further checks are necessary.  Interrupts are typically managed on a
75  * per-processor basis at least until you leave a critical section, but
76  * may then be scheduled to other cpus.
77  *
78  * gd_vme_avail and gd_vme_base cache free vm_map_entry structures for use
79  * in various vm_map related operations.  gd_vme_avail is *NOT* a count of
80  * the number of structures in the cache but is instead a count of the number
81  * of unreserved structures in the cache.  See vm_map_entry_reserve().
82  *
83  * gd_uschedcp is internal to the userland scheduler.  It does not represent
84  * the currently running process.
85  */
86
87 struct sysmsg;
88 struct privatespace;
89 struct vm_map_entry;
90 struct pipe;
91
92 struct globaldata {
93         struct privatespace *gd_prvspace;       /* self-reference */
94         struct thread   *gd_curthread;
95         int             gd_tdfreecount;         /* new thread cache */
96         __uint32_t      gd_reqflags;            /* (see note above) */
97         union sysunion  *gd_freesysun;          /* free syscall messages */
98         TAILQ_HEAD(,thread) gd_tdallq;          /* all threads */
99         TAILQ_HEAD(,thread) gd_tdfreeq;         /* new thread cache */
100         TAILQ_HEAD(,thread) gd_tdrunq[32];      /* runnable threads */
101         __uint32_t      gd_runqmask;            /* which queues? */
102         __uint32_t      gd_cpuid;
103         cpumask_t       gd_cpumask;             /* mask = 1<<cpuid */
104         cpumask_t       gd_other_cpus;          /* mask of 'other' cpus */
105         struct timeval  gd_stattv;
106         int             gd_intr_nesting_level;  /* (for interrupts) */
107         struct vmmeter  gd_cnt;
108         struct lwkt_ipiq *gd_ipiq;              /* array[ncpu] of ipiq's */
109         struct lwkt_ipiq gd_cpusyncq;           /* ipiq for cpu synchro */
110         short           gd_upri;                /* userland scheduler helper */
111         short           gd_unused01;
112         struct thread   gd_schedthread;         /* userland scheduler helper */
113         struct thread   gd_idlethread;
114         SLGlobalData    gd_slab;                /* slab allocator */
115         int             gd_vme_kdeficit;        /* vm_map_entry reservation */
116         int             gd_vme_avail;           /* vm_map_entry reservation */
117         struct vm_map_entry *gd_vme_base;       /* vm_map_entry reservation */
118         struct systimerq gd_systimerq;          /* per-cpu system timers */
119         int             gd_syst_nest;
120         sysclock_t      gd_nextclock;           /* next best-case clock req */
121         struct systimer gd_hardclock;           /* scheduler periodic */
122         struct systimer gd_statclock;           /* statistics periodic */
123         struct systimer gd_schedclock;          /* scheduler periodic */
124         volatile __uint32_t gd_time_seconds;    /* uptime in seconds */
125         volatile sysclock_t gd_cpuclock_base;   /* cpuclock relative base */
126
127         struct pipe     *gd_pipeq;              /* cache pipe structures */
128         struct nchstats *gd_nchstats;           /* namecache effectiveness */
129         int             gd_pipeqcount;          /* number of structures */
130         lwkt_tokref_t   gd_tokreqbase;          /* requests from other cpus */
131         struct proc     *gd_uschedcp;           /* userland scheduler */
132         /* extended by <machine/globaldata.h> */
133 };
134
135 typedef struct globaldata *globaldata_t;
136
137 #define RQB_IPIQ                0
138 #define RQB_INTPEND             1
139 #define RQB_AST_OWEUPC          2
140 #define RQB_AST_SIGNAL          3
141 #define RQB_AST_USER_RESCHED    4
142 #define RQB_AST_LWKT_RESCHED    5
143 #define RQB_AST_UPCALL          6
144
145 #define RQF_IPIQ                (1 << RQB_IPIQ)
146 #define RQF_INTPEND             (1 << RQB_INTPEND)
147 #define RQF_AST_OWEUPC          (1 << RQB_AST_OWEUPC)
148 #define RQF_AST_SIGNAL          (1 << RQB_AST_SIGNAL)
149 #define RQF_AST_USER_RESCHED    (1 << RQB_AST_USER_RESCHED)
150 #define RQF_AST_LWKT_RESCHED    (1 << RQB_AST_LWKT_RESCHED)
151 #define RQF_AST_UPCALL          (1 << RQB_AST_UPCALL)
152 #define RQF_AST_MASK            (RQF_AST_OWEUPC|RQF_AST_SIGNAL|\
153                                 RQF_AST_USER_RESCHED|RQF_AST_LWKT_RESCHED|\
154                                 RQF_AST_UPCALL)
155 #define RQF_IDLECHECK_MASK      (RQF_IPIQ|RQF_INTPEND)
156
157 #endif
158
159 #ifdef _KERNEL
160 struct globaldata *globaldata_find(int cpu);
161 #endif
162
163 #endif