2 * Copyright (c) 2001 Wind River Systems, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/queue.h>
38 #include <sys/vmmeter.h>
39 #include <machine/pcpu.h>
47 * This structure maps out the global data that needs to be kept on a
48 * per-cpu basis. The members are accessed via the PCPU_GET/SET/PTR
49 * macros defined in <machine/pcpu.h>. Machine dependent fields are
50 * defined in the PCPU_MD_FIELDS macro defined in <machine/pcpu.h>.
53 struct thread *pc_curthread; /* Current thread */
54 struct thread *pc_idlethread; /* Idle thread */
55 struct thread *pc_fpcurthread; /* Fp state owner */
56 struct pcb *pc_curpcb; /* Current pcb */
57 struct bintime pc_switchtime;
59 u_int pc_cpuid; /* This cpu number */
60 u_int pc_cpumask; /* This cpu mask */
61 u_int pc_other_cpus; /* Mask of all other cpus */
62 SLIST_ENTRY(pcpu) pc_allcpu;
63 struct lock_list_entry *pc_spinlocks;
65 int pc_ktr_idx; /* Index into trace table */
69 struct vmmeter pc_cnt; /* VM stats counters */
72 SLIST_HEAD(cpuhead, pcpu);
74 extern struct cpuhead cpuhead;
76 #define curthread PCPU_GET(curthread)
77 #define CURPROC (curthread->td_proc)
78 #define curproc (curthread->td_proc)
79 #define curksegrp (curthread->td_ksegrp)
80 #define curkse (curthread->td_kse)
83 * MI PCPU support functions
85 * PCPU_LAZY_INC() - Lazily increment a per-cpu stats counter, without
86 * guarenteeing atomicy or even necessarily consistency.
88 * XXX we need to create MD primitives to support
89 * this to guarentee at least some level of consistency,
90 * i.e. to prevent us from totally corrupting the
91 * counters due to preemption in a multi-instruction
92 * increment sequence for architectures that do not
93 * support single-instruction memory increments.
95 #define PCPU_LAZY_INC(var) (++*PCPU_PTR(var))
98 * Machine dependent callouts. cpu_pcpu_init() is responsible for
99 * initializing machine dependent fields of struct pcpu, and
100 * db_show_mdpcpu() is responsible for handling machine dependent
101 * fields for the DDB 'show pcpu' command.
103 void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size);
104 void db_show_mdpcpu(struct pcpu *pcpu);
106 void pcpu_destroy(struct pcpu *pcpu);
107 struct pcpu *pcpu_find(u_int cpuid);
108 void pcpu_init(struct pcpu *pcpu, int cpuid, size_t size);
112 #endif /* _SYS_PCPU_H_ */