smp.h revision 134416
125164Speter/*
225164Speter * ----------------------------------------------------------------------------
325164Speter * "THE BEER-WARE LICENSE" (Revision 42):
425164Speter * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
525164Speter * can do whatever you want with this stuff. If we meet some day, and you think
625164Speter * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
725164Speter * ----------------------------------------------------------------------------
825164Speter *
950477Speter * $FreeBSD: head/sys/sys/smp.h 134416 2004-08-28 00:49:55Z obrien $
1025164Speter */
1125164Speter
1276078Sjhb#ifndef _SYS_SMP_H_
1376078Sjhb#define _SYS_SMP_H_
1425164Speter
1555205Speter#ifdef _KERNEL
1625164Speter
1776078Sjhb#ifndef LOCORE
1825517Sfsmp
1976078Sjhb#ifdef SMP
20117005Sjeff
21117005Sjeff/*
22117005Sjeff * Topology of a NUMA or HTT system.
23117005Sjeff *
24117005Sjeff * The top level topology is an array of pointers to groups.  Each group
25117005Sjeff * contains a bitmask of cpus in its group or subgroups.  It may also
26117005Sjeff * contain a pointer to an array of child groups.
27117005Sjeff *
28117005Sjeff * The bitmasks at non leaf groups may be used by consumers who support
29117005Sjeff * a smaller depth than the hardware provides.
30117005Sjeff *
31117005Sjeff * The topology may be omitted by systems where all CPUs are equal.
32117005Sjeff */
33117005Sjeff
34117005Sjeffstruct cpu_group {
35127498Smarcel	cpumask_t cg_mask;		/* Mask of cpus in this group. */
36117005Sjeff	int	cg_count;		/* Count of cpus in this group. */
37117005Sjeff	int	cg_children;		/* Number of children groups. */
38117005Sjeff	struct cpu_group *cg_child;	/* Optional child group. */
39117005Sjeff};
40117005Sjeff
41117005Sjeffstruct cpu_top {
42117005Sjeff	int	ct_count;		/* Count of groups. */
43117005Sjeff	struct cpu_group *ct_group;	/* Array of pointers to cpu groups. */
44117005Sjeff};
45117005Sjeff
46117005Sjeffextern struct cpu_top *smp_topology;
4776078Sjhbextern void (*cpustop_restartfunc)(void);
4876078Sjhbextern int smp_active;
4976078Sjhbextern int smp_cpus;
50127498Smarcelextern volatile cpumask_t started_cpus;
51127498Smarcelextern volatile cpumask_t stopped_cpus;
52123125Sjhb#endif /* SMP */
53123125Sjhb
54127498Smarcelextern cpumask_t all_cpus;
5591673Sjeffextern u_int mp_maxid;
56123125Sjhbextern int mp_ncpus;
57123125Sjhbextern volatile int smp_started;
5827728Sfsmp
5927002Sfsmp/*
6080779Sbmilekic * Macro allowing us to determine whether a CPU is absent at any given
6180779Sbmilekic * time, thus permitting us to configure sparse maps of cpuid-dependent
6280779Sbmilekic * (per-CPU) structures.
6380779Sbmilekic */
6480779Sbmilekic#define	CPU_ABSENT(x_cpu)	((all_cpus & (1 << (x_cpu))) == 0)
6580779Sbmilekic
66123125Sjhb#ifdef SMP
6780779Sbmilekic/*
6876078Sjhb * Machine dependent functions used to initialize MP support.
6976078Sjhb *
7076078Sjhb * The cpu_mp_probe() should check to see if MP support is present and return
7176078Sjhb * zero if it is not or non-zero if it is.  If MP support is present, then
7276078Sjhb * cpu_mp_start() will be called so that MP can be enabled.  This function
7376078Sjhb * should do things such as startup secondary processors.  It should also
7476078Sjhb * setup mp_ncpus, all_cpus, and smp_cpus.  It should also ensure that
7576078Sjhb * smp_active and smp_started are initialized at the appropriate time.
7676078Sjhb * Once cpu_mp_start() returns, machine independent MP startup code will be
7776078Sjhb * executed and a simple message will be output to the console.  Finally,
7876078Sjhb * cpu_mp_announce() will be called so that machine dependent messages about
7976078Sjhb * the MP support may be output to the console if desired.
80122947Sjhb *
81122947Sjhb * The cpu_setmaxid() function is called very early during the boot process
82122947Sjhb * so that the MD code may set mp_maxid to provide an upper bound on CPU IDs
83122947Sjhb * that other subsystems may use.  If a platform is not able to determine
84123126Sjhb * the exact maximum ID that early, then it may set mp_maxid to MAXCPU - 1.
8527002Sfsmp */
8696999Sjakestruct thread;
8796999Sjake
8876078Sjhbvoid	cpu_mp_announce(void);
8976078Sjhbint	cpu_mp_probe(void);
90122947Sjhbvoid	cpu_mp_setmaxid(void);
9176078Sjhbvoid	cpu_mp_start(void);
9227002Sfsmp
9383366Sjulianvoid	forward_signal(struct thread *);
9476078Sjhbvoid	forward_roundrobin(void);
95127498Smarcelint	restart_cpus(cpumask_t);
96127498Smarcelint	stop_cpus(cpumask_t);
9776078Sjhbvoid	smp_rendezvous_action(void);
98134416Sobrienextern	struct mtx smp_ipi_mtx;
99123125Sjhb#endif /* SMP */
10076078Sjhbvoid	smp_rendezvous(void (*)(void *),
10176078Sjhb		       void (*)(void *),
10276078Sjhb		       void (*)(void *),
10376078Sjhb		       void *arg);
10427728Sfsmp#endif /* !LOCORE */
10555205Speter#endif /* _KERNEL */
10676078Sjhb#endif /* _SYS_SMP_H_ */
107