source: rtems-libbsd/freebsd/sys/sys/smp.h @ 2815cdb

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 2815cdb was 2815cdb, checked in by Sebastian Huber <sebastian.huber@…>, on 12/02/13 at 14:36:31

Changes due to <sys/cpuset.h> from latest Newlib

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*-
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 * ----------------------------------------------------------------------------
8 *
9 * $FreeBSD$
10 */
11
12#ifndef _SYS_SMP_H_
13#define _SYS_SMP_H_
14
15#ifdef _KERNEL
16
17#ifndef LOCORE
18
19#include <rtems/bsd/sys/cpuset.h>
20
21/*
22 * Topology of a NUMA or HTT system.
23 *
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.
27 *
28 * The bitmasks at non leaf groups may be used by consumers who support
29 * a smaller depth than the hardware provides.
30 *
31 * The topology may be omitted by systems where all CPUs are equal.
32 */
33
34struct cpu_group {
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. */
42};
43
44typedef struct cpu_group *cpu_group_t;
45
46/*
47 * Defines common resources for CPUs in the group.  The highest level
48 * resource should be used when multiple are shared.
49 */
50#define CG_SHARE_NONE   0
51#define CG_SHARE_L1     1
52#define CG_SHARE_L2     2
53#define CG_SHARE_L3     3
54
55/*
56 * Behavior modifiers for load balancing and affinity.
57 */
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. */
61
62/*
63 * Convenience routines for building topologies.
64 */
65#ifdef SMP
66struct cpu_group *smp_topo(void);
67struct cpu_group *smp_topo_none(void);
68struct cpu_group *smp_topo_1level(int l1share, int l1count, int l1flags);
69struct cpu_group *smp_topo_2level(int l2share, int l2count, int l1share,
70    int l1count, int l1flags);
71struct cpu_group *smp_topo_find(struct cpu_group *top, int cpu);
72
73extern void (*cpustop_restartfunc)(void);
74extern int smp_active;
75extern int smp_cpus;
76extern volatile cpuset_t started_cpus;
77extern volatile cpuset_t stopped_cpus;
78extern cpuset_t hlt_cpus_mask;
79extern cpuset_t logical_cpus_mask;
80#endif /* SMP */
81
82#ifndef __rtems__
83extern u_int mp_maxid;
84extern int mp_maxcpus;
85extern int mp_ncpus;
86extern volatile int smp_started;
87
88extern cpuset_t all_cpus;
89#else /* __rtems__ */
90#define mp_maxid 1U
91#define mp_maxcpus 1
92#define mp_ncpus 1
93#define all_cpus 1U
94#endif /* __rtems__ */
95
96/*
97 * Macro allowing us to determine whether a CPU is absent at any given
98 * time, thus permitting us to configure sparse maps of cpuid-dependent
99 * (per-CPU) structures.
100 */
101#ifndef __rtems__
102#define CPU_ABSENT(x_cpu)       (!CPU_ISSET(x_cpu, &all_cpus))
103#else /* __rtems__ */
104#define CPU_ABSENT(x_cpu) 0
105#endif /* __rtems__ */
106
107/*
108 * Macros to iterate over non-absent CPUs.  CPU_FOREACH() takes an
109 * integer iterator and iterates over the available set of CPUs.
110 * CPU_FIRST() returns the id of the first non-absent CPU.  CPU_NEXT()
111 * returns the id of the next non-absent CPU.  It will wrap back to
112 * CPU_FIRST() once the end of the list is reached.  The iterators are
113 * currently implemented via inline functions.
114 */
115#define CPU_FOREACH(i)                                                  \
116        for ((i) = 0; (i) <= mp_maxid; (i)++)                           \
117                if (!CPU_ABSENT((i)))
118
119static __inline int
120cpu_first(void)
121{
122        int i;
123
124        for (i = 0;; i++)
125                if (!CPU_ABSENT(i))
126                        return (i);
127}
128
129static __inline int
130cpu_next(int i)
131{
132
133        for (;;) {
134                i++;
135                if (i > mp_maxid)
136                        i = 0;
137                if (!CPU_ABSENT(i))
138                        return (i);
139        }
140}
141
142#define CPU_FIRST()     cpu_first()
143#define CPU_NEXT(i)     cpu_next((i))
144
145#ifdef SMP
146/*
147 * Machine dependent functions used to initialize MP support.
148 *
149 * The cpu_mp_probe() should check to see if MP support is present and return
150 * zero if it is not or non-zero if it is.  If MP support is present, then
151 * cpu_mp_start() will be called so that MP can be enabled.  This function
152 * should do things such as startup secondary processors.  It should also
153 * setup mp_ncpus, all_cpus, and smp_cpus.  It should also ensure that
154 * smp_active and smp_started are initialized at the appropriate time.
155 * Once cpu_mp_start() returns, machine independent MP startup code will be
156 * executed and a simple message will be output to the console.  Finally,
157 * cpu_mp_announce() will be called so that machine dependent messages about
158 * the MP support may be output to the console if desired.
159 *
160 * The cpu_setmaxid() function is called very early during the boot process
161 * so that the MD code may set mp_maxid to provide an upper bound on CPU IDs
162 * that other subsystems may use.  If a platform is not able to determine
163 * the exact maximum ID that early, then it may set mp_maxid to MAXCPU - 1.
164 */
165struct thread;
166
167struct cpu_group *cpu_topo(void);
168void    cpu_mp_announce(void);
169int     cpu_mp_probe(void);
170void    cpu_mp_setmaxid(void);
171void    cpu_mp_start(void);
172
173void    forward_signal(struct thread *);
174int     restart_cpus(cpuset_t);
175int     stop_cpus(cpuset_t);
176int     stop_cpus_hard(cpuset_t);
177#if defined(__amd64__) || defined(__i386__)
178int     suspend_cpus(cpuset_t);
179#endif
180void    smp_rendezvous_action(void);
181extern  struct mtx smp_ipi_mtx;
182
183#endif /* SMP */
184void    smp_no_rendevous_barrier(void *);
185void    smp_rendezvous(void (*)(void *),
186                       void (*)(void *),
187                       void (*)(void *),
188                       void *arg);
189void    smp_rendezvous_cpus(cpuset_t,
190                       void (*)(void *),
191                       void (*)(void *),
192                       void (*)(void *),
193                       void *arg);
194#endif /* !LOCORE */
195#endif /* _KERNEL */
196#endif /* _SYS_SMP_H_ */
Note: See TracBrowser for help on using the repository browser.