2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
19 #include <sys/cpuset.h>
22 * Topology of a NUMA or HTT system.
24 * The top level topology is an array of pointers to groups. Each group
25 * contains a bitmask of cpus in its group or subgroups. It may also
26 * contain a pointer to an array of child groups.
28 * The bitmasks at non leaf groups may be used by consumers who support
29 * a smaller depth than the hardware provides.
31 * The topology may be omitted by systems where all CPUs are equal.
35 struct cpu_group *cg_parent; /* Our parent group. */
36 struct cpu_group *cg_child; /* Optional children groups. */
37 cpuset_t cg_mask; /* Mask of cpus in this group. */
38 int32_t cg_count; /* Count of cpus in this group. */
39 int16_t cg_children; /* Number of children groups. */
40 int8_t cg_level; /* Shared cache level. */
41 int8_t cg_flags; /* Traversal modifiers. */
44 typedef struct cpu_group *cpu_group_t;
47 * Defines common resources for CPUs in the group. The highest level
48 * resource should be used when multiple are shared.
50 #define CG_SHARE_NONE 0
56 * Behavior modifiers for load balancing and affinity.
58 #define CG_FLAG_HTT 0x01 /* Schedule the alternate core last. */
59 #define CG_FLAG_SMT 0x02 /* New age htt, less crippled. */
60 #define CG_FLAG_THREAD (CG_FLAG_HTT | CG_FLAG_SMT) /* Any threading. */
63 * Convenience routines for building topologies.
66 struct cpu_group *smp_topo(void);
67 struct cpu_group *smp_topo_none(void);
68 struct cpu_group *smp_topo_1level(int l1share, int l1count, int l1flags);
69 struct cpu_group *smp_topo_2level(int l2share, int l2count, int l1share,
70 int l1count, int l1flags);
71 struct cpu_group *smp_topo_find(struct cpu_group *top, int cpu);
73 extern void (*cpustop_restartfunc)(void);
75 extern volatile cpuset_t started_cpus;
76 extern volatile cpuset_t stopped_cpus;
77 extern volatile cpuset_t suspended_cpus;
78 extern cpuset_t hlt_cpus_mask;
79 extern cpuset_t logical_cpus_mask;
82 extern u_int mp_maxid;
83 extern int mp_maxcpus;
85 extern volatile int smp_started;
87 extern cpuset_t all_cpus;
90 * Macro allowing us to determine whether a CPU is absent at any given
91 * time, thus permitting us to configure sparse maps of cpuid-dependent
92 * (per-CPU) structures.
94 #define CPU_ABSENT(x_cpu) (!CPU_ISSET(x_cpu, &all_cpus))
97 * Macros to iterate over non-absent CPUs. CPU_FOREACH() takes an
98 * integer iterator and iterates over the available set of CPUs.
99 * CPU_FIRST() returns the id of the first non-absent CPU. CPU_NEXT()
100 * returns the id of the next non-absent CPU. It will wrap back to
101 * CPU_FIRST() once the end of the list is reached. The iterators are
102 * currently implemented via inline functions.
104 #define CPU_FOREACH(i) \
105 for ((i) = 0; (i) <= mp_maxid; (i)++) \
106 if (!CPU_ABSENT((i)))
131 #define CPU_FIRST() cpu_first()
132 #define CPU_NEXT(i) cpu_next((i))
136 * Machine dependent functions used to initialize MP support.
138 * The cpu_mp_probe() should check to see if MP support is present and return
139 * zero if it is not or non-zero if it is. If MP support is present, then
140 * cpu_mp_start() will be called so that MP can be enabled. This function
141 * should do things such as startup secondary processors. It should also
142 * setup mp_ncpus, all_cpus, and smp_cpus. It should also ensure that
143 * smp_started is initialized at the appropriate time.
144 * Once cpu_mp_start() returns, machine independent MP startup code will be
145 * executed and a simple message will be output to the console. Finally,
146 * cpu_mp_announce() will be called so that machine dependent messages about
147 * the MP support may be output to the console if desired.
149 * The cpu_setmaxid() function is called very early during the boot process
150 * so that the MD code may set mp_maxid to provide an upper bound on CPU IDs
151 * that other subsystems may use. If a platform is not able to determine
152 * the exact maximum ID that early, then it may set mp_maxid to MAXCPU - 1.
156 struct cpu_group *cpu_topo(void);
157 void cpu_mp_announce(void);
158 int cpu_mp_probe(void);
159 void cpu_mp_setmaxid(void);
160 void cpu_mp_start(void);
162 void forward_signal(struct thread *);
163 int restart_cpus(cpuset_t);
164 int stop_cpus(cpuset_t);
165 int stop_cpus_hard(cpuset_t);
166 #if defined(__amd64__) || defined(__i386__)
167 int suspend_cpus(cpuset_t);
168 int resume_cpus(cpuset_t);
171 void smp_rendezvous_action(void);
172 extern struct mtx smp_ipi_mtx;
176 int quiesce_all_cpus(const char *, int);
177 int quiesce_cpus(cpuset_t, const char *, int);
178 void smp_no_rendevous_barrier(void *);
179 void smp_rendezvous(void (*)(void *),
183 void smp_rendezvous_cpus(cpuset_t,
190 #endif /* _SYS_SMP_H_ */