summaryrefslogtreecommitdiff
path: root/sys/arch/amd64
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2010-04-01 19:48:51 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2010-04-01 19:48:51 +0000
commitdb69f0f9498552064385a0102c0d9e480f672b85 (patch)
treec792eda85395f9d4d1b08c3852c709791aa03125 /sys/arch/amd64
parent23342e47fdbddcd5f3549ab7f7762121979f8216 (diff)
Don't index cpu_info by apic id, but by device unit number instead. Recent
Intel CPUs come up with apic id's >= 32, even on systems with less than 32 logical CPUs. ok krw@, marco@; tested by deraadt@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r--sys/arch/amd64/amd64/cpu.c17
-rw-r--r--sys/arch/amd64/amd64/db_interface.c59
-rw-r--r--sys/arch/amd64/amd64/genassym.cf3
-rw-r--r--sys/arch/amd64/amd64/lapic.c4
-rw-r--r--sys/arch/amd64/amd64/mptramp.S12
5 files changed, 37 insertions, 58 deletions
diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c
index aa84155b939..75a1ffaba82 100644
--- a/sys/arch/amd64/amd64/cpu.c
+++ b/sys/arch/amd64/amd64/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.28 2009/06/09 02:56:38 krw Exp $ */
+/* $OpenBSD: cpu.c,v 1.29 2010/04/01 19:47:59 kettenis Exp $ */
/* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
/*-
@@ -158,13 +158,6 @@ static void cpu_copy_trampoline(void);
void
cpu_init_first(void)
{
- int cpunum = lapic_cpu_number();
-
- if (cpunum != 0) {
- cpu_info[0] = NULL;
- cpu_info[cpunum] = &cpu_info_primary;
- }
-
cpu_copy_trampoline();
}
#endif
@@ -225,7 +218,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
struct cpu_attach_args *caa = aux;
struct cpu_info *ci;
#if defined(MULTIPROCESSOR)
- int cpunum = caa->cpu_number;
+ int cpunum = sc->sc_dev.dv_unit;
vaddr_t kstack;
struct pcb *pcb;
#endif
@@ -248,10 +241,10 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
} else {
ci = &cpu_info_primary;
#if defined(MULTIPROCESSOR)
- if (cpunum != lapic_cpu_number()) {
+ if (caa->cpu_number != lapic_cpu_number()) {
panic("%s: running cpu is at apic %d"
" instead of at expected %d",
- sc->sc_dev.dv_xname, lapic_cpu_number(), cpunum);
+ sc->sc_dev.dv_xname, lapic_cpu_number(), caa->cpu_number);
}
#endif
}
@@ -262,7 +255,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
ci->ci_dev = self;
ci->ci_apicid = caa->cpu_number;
#ifdef MULTIPROCESSOR
- ci->ci_cpuid = ci->ci_apicid;
+ ci->ci_cpuid = cpunum;
#else
ci->ci_cpuid = 0; /* False for APs, but they're not used anyway */
#endif
diff --git a/sys/arch/amd64/amd64/db_interface.c b/sys/arch/amd64/amd64/db_interface.c
index 36455c96a3b..a6d95bc986d 100644
--- a/sys/arch/amd64/amd64/db_interface.c
+++ b/sys/arch/amd64/amd64/db_interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_interface.c,v 1.15 2008/10/03 21:57:25 weingart Exp $ */
+/* $OpenBSD: db_interface.c,v 1.16 2010/04/01 19:47:59 kettenis Exp $ */
/* $NetBSD: db_interface.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */
/*
@@ -83,7 +83,6 @@ void db_cpuinfo_cmd(db_expr_t, int, db_expr_t, char *);
void db_startproc_cmd(db_expr_t, int, db_expr_t, char *);
void db_stopproc_cmd(db_expr_t, int, db_expr_t, char *);
void db_ddbproc_cmd(db_expr_t, int, db_expr_t, char *);
-int db_cpuid2apic(int);
#endif
/*
@@ -162,19 +161,6 @@ kdb_trap(int type, int code, db_regs_t *regs)
#ifdef MULTIPROCESSOR
-int
-db_cpuid2apic(int id)
-{
- int apic;
-
- for (apic = 0; apic < MAXCPUS; apic++) {
- if (cpu_info[apic] != NULL &&
- CPU_INFO_UNIT(cpu_info[apic]) == id)
- return (apic);
- }
- return (-1);
-}
-
void
db_cpuinfo_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
@@ -212,20 +198,18 @@ db_cpuinfo_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
void
db_startproc_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
- int apic;
+ int i;
if (have_addr) {
- apic = db_cpuid2apic(addr);
- if (apic >= 0 && apic < MAXCPUS &&
- cpu_info[apic] != NULL && apic != cpu_number())
- db_startcpu(apic);
+ if (addr >= 0 && addr < MAXCPUS &&
+ cpu_info[addr] != NULL && addr != cpu_number())
+ db_startcpu(addr);
else
db_printf("Invalid cpu %d\n", (int)addr);
} else {
- for (apic = 0; apic < MAXCPUS; apic++) {
- if (cpu_info[apic] != NULL && apic != cpu_number()) {
- db_startcpu(apic);
- }
+ for (i = 0; i < MAXCPUS; i++) {
+ if (cpu_info[i] != NULL && i != cpu_number())
+ db_startcpu(i);
}
}
}
@@ -233,20 +217,18 @@ db_startproc_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
void
db_stopproc_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
- int apic;
+ int i;
if (have_addr) {
- apic = db_cpuid2apic(addr);
- if (apic >= 0 && apic < MAXCPUS &&
- cpu_info[apic] != NULL && apic != cpu_number())
- db_stopcpu(apic);
+ if (addr >= 0 && addr < MAXCPUS &&
+ cpu_info[addr] != NULL && addr != cpu_number())
+ db_stopcpu(addr);
else
db_printf("Invalid cpu %d\n", (int)addr);
} else {
- for (apic = 0; apic < MAXCPUS; apic++) {
- if (cpu_info[apic] != NULL && apic != cpu_number()) {
- db_stopcpu(apic);
- }
+ for (i = 0; i < MAXCPUS; i++) {
+ if (cpu_info[i] != NULL && i != cpu_number())
+ db_stopcpu(i);
}
}
}
@@ -254,14 +236,11 @@ db_stopproc_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
void
db_ddbproc_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
- int apic;
-
if (have_addr) {
- apic = db_cpuid2apic(addr);
- if (apic >= 0 && apic < MAXCPUS &&
- cpu_info[apic] != NULL && apic != cpu_number()) {
- db_stopcpu(apic);
- db_switch_to_cpu = apic;
+ if (addr >= 0 && addr < MAXCPUS &&
+ cpu_info[addr] != NULL && addr != cpu_number()) {
+ db_stopcpu(addr);
+ db_switch_to_cpu = addr;
db_switch_cpu = 1;
db_cmd_loop_done = 1;
} else {
diff --git a/sys/arch/amd64/amd64/genassym.cf b/sys/arch/amd64/amd64/genassym.cf
index 381b7d0438c..602221a923f 100644
--- a/sys/arch/amd64/amd64/genassym.cf
+++ b/sys/arch/amd64/amd64/genassym.cf
@@ -1,4 +1,4 @@
-# $OpenBSD: genassym.cf,v 1.21 2009/06/09 02:56:38 krw Exp $
+# $OpenBSD: genassym.cf,v 1.22 2010/04/01 19:47:59 kettenis Exp $
# Written by Artur Grabowski art@openbsd.org, Public Domain
include <sys/param.h>
@@ -94,6 +94,7 @@ member pcb_fpcpu
struct cpu_info
member CPU_INFO_SCRATCH ci_scratch
member CPU_INFO_SELF ci_self
+member CPU_INFO_APICID ci_apicid
member CPU_INFO_RESCHED ci_want_resched
member CPU_INFO_CURPROC ci_curproc
member CPU_INFO_CURPCB ci_curpcb
diff --git a/sys/arch/amd64/amd64/lapic.c b/sys/arch/amd64/amd64/lapic.c
index c1fab756130..2dbd9acb983 100644
--- a/sys/arch/amd64/amd64/lapic.c
+++ b/sys/arch/amd64/amd64/lapic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lapic.c,v 1.22 2009/08/10 17:04:37 deraadt Exp $ */
+/* $OpenBSD: lapic.c,v 1.23 2010/04/01 19:47:59 kettenis Exp $ */
/* $NetBSD: lapic.c,v 1.2 2003/05/08 01:04:35 fvdl Exp $ */
/*-
@@ -113,7 +113,7 @@ lapic_map(paddr_t lapic_base)
invlpg(va);
#ifdef MULTIPROCESSOR
- cpu_init_first(); /* catch up to changed cpu_number() */
+ cpu_init_first();
#endif
lapic_tpr = s;
diff --git a/sys/arch/amd64/amd64/mptramp.S b/sys/arch/amd64/amd64/mptramp.S
index 72b17773951..98d9f861f2d 100644
--- a/sys/arch/amd64/amd64/mptramp.S
+++ b/sys/arch/amd64/amd64/mptramp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mptramp.S,v 1.5 2008/06/26 05:42:09 ray Exp $ */
+/* $OpenBSD: mptramp.S,v 1.6 2010/04/01 19:47:59 kettenis Exp $ */
/* $NetBSD: mptramp.S,v 1.1 2003/04/26 18:39:30 fvdl Exp $ */
/*-
@@ -208,9 +208,15 @@ _TRMP_LABEL(mptramp_longmode)
_C_LABEL(cpu_spinup_trampoline_end): #end of code copied to MP_TRAMPOLINE
- movl _C_LABEL(local_apic)+LAPIC_ID,%ecx
- shrl $LAPIC_ID_SHIFT,%ecx
+ movl _C_LABEL(local_apic)+LAPIC_ID,%eax
+ shrl $LAPIC_ID_SHIFT,%eax
+ xorq %rcx,%rcx
+1:
movq _C_LABEL(cpu_info)(,%rcx,8),%rdi
+ incq %rcx
+ movl CPU_INFO_APICID(%rdi),%edx
+ cmpl %eax,%edx
+ jne 1b
movq CPU_INFO_IDLE_PCB(%rdi),%rsi