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>
20 #include <sys/queue.h>
23 * Types of nodes in the topological tree.
26 /* No node has this type; can be used in topo API calls. */
28 /* Processing unit aka computing unit aka logical CPU. */
30 /* Physical subdivision of a package. */
32 /* CPU L1/L2/L3 cache. */
34 /* Package aka chip, equivalent to socket. */
38 /* Other logical or physical grouping of PUs. */
39 /* E.g. PUs on the same dye, or PUs sharing an FPU. */
41 /* The whole system. */
45 /* Hardware indenitifier of a topology component. */
46 typedef unsigned int hwid_t;
47 /* Logical CPU idenitifier. */
50 /* A node in the topology. */
52 struct topo_node *parent;
53 TAILQ_HEAD(topo_children, topo_node) children;
54 TAILQ_ENTRY(topo_node) siblings;
65 * Scheduling topology of a NUMA or SMP system.
67 * The top level topology is an array of pointers to groups. Each group
68 * contains a bitmask of cpus in its group or subgroups. It may also
69 * contain a pointer to an array of child groups.
71 * The bitmasks at non leaf groups may be used by consumers who support
72 * a smaller depth than the hardware provides.
74 * The topology may be omitted by systems where all CPUs are equal.
78 struct cpu_group *cg_parent; /* Our parent group. */
79 struct cpu_group *cg_child; /* Optional children groups. */
80 cpuset_t cg_mask; /* Mask of cpus in this group. */
81 int32_t cg_count; /* Count of cpus in this group. */
82 int16_t cg_children; /* Number of children groups. */
83 int8_t cg_level; /* Shared cache level. */
84 int8_t cg_flags; /* Traversal modifiers. */
87 typedef struct cpu_group *cpu_group_t;
90 * Defines common resources for CPUs in the group. The highest level
91 * resource should be used when multiple are shared.
93 #define CG_SHARE_NONE 0
98 #define MAX_CACHE_LEVELS CG_SHARE_L3
101 * Behavior modifiers for load balancing and affinity.
103 #define CG_FLAG_HTT 0x01 /* Schedule the alternate core last. */
104 #define CG_FLAG_SMT 0x02 /* New age htt, less crippled. */
105 #define CG_FLAG_THREAD (CG_FLAG_HTT | CG_FLAG_SMT) /* Any threading. */
108 * Convenience routines for building and traversing topologies.
111 void topo_init_node(struct topo_node *node);
112 void topo_init_root(struct topo_node *root);
113 struct topo_node * topo_add_node_by_hwid(struct topo_node *parent, int hwid,
114 topo_node_type type, uintptr_t subtype);
115 struct topo_node * topo_find_node_by_hwid(struct topo_node *parent, int hwid,
116 topo_node_type type, uintptr_t subtype);
117 void topo_promote_child(struct topo_node *child);
118 struct topo_node * topo_next_node(struct topo_node *top,
119 struct topo_node *node);
120 struct topo_node * topo_next_nonchild_node(struct topo_node *top,
121 struct topo_node *node);
122 void topo_set_pu_id(struct topo_node *node, cpuid_t id);
127 * Some systems have useful sub-package core organizations. On these,
128 * a package has one or more subgroups. Each subgroup contains one or
129 * more cache groups (cores that share a last level cache).
132 TOPO_LEVEL_CACHEGROUP,
135 TOPO_LEVEL_COUNT /* Must be last */
137 struct topo_analysis {
138 int entities[TOPO_LEVEL_COUNT];
140 int topo_analyze(struct topo_node *topo_root, int all,
141 struct topo_analysis *results);
143 #define TOPO_FOREACH(i, root) \
144 for (i = root; i != NULL; i = topo_next_node(root, i))
146 struct cpu_group *smp_topo(void);
147 struct cpu_group *smp_topo_alloc(u_int count);
148 struct cpu_group *smp_topo_none(void);
149 struct cpu_group *smp_topo_1level(int l1share, int l1count, int l1flags);
150 struct cpu_group *smp_topo_2level(int l2share, int l2count, int l1share,
151 int l1count, int l1flags);
152 struct cpu_group *smp_topo_find(struct cpu_group *top, int cpu);
154 extern void (*cpustop_restartfunc)(void);
156 extern volatile cpuset_t started_cpus;
157 extern volatile cpuset_t stopped_cpus;
158 extern volatile cpuset_t suspended_cpus;
159 extern cpuset_t hlt_cpus_mask;
160 extern cpuset_t logical_cpus_mask;
163 extern u_int mp_maxid;
164 extern int mp_maxcpus;
166 extern volatile int smp_started;
168 extern cpuset_t all_cpus;
169 extern cpuset_t cpuset_domain[MAXMEMDOM]; /* CPUs in each NUMA domain. */
172 * Macro allowing us to determine whether a CPU is absent at any given
173 * time, thus permitting us to configure sparse maps of cpuid-dependent
174 * (per-CPU) structures.
176 #define CPU_ABSENT(x_cpu) (!CPU_ISSET(x_cpu, &all_cpus))
179 * Macros to iterate over non-absent CPUs. CPU_FOREACH() takes an
180 * integer iterator and iterates over the available set of CPUs.
181 * CPU_FIRST() returns the id of the first non-absent CPU. CPU_NEXT()
182 * returns the id of the next non-absent CPU. It will wrap back to
183 * CPU_FIRST() once the end of the list is reached. The iterators are
184 * currently implemented via inline functions.
186 #define CPU_FOREACH(i) \
187 for ((i) = 0; (i) <= mp_maxid; (i)++) \
188 if (!CPU_ABSENT((i)))
213 #define CPU_FIRST() cpu_first()
214 #define CPU_NEXT(i) cpu_next((i))
218 * Machine dependent functions used to initialize MP support.
220 * The cpu_mp_probe() should check to see if MP support is present and return
221 * zero if it is not or non-zero if it is. If MP support is present, then
222 * cpu_mp_start() will be called so that MP can be enabled. This function
223 * should do things such as startup secondary processors. It should also
224 * setup mp_ncpus, all_cpus, and smp_cpus. It should also ensure that
225 * smp_started is initialized at the appropriate time.
226 * Once cpu_mp_start() returns, machine independent MP startup code will be
227 * executed and a simple message will be output to the console. Finally,
228 * cpu_mp_announce() will be called so that machine dependent messages about
229 * the MP support may be output to the console if desired.
231 * The cpu_setmaxid() function is called very early during the boot process
232 * so that the MD code may set mp_maxid to provide an upper bound on CPU IDs
233 * that other subsystems may use. If a platform is not able to determine
234 * the exact maximum ID that early, then it may set mp_maxid to MAXCPU - 1.
238 struct cpu_group *cpu_topo(void);
239 void cpu_mp_announce(void);
240 int cpu_mp_probe(void);
241 void cpu_mp_setmaxid(void);
242 void cpu_mp_start(void);
244 void forward_signal(struct thread *);
245 int restart_cpus(cpuset_t);
246 int stop_cpus(cpuset_t);
247 int stop_cpus_hard(cpuset_t);
248 #if defined(__amd64__) || defined(__i386__)
249 int suspend_cpus(cpuset_t);
250 int resume_cpus(cpuset_t);
253 void smp_rendezvous_action(void);
254 extern struct mtx smp_ipi_mtx;
258 int quiesce_all_cpus(const char *, int);
259 int quiesce_cpus(cpuset_t, const char *, int);
260 void smp_no_rendezvous_barrier(void *);
261 void smp_rendezvous(void (*)(void *),
265 void smp_rendezvous_cpus(cpuset_t,
272 #endif /* _SYS_SMP_H_ */