More minor IPI work.
[dragonfly/vkernel-mp.git] / lib / libcaps / globaldata.h
blob7232f318afb8a5b23be78cc0bb2256cca04700d1
1 /*
2 * GLOBALDATA.H
3 */
4 /*
5 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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 the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * $DragonFly: src/lib/libcaps/globaldata.h,v 1.9 2004/09/21 20:40:30 joerg Exp $
32 #ifndef _LIBCAPS_GLOBALDATA_H_
33 #define _LIBCAPS_GLOBALDATA_H_
35 #ifndef _LIBCAPS_THREAD_H_
36 #include "thread.h"
37 #endif
38 #ifndef _SYS_THREAD_H_
39 #include <sys/thread.h>
40 #endif
41 #ifndef _SYS_UPCALL_H_
42 #include <sys/upcall.h>
43 #endif
44 #ifndef _LIBCAPS_SLABALLOC_H_
45 #include "slaballoc.h"
46 #endif
47 #ifndef _ASSERT_H_
48 #include <assert.h>
49 #endif
50 #ifndef _SYS_QUEUE_H_
51 #include <sys/queue.h>
52 #endif
53 #ifndef _MACHINE_LOCK_H_
54 #include <machine/lock.h>
55 #endif
57 struct globaldata;
58 typedef struct globaldata *globaldata_t;
60 #include "md_globaldata.h"
62 extern int smp_active;
63 extern int ncpus;
64 extern int hz;
65 extern u_int32_t stopped_cpus;
66 extern char *panicstr;
68 struct globaldata {
69 struct globaldata *gd_self; /* self pointer */
70 struct upcall gd_upcall; /* upcall for this cpu */
71 int gd_upcid; /* upcall id */
72 int gd_pid; /* user pid for rfork'd cpu */
73 int gd_tdfreecount;
74 TAILQ_HEAD(,thread) gd_tdallq; /* all threads */
75 TAILQ_HEAD(,thread) gd_tdfreeq; /* new thread cache */
76 TAILQ_HEAD(,thread) gd_tdrunq[32]; /* runnable threads */
77 __uint32_t gd_runqmask; /* which queues? */
78 __uint32_t gd_cpuid;
79 cpumask_t gd_cpumask; /* mask = 1<<cpuid */
80 cpumask_t gd_other_cpus;
81 int gd_intr_nesting_level;
82 struct thread gd_idlethread;
83 SLGlobalData gd_slab; /* slab allocator */
84 int gd_num_threads; /* Number of threads */
85 int gd_sys_threads; /* Number of threads */
86 struct lwkt_ipiq *gd_ipiq;
87 lwkt_tokref_t gd_tokreqbase; /* requests from other cpus */
88 struct lwkt_ipiq gd_cpusyncq; /* ipiq for cpu synchro */
91 #define gd_reqflags gd_upcall.upc_pending
92 #define gd_curthread gd_upcall.upc_uthread
94 #define RQB_IPIQ 0
95 #define RQB_INTPEND 1
96 #define RQB_AST_OWEUPC 2
97 #define RQB_AST_SIGNAL 3
98 #define RQB_AST_USER_RESCHED 4
99 #define RQB_AST_LWKT_RESCHED 5
100 #define RQB_AST_UPCALL 6
102 #define RQF_IPIQ (1 << RQB_IPIQ)
103 #define RQF_INTPEND (1 << RQB_INTPEND)
104 #define RQF_AST_OWEUPC (1 << RQB_AST_OWEUPC)
105 #define RQF_AST_SIGNAL (1 << RQB_AST_SIGNAL)
106 #define RQF_AST_USER_RESCHED (1 << RQB_AST_USER_RESCHED)
107 #define RQF_AST_LWKT_RESCHED (1 << RQB_AST_LWKT_RESCHED)
108 #define RQF_AST_UPCALL (1 << RQB_AST_UPCALL)
109 #define RQF_AST_MASK (RQF_AST_OWEUPC|RQF_AST_SIGNAL|\
110 RQF_AST_USER_RESCHED|RQF_AST_LWKT_RESCHED|\
111 RQF_AST_UPCALL)
112 #define RQF_IDLECHECK_MASK (RQF_IPIQ|RQF_INTPEND)
114 #define KASSERT(exp, printargs) \
115 do { if (!(exp)) { panic printargs; } } while(0)
116 #define KKASSERT(exp) assert(exp)
118 #define MAXVCPU 32
120 #define curthread (mycpu->gd_curthread)
122 extern cpumask_t smp_active_mask;
124 extern struct globaldata *globaldata_find(int cpu);
126 void globaldata_init(struct thread *td);
127 void splz(void);
128 int need_lwkt_resched(void);
129 void cpu_halt(void);
130 void cpu_send_ipiq(int dcpu);
131 void mi_gdinit1(globaldata_t gd, int cpuid);
132 void mi_gdinit2(globaldata_t gd);
133 __dead2 void panic(const char *, ...);
135 #endif