proc->thread stage3: make time accounting threads based and rework it for
[dragonfly.git] / sys / i386 / include / globaldata.h
1 /*-
2  * Copyright (c) Peter Wemm <peter@netplex.com.au>
3  * 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/i386/include/Attic/globaldata.h,v 1.10 2003/06/23 23:36:08 dillon Exp $
28  */
29
30 /*
31  * This structure maps out the global data that needs to be kept on a
32  * per-cpu basis.  genassym uses this to generate offsets for the assembler
33  * code, which also provides external symbols so that C can get at them as
34  * though they were really globals.
35  *
36  * The SMP parts are setup in pmap.c and locore.s for the BSP, and
37  * mp_machdep.c sets up the data for the AP's to "see" when they awake.
38  * The reason for doing it via a struct is so that an array of pointers
39  * to each CPU's data can be set up for things like "check curproc on all
40  * other processors"
41  *
42  * NOTE! this structure needs to remain compatible between module accessors
43  * and the kernel, so we can't throw in lots of #ifdef's.
44  */
45 struct globaldata {
46         struct privatespace *gd_prvspace;       /* self-reference */
47         struct thread   *gd_curthread;
48         struct thread   *gd_npxthread;
49         struct i386tss  gd_common_tss;
50         int             gd_tdfreecount;         /* new thread cache */
51         int             gd_reqpri;              /* highest pri blocked thread */
52         TAILQ_HEAD(,thread) gd_tdfreeq;         /* new thread cache */
53         TAILQ_HEAD(,thread) gd_tdrunq;          /* runnable threads */
54         struct segment_descriptor gd_common_tssd;
55         struct segment_descriptor *gd_tss_gdt;
56         int             gd_currentldt;          /* USER_LDT */
57         u_int           gd_cpu;
58         struct timeval  gd_stattv;
59 #ifdef SMP
60         u_int           gd_cpu_lockid;
61         u_int           gd_other_cpus;
62         int             gd_inside_intr;
63         u_int           gd_ss_eflags;
64         pt_entry_t      *gd_prv_CMAP1;
65         pt_entry_t      *gd_prv_CMAP2;
66         pt_entry_t      *gd_prv_CMAP3;
67         pt_entry_t      *gd_prv_PMAP1;
68         caddr_t         gd_prv_CADDR1;
69         caddr_t         gd_prv_CADDR2;
70         caddr_t         gd_prv_CADDR3;
71         unsigned        *gd_prv_PADDR1;
72 #endif
73         u_int           gd_astpending;
74         struct thread   gd_idlethread;
75 };
76
77 /*
78  * This is the upper (0xff800000) address space layout that is per-cpu.
79  * It is setup in locore.s and pmap.c for the BSP and in mp_machdep.c for
80  * each AP.  genassym helps export this to the assembler code.
81  */
82 struct privatespace {
83         /* page 0 - data page */
84         struct globaldata globaldata;
85         char            __filler0[PAGE_SIZE - sizeof(struct globaldata)];
86
87 #ifdef SMP
88         /* page 1..4 - CPAGE1,CPAGE2,CPAGE3,PPAGE1 */
89         char            CPAGE1[PAGE_SIZE];
90         char            CPAGE2[PAGE_SIZE];
91         char            CPAGE3[PAGE_SIZE];
92         char            PPAGE1[PAGE_SIZE];
93 #endif
94
95         /* page 5..4+UPAGES - idle stack (UPAGES pages) */
96         char            idlestack[UPAGES * PAGE_SIZE];
97 };
98
99 extern struct privatespace CPU_prvspace[];
100