5 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
8 * Redistribution and use in source and binary forms, with or without
9 * 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 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
29 * $DragonFly: src/lib/libcaps/globaldata.h,v 1.4 2004/01/17 17:27:54 drhodus Exp $
32 #ifndef _LIBCAPS_GLOBALDATA_H_
33 #define _LIBCAPS_GLOBALDATA_H_
35 #ifndef _LIBCAPS_THREAD_H_
38 #ifndef _SYS_THREAD_H_
39 #include <sys/thread.h>
41 #ifndef _SYS_UPCALL_H_
42 #include <sys/upcall.h>
44 #ifndef _LIBCAPS_SLABALLOC_H_
45 #include "slaballoc.h"
51 #include <sys/queue.h>
53 #ifndef _MACHINE_LOCK_H_
54 #include <machine/lock.h>
58 typedef struct globaldata *globaldata_t;
60 #include "md_globaldata.h"
62 extern int smp_active;
65 extern u_int32_t stopped_cpus;
66 extern char *panicstr;
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 */
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? */
79 int gd_intr_nesting_level;
80 struct thread gd_idlethread;
81 SLGlobalData gd_slab; /* slab allocator */
82 int gd_num_threads; /* Number of threads */
83 int gd_sys_threads; /* Number of threads */
84 struct lwkt_ipiq *gd_ipiq;
87 #define gd_reqflags gd_upcall.upc_pending
88 #define gd_curthread gd_upcall.upc_uthread
92 #define RQB_AST_OWEUPC 2
93 #define RQB_AST_SIGNAL 3
94 #define RQB_AST_RESCHED 4
95 #define RQB_AST_UPCALL 5
98 #define RQF_IPIQ (1 << RQB_IPIQ)
99 #define RQF_INTPEND (1 << RQB_INTPEND)
100 #define RQF_AST_OWEUPC (1 << RQB_AST_OWEUPC)
101 #define RQF_AST_SIGNAL (1 << RQB_AST_SIGNAL)
102 #define RQF_AST_RESCHED (1 << RQB_AST_RESCHED)
103 #define RQF_AST_UPCALL (1 << RQB_AST_UPCALL)
104 #define RQF_AST_MASK (RQF_AST_OWEUPC|RQF_AST_SIGNAL|RQF_AST_RESCHED|\
107 #define RQF_IDLECHECK_MASK (RQF_IPIQ|RQF_INTPEND)
109 #define KASSERT(exp, printargs) \
110 do { if (!(exp)) { panic printargs; } } while(0)
111 #define KKASSERT(exp) assert(exp)
115 #define curthread (mycpu->gd_curthread)
117 extern struct globaldata *globaldata_find(int cpu);
119 void globaldata_init(struct thread *td);
121 int need_resched(void);
123 void cpu_send_ipiq(int dcpu);
124 void mi_gdinit1(globaldata_t gd, int cpuid);
125 void mi_gdinit2(globaldata_t gd);
126 __dead2 void panic(const char *, ...);