summaryrefslogtreecommitdiffstats
path: root/sys/ia64
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2001-04-27 19:28:25 +0000
committerjhb <jhb@FreeBSD.org>2001-04-27 19:28:25 +0000
commit8bfdafc9349392c2fe02f548d6ffe6db56626575 (patch)
treeb44641a14ad9f8eb3b338e429775d3298b8946e2 /sys/ia64
parent95c17411607d3bc160b63f97e94912bf27b24274 (diff)
downloadFreeBSD-src-8bfdafc9349392c2fe02f548d6ffe6db56626575.zip
FreeBSD-src-8bfdafc9349392c2fe02f548d6ffe6db56626575.tar.gz
Overhaul of the SMP code. Several portions of the SMP kernel support have
been made machine independent and various other adjustments have been made to support Alpha SMP. - It splits the per-process portions of hardclock() and statclock() off into hardclock_process() and statclock_process() respectively. hardclock() and statclock() call the *_process() functions for the current process so that UP systems will run as before. For SMP systems, it is simply necessary to ensure that all other processors execute the *_process() functions when the main clock functions are triggered on one CPU by an interrupt. For the alpha 4100, clock interrupts are delievered in a staggered broadcast fashion, so we simply call hardclock/statclock on the boot CPU and call the *_process() functions on the secondaries. For x86, we call statclock and hardclock as usual and then call forward_hardclock/statclock in the MD code to send an IPI to cause the AP's to execute forwared_hardclock/statclock which then call the *_process() functions. - forward_signal() and forward_roundrobin() have been reworked to be MI and to involve less hackery. Now the cpu doing the forward sets any flags, etc. and sends a very simple IPI_AST to the other cpu(s). AST IPIs now just basically return so that they can execute ast() and don't bother with setting the astpending or needresched flags themselves. This also removes the loop in forward_signal() as sched_lock closes the race condition that the loop worked around. - need_resched(), resched_wanted() and clear_resched() have been changed to take a process to act on rather than assuming curproc so that they can be used to implement forward_roundrobin() as described above. - Various other SMP variables have been moved to a MI subr_smp.c and a new header sys/smp.h declares MI SMP variables and API's. The IPI API's from machine/ipl.h have moved to machine/smp.h which is included by sys/smp.h. - The globaldata_register() and globaldata_find() functions as well as the SLIST of globaldata structures has become MI and moved into subr_smp.c. Also, the globaldata list is only available if SMP support is compiled in. Reviewed by: jake, peter Looked over by: eivind
Diffstat (limited to 'sys/ia64')
-rw-r--r--sys/ia64/ia64/db_interface.c2
-rw-r--r--sys/ia64/ia64/machdep.c21
-rw-r--r--sys/ia64/ia64/mp_machdep.c289
-rw-r--r--sys/ia64/ia64/trap.c6
-rw-r--r--sys/ia64/include/cpu.h3
-rw-r--r--sys/ia64/include/globaldata.h4
-rw-r--r--sys/ia64/include/ipl.h15
-rw-r--r--sys/ia64/include/pcpu.h4
-rw-r--r--sys/ia64/include/smp.h41
9 files changed, 37 insertions, 348 deletions
diff --git a/sys/ia64/ia64/db_interface.c b/sys/ia64/ia64/db_interface.c
index 3750189..7069f60 100644
--- a/sys/ia64/ia64/db_interface.c
+++ b/sys/ia64/ia64/db_interface.c
@@ -44,6 +44,7 @@
#include <sys/reboot.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#include <sys/smp.h>
#include <sys/cons.h>
#include <sys/ktr.h>
@@ -51,7 +52,6 @@
#include <machine/db_machdep.h>
#include <machine/mutex.h>
-#include <machine/smp.h>
#include <machine/inst.h>
diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c
index a113c9b..9eac9ed 100644
--- a/sys/ia64/ia64/machdep.c
+++ b/sys/ia64/ia64/machdep.c
@@ -82,8 +82,6 @@ u_int32_t cycles_per_sec;
int cold = 1;
struct bootinfo_kernel bootinfo;
-struct cpuhead cpuhead;
-
struct mtx sched_lock;
struct mtx Giant;
@@ -579,12 +577,6 @@ ia64_init()
proc0.p_md.md_tf =
(struct trapframe *)(proc0.p_addr->u_pcb.pcb_sp + 16);
- /*
- * Record all cpus in a list.
- */
- SLIST_INIT(&cpuhead);
- SLIST_INSERT_HEAD(&cpuhead, GLOBALP, gd_allcpu);
-
/* Setup curproc so that mutexes work */
PCPU_SET(curproc, &proc0);
PCPU_SET(spinlocks, NULL);
@@ -1367,3 +1359,16 @@ ia64_fpstate_switch(struct proc *p)
p->p_md.md_flags |= MDP_FPUSED;
}
+
+/*
+ * Initialise a struct globaldata.
+ */
+void
+globaldata_init(struct globaldata *globaldata, int cpuid, size_t sz)
+{
+ bzero(globaldata, sz);
+ globaldata->gd_cpuid = cpuid;
+#ifdef SMP
+ globaldata_register(globaldata);
+#endif
+}
diff --git a/sys/ia64/ia64/mp_machdep.c b/sys/ia64/ia64/mp_machdep.c
index db73f61..143963a 100644
--- a/sys/ia64/ia64/mp_machdep.c
+++ b/sys/ia64/ia64/mp_machdep.c
@@ -34,6 +34,7 @@
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/kernel.h>
+#include <sys/smp.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
@@ -42,7 +43,6 @@
#include <sys/user.h>
#include <sys/dkstat.h>
-#include <machine/smp.h>
#include <machine/atomic.h>
#include <machine/ipl.h>
#include <machine/globaldata.h>
@@ -53,8 +53,6 @@
#define CHECKSTATE_SYS 1
#define CHECKSTATE_INTR 2
-volatile u_int stopped_cpus;
-volatile u_int started_cpus;
volatile u_int checkstate_probed_cpus;
volatile u_int checkstate_need_ast;
volatile u_int checkstate_pending_ast;
@@ -62,76 +60,27 @@ struct proc* checkstate_curproc[MAXCPU];
int checkstate_cpustate[MAXCPU];
u_long checkstate_pc[MAXCPU];
volatile u_int resched_cpus;
-void (*cpustop_restartfunc) __P((void));
-int mp_ncpus;
-int smp_started;
int boot_cpu_id;
-u_int32_t all_cpus;
-
-static struct globaldata *cpuid_to_globaldata[MAXCPU];
-
-int smp_active = 0; /* are the APs allowed to run? */
-SYSCTL_INT(_machdep, OID_AUTO, smp_active, CTLFLAG_RW, &smp_active, 0, "");
/* Is forwarding of a interrupt to the CPU holding the ISR lock enabled ? */
int forward_irq_enabled = 1;
SYSCTL_INT(_machdep, OID_AUTO, forward_irq_enabled, CTLFLAG_RW,
&forward_irq_enabled, 0, "");
-/* Enable forwarding of a signal to a process running on a different CPU */
-static int forward_signal_enabled = 1;
-SYSCTL_INT(_machdep, OID_AUTO, forward_signal_enabled, CTLFLAG_RW,
- &forward_signal_enabled, 0, "");
-
-/* Enable forwarding of roundrobin to all other cpus */
-static int forward_roundrobin_enabled = 1;
-SYSCTL_INT(_machdep, OID_AUTO, forward_roundrobin_enabled, CTLFLAG_RW,
- &forward_roundrobin_enabled, 0, "");
-
-/*
- * Initialise a struct globaldata.
- */
-void
-globaldata_init(struct globaldata *globaldata, int cpuid, size_t sz)
-{
- bzero(globaldata, sz);
- globaldata->gd_cpuid = cpuid;
- globaldata->gd_other_cpus = all_cpus & ~(1 << cpuid);
- cpuid_to_globaldata[cpuid] = globaldata;
-}
-
-struct globaldata *
-globaldata_find(int cpuid)
-{
- return cpuid_to_globaldata[cpuid];
-}
-
-/* Other stuff */
-
-/* lock around the MP rendezvous */
-static struct mtx smp_rv_mtx;
-
-static void
-init_locks(void)
-{
-
- mtx_init(&smp_rv_mtx, "smp_rendezvous", MTX_SPIN);
-}
-
-void
-mp_start()
+int
+cpu_mp_probe()
{
- init_locks();
+ return (0);
}
void
-mp_announce()
+cpu_mp_start()
{
}
void
-smp_invltlb()
+cpu_mp_announce()
{
}
@@ -426,227 +375,6 @@ forward_hardclock(int pscnt)
}
}
-void
-forward_signal(struct proc *p)
-{
- int map;
- int id;
- int i;
-
- /* Kludge. We don't yet have separate locks for the interrupts
- * and the kernel. This means that we cannot let the other processors
- * handle complex interrupts while inhibiting them from entering
- * the kernel in a non-interrupt context.
- *
- * What we can do, without changing the locking mechanisms yet,
- * is letting the other processors handle a very simple interrupt
- * (wich determines the processor states), and do the main
- * work ourself.
- */
-
- CTR1(KTR_SMP, "forward_signal(%p)", p);
-
- if (!smp_started || cold || panicstr)
- return;
- if (!forward_signal_enabled)
- return;
- while (1) {
- if (p->p_stat != SRUN)
- return;
- id = p->p_oncpu;
- if (id == 0xff)
- return;
- map = (1<<id);
- checkstate_need_ast |= map;
- ipi_selected(map, IPI_AST);
- i = 0;
- while ((checkstate_need_ast & map) != 0) {
- /* spin */
- i++;
- if (i > 100000) {
-#if 0
- printf("forward_signal: dropped ast 0x%x\n",
- checkstate_need_ast & map);
-#endif
- break;
- }
- }
- if (id == p->p_oncpu)
- return;
- }
-}
-
-void
-forward_roundrobin(void)
-{
- u_int map;
- int i;
-
- CTR0(KTR_SMP, "forward_roundrobin()");
-
- if (!smp_started || cold || panicstr)
- return;
- if (!forward_roundrobin_enabled)
- return;
- resched_cpus |= PCPU_GET(other_cpus);
- map = PCPU_GET(other_cpus) & ~stopped_cpus ;
- ipi_selected(map, IPI_AST);
- i = 0;
- while ((checkstate_need_ast & map) != 0) {
- /* spin */
- i++;
- if (i > 100000) {
-#if 0
- printf("forward_roundrobin: dropped ast 0x%x\n",
- checkstate_need_ast & map);
-#endif
- break;
- }
- }
-}
-
-/*
- * When called the executing CPU will send an IPI to all other CPUs
- * requesting that they halt execution.
- *
- * Usually (but not necessarily) called with 'other_cpus' as its arg.
- *
- * - Signals all CPUs in map to stop.
- * - Waits for each to stop.
- *
- * Returns:
- * -1: error
- * 0: NA
- * 1: ok
- *
- * XXX FIXME: this is not MP-safe, needs a lock to prevent multiple CPUs
- * from executing at same time.
- */
-int
-stop_cpus(u_int map)
-{
- int i;
-
- if (!smp_started)
- return 0;
-
- CTR1(KTR_SMP, "stop_cpus(%x)", map);
-
- /* send the stop IPI to all CPUs in map */
- ipi_selected(map, IPI_STOP);
-
- i = 0;
- while ((stopped_cpus & map) != map) {
- /* spin */
- i++;
- if (i == 100000) {
- printf("timeout stopping cpus\n");
- break;
- }
- ia64_mf();
- }
-
- printf("stopped_cpus=%x\n", stopped_cpus);
-
- return 1;
-}
-
-
-/*
- * Called by a CPU to restart stopped CPUs.
- *
- * Usually (but not necessarily) called with 'stopped_cpus' as its arg.
- *
- * - Signals all CPUs in map to restart.
- * - Waits for each to restart.
- *
- * Returns:
- * -1: error
- * 0: NA
- * 1: ok
- */
-int
-restart_cpus(u_int map)
-{
- if (!smp_started)
- return 0;
-
- CTR1(KTR_SMP, "restart_cpus(%x)", map);
-
- started_cpus = map; /* signal other cpus to restart */
- ia64_mf();
-
- while ((stopped_cpus & map) != 0) /* wait for each to clear its bit */
- ia64_mf();
-
- return 1;
-}
-
-/*
- * All-CPU rendezvous. CPUs are signalled, all execute the setup function
- * (if specified), rendezvous, execute the action function (if specified),
- * rendezvous again, execute the teardown function (if specified), and then
- * resume.
- *
- * Note that the supplied external functions _must_ be reentrant and aware
- * that they are running in parallel and in an unknown lock context.
- */
-static void (*smp_rv_setup_func)(void *arg);
-static void (*smp_rv_action_func)(void *arg);
-static void (*smp_rv_teardown_func)(void *arg);
-static void *smp_rv_func_arg;
-static volatile int smp_rv_waiters[2];
-
-void
-smp_rendezvous_action(void)
-{
- /* setup function */
- if (smp_rv_setup_func != NULL)
- smp_rv_setup_func(smp_rv_func_arg);
- /* spin on entry rendezvous */
- atomic_add_int(&smp_rv_waiters[0], 1);
- while (smp_rv_waiters[0] < mp_ncpus)
- ;
- /* action function */
- if (smp_rv_action_func != NULL)
- smp_rv_action_func(smp_rv_func_arg);
- /* spin on exit rendezvous */
- atomic_add_int(&smp_rv_waiters[1], 1);
- while (smp_rv_waiters[1] < mp_ncpus)
- ;
- /* teardown function */
- if (smp_rv_teardown_func != NULL)
- smp_rv_teardown_func(smp_rv_func_arg);
-}
-
-void
-smp_rendezvous(void (* setup_func)(void *),
- void (* action_func)(void *),
- void (* teardown_func)(void *),
- void *arg)
-{
-
- /* obtain rendezvous lock */
- mtx_lock_spin(&smp_rv_mtx);
-
- /* set static function pointers */
- smp_rv_setup_func = setup_func;
- smp_rv_action_func = action_func;
- smp_rv_teardown_func = teardown_func;
- smp_rv_func_arg = arg;
- smp_rv_waiters[0] = 0;
- smp_rv_waiters[1] = 0;
-
- /* signal other processors, which will enter the IPI with interrupts off */
- ipi_all_but_self(IPI_RENDEZVOUS);
-
- /* call executor function */
- smp_rendezvous_action();
-
- /* release lock */
- mtx_unlock_spin(&smp_rv_mtx);
-}
-
/*
* send an IPI to a set of cpus.
*/
@@ -661,7 +389,7 @@ ipi_selected(u_int32_t cpus, u_int64_t ipi)
int cpuid = ffs(cpus) - 1;
cpus &= ~(1 << cpuid);
- globaldata = cpuid_to_globaldata[cpuid];
+ globaldata = globaldata_find(cpuid);
if (globaldata) {
atomic_set_64(&globaldata->gd_pending_ipis, ipi);
ia64_mf();
@@ -733,9 +461,6 @@ smp_handle_ipi(struct trapframe *frame)
CTR0(KTR_SMP, "IPI_AST");
atomic_clear_int(&checkstate_need_ast, 1<<cpuid);
atomic_set_int(&checkstate_pending_ast, 1<<cpuid);
- if ((frame->tf_cr_ipsr & IA64_PSR_CPL)
- == IA64_PSR_CPL_USER)
- ast(frame); /* XXX */
break;
case IPI_CHECKSTATE:
diff --git a/sys/ia64/ia64/trap.c b/sys/ia64/ia64/trap.c
index 8486877..8f9b258 100644
--- a/sys/ia64/ia64/trap.c
+++ b/sys/ia64/ia64/trap.c
@@ -41,6 +41,7 @@
#include <sys/exec.h>
#include <sys/lock.h>
#include <sys/mutex.h>
+#include <sys/smp.h>
#include <sys/vmmeter.h>
#include <sys/sysent.h>
#include <sys/syscall.h>
@@ -58,7 +59,6 @@
#include <machine/reg.h>
#include <machine/pal.h>
#include <machine/fpu.h>
-#include <machine/smp.h>
#ifdef KTRACE
#include <sys/uio.h>
@@ -90,7 +90,7 @@ userret(register struct proc *p, struct trapframe *frame, u_quad_t oticks)
mtx_lock_spin(&sched_lock);
p->p_pri.pri_level = p->p_pri.pri_user;
- if (resched_wanted()) {
+ if (resched_wanted(p)) {
/*
* Since we are curproc, a clock interrupt could
* change our priority without changing run queues
@@ -638,7 +638,7 @@ ast(framep)
* acquiring and release mutexes in assembly is not fun.
*/
mtx_lock_spin(&sched_lock);
- if (!(astpending(p) || resched_wanted())) {
+ if (!(astpending(p) || resched_wanted(p))) {
mtx_unlock_spin(&sched_lock);
return;
}
diff --git a/sys/ia64/include/cpu.h b/sys/ia64/include/cpu.h
index 2b15a48..61766d2 100644
--- a/sys/ia64/include/cpu.h
+++ b/sys/ia64/include/cpu.h
@@ -68,9 +68,6 @@ struct clockframe {
#define CLKF_USERMODE(framep) TRAPF_USERMODE(&(framep)->cf_tf)
#define CLKF_PC(framep) TRAPF_PC(&(framep)->cf_tf)
-#define CLKF_BASEPRI(framep) \
- (((framep)->cf_tf.tf_cr_ipsr & IA64_PSR_I) == 0)
-#define CLKF_INTR(framep) (curproc->p_intr_nesting_level >= 2)
/*
* Give a profiling tick to the current process when the user profiling
diff --git a/sys/ia64/include/globaldata.h b/sys/ia64/include/globaldata.h
index a92f543..0ec1e19 100644
--- a/sys/ia64/include/globaldata.h
+++ b/sys/ia64/include/globaldata.h
@@ -66,11 +66,7 @@ struct globaldata {
#endif
};
-SLIST_HEAD(cpuhead, globaldata);
-extern struct cpuhead cpuhead;
-
void globaldata_init(struct globaldata *pcpu, int cpuid, size_t sz);
-struct globaldata *globaldata_find(int cpuid);
#endif /* _KERNEL */
diff --git a/sys/ia64/include/ipl.h b/sys/ia64/include/ipl.h
index 8432299..cbdecbb 100644
--- a/sys/ia64/include/ipl.h
+++ b/sys/ia64/include/ipl.h
@@ -29,19 +29,4 @@
#ifndef _MACHINE_IPL_H_
#define _MACHINE_IPL_H_
-/*
- * Interprocessor interrupts for SMP.
- */
-#define IPI_INVLTLB 0x0001
-#define IPI_RENDEZVOUS 0x0002
-#define IPI_AST 0x0004
-#define IPI_CHECKSTATE 0x0008
-#define IPI_STOP 0x0010
-
-void ipi_selected(u_int32_t cpus, u_int64_t ipi);
-void ipi_all(u_int64_t ipi);
-void ipi_all_but_self(u_int64_t ipi);
-void ipi_self(u_int64_t ipi);
-void smp_handle_ipi(struct trapframe *frame);
-
#endif /* !_MACHINE_IPL_H_ */
diff --git a/sys/ia64/include/pcpu.h b/sys/ia64/include/pcpu.h
index a92f543..0ec1e19 100644
--- a/sys/ia64/include/pcpu.h
+++ b/sys/ia64/include/pcpu.h
@@ -66,11 +66,7 @@ struct globaldata {
#endif
};
-SLIST_HEAD(cpuhead, globaldata);
-extern struct cpuhead cpuhead;
-
void globaldata_init(struct globaldata *pcpu, int cpuid, size_t sz);
-struct globaldata *globaldata_find(int cpuid);
#endif /* _KERNEL */
diff --git a/sys/ia64/include/smp.h b/sys/ia64/include/smp.h
index 65c85ef..e4f2091 100644
--- a/sys/ia64/include/smp.h
+++ b/sys/ia64/include/smp.h
@@ -6,43 +6,28 @@
#ifdef _KERNEL
-#include <machine/mutex.h>
-#include <machine/ipl.h>
-#include <sys/ktr.h>
+/*
+ * Interprocessor interrupts for SMP.
+ */
+#define IPI_INVLTLB 0x0001
+#define IPI_RENDEZVOUS 0x0002
+#define IPI_AST 0x0004
+#define IPI_CHECKSTATE 0x0008
+#define IPI_STOP 0x0010
#ifndef LOCORE
-#define BETTER_CLOCK /* unconditional on ia64 */
-
/* global data in mp_machdep.c */
extern volatile u_int checkstate_probed_cpus;
extern volatile u_int checkstate_need_ast;
extern volatile u_int resched_cpus;
-extern void (*cpustop_restartfunc) __P((void));
-
-extern int smp_active;
-extern int mp_ncpus;
-extern u_int all_cpus;
-extern u_int started_cpus;
-extern u_int stopped_cpus;
-/* functions in mp_machdep.c */
-void mp_start(void);
-void mp_announce(void);
-void smp_invltlb(void);
-void forward_statclock(int pscnt);
-void forward_hardclock(int pscnt);
-void forward_signal(struct proc *);
-void forward_roundrobin(void);
-int stop_cpus(u_int);
-int restart_cpus(u_int);
-void smp_rendezvous_action(void);
-void smp_rendezvous(void (*)(void *),
- void (*)(void *),
- void (*)(void *),
- void *arg);
+void ipi_selected(u_int cpus, u_int ipi);
+void ipi_all(u_int ipi);
+void ipi_all_but_self(u_int ipi);
+void ipi_self(u_int ipi);
void smp_init_secondary(void);
#endif /* !LOCORE */
#endif /* _KERNEL */
-#endif
+#endif /* !_MACHINE_SMP_H */
OpenPOWER on IntegriCloud