Use atomics to adjust ci_flags.

This commit is contained in:
ad 2007-12-02 19:33:31 +00:00
parent 0d78c993a2
commit 3ce0f72397
1 changed files with 21 additions and 21 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.c,v 1.8 2007/11/14 14:59:28 ad Exp $ */
/* $NetBSD: cpu.c,v 1.9 2007/12/02 19:33:31 ad Exp $ */
/*-
* Copyright (c) 2000, 2006, 2007 The NetBSD Foundation, Inc.
@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.8 2007/11/14 14:59:28 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.9 2007/12/02 19:33:31 ad Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@ -87,10 +87,11 @@ __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.8 2007/11/14 14:59:28 ad Exp $");
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/cpu.h>
#include <sys/atomic.h>
#include <uvm/uvm_extern.h>
#include <machine/cpu.h>
#include <machine/cpufunc.h>
#include <machine/cpuvar.h>
#include <machine/pmap.h>
@ -165,6 +166,7 @@ static void cpu_init_tss(struct i386tss *, void *, void *);
#endif
uint32_t cpus_attached = 0;
uint32_t cpus_running = 0;
extern char x86_64_doubleflt_stack[];
@ -175,8 +177,6 @@ extern char x86_64_doubleflt_stack[];
*/
struct cpu_info *cpu_info[X86_MAXPROCS] = { &cpu_info_primary, };
uint32_t cpus_running = 0;
void cpu_hatch(void *);
static void cpu_boot_secondary(struct cpu_info *ci);
static void cpu_start_secondary(struct cpu_info *ci);
@ -189,7 +189,7 @@ static void cpu_copy_trampoline(void);
* Called from lapic_boot_init() (from mpbios_scan()).
*/
void
cpu_init_first()
cpu_init_first(void)
{
int cpunum = lapic_cpu_number();
@ -328,7 +328,8 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
switch (caa->cpu_role) {
case CPU_ROLE_SP:
aprint_normal(": (uniprocessor)\n");
ci->ci_flags |= CPUF_PRESENT | CPUF_SP | CPUF_PRIMARY;
atomic_or_32(&ci->ci_flags,
CPUF_PRESENT | CPUF_SP | CPUF_PRIMARY);
cpu_intr_init(ci);
identifycpu(ci);
cpu_init(ci);
@ -339,7 +340,8 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
case CPU_ROLE_BP:
aprint_normal(": (boot processor)\n");
ci->ci_flags |= CPUF_PRESENT | CPUF_BSP | CPUF_PRIMARY;
atomic_or_32(&ci->ci_flags,
CPUF_PRESENT | CPUF_BSP | CPUF_PRIMARY);
cpu_intr_init(ci);
identifycpu(ci);
cpu_init(ci);
@ -411,8 +413,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
*/
void
cpu_init(ci)
struct cpu_info *ci;
cpu_init(struct cpu_info *ci)
{
/* configure the CPU if needed */
if (ci->cpu_setup != NULL)
@ -476,10 +477,10 @@ cpu_init(ci)
#endif /* i386 */
#endif /* MTRR */
#ifdef MULTIPROCESSOR
ci->ci_flags |= CPUF_RUNNING;
cpus_running |= ci->ci_cpumask;
#else
atomic_or_32(&ci->ci_flags, CPUF_RUNNING);
atomic_or_32(&cpus_running, ci->ci_cpumask);
#ifndef MULTIPROCESSOR
/* XXX */
x86_patch();
#endif
@ -564,7 +565,7 @@ cpu_start_secondary(ci)
#endif
mp_pdirpa = kpm->pm_pdirpa;
ci->ci_flags |= CPUF_AP;
atomic_or_32(&ci->ci_flags, CPUF_AP);
aprint_debug("%s: starting\n", ci->ci_dev->dv_xname);
@ -577,7 +578,7 @@ cpu_start_secondary(ci)
for (i = 100000; (!(ci->ci_flags & CPUF_PRESENT)) && i>0;i--) {
delay(10);
}
if (! (ci->ci_flags & CPUF_PRESENT)) {
if ((ci->ci_flags & CPUF_PRESENT) == 0) {
aprint_error("%s: failed to become ready\n",
ci->ci_dev->dv_xname);
#if defined(MPDEBUG) && defined(DDB)
@ -595,12 +596,11 @@ cpu_boot_secondary(ci)
{
int i;
ci->ci_flags |= CPUF_GO; /* XXX atomic */
atomic_or_32(&ci->ci_flags, CPUF_GO);
for (i = 100000; (!(ci->ci_flags & CPUF_RUNNING)) && i>0;i--) {
delay(10);
lapic_boot_timecount = lapic_get_timecount(NULL);
}
if (! (ci->ci_flags & CPUF_RUNNING)) {
if ((ci->ci_flags & CPUF_RUNNING) == 0) {
aprint_error("%s: failed to start\n", ci->ci_dev->dv_xname);
#if defined(MPDEBUG) && defined(DDB)
printf("dropping into debugger; continue from here to resume boot\n");
@ -629,7 +629,7 @@ cpu_hatch(void *v)
cpu_feature2 &= ci->ci_feature2_flags;
KDASSERT((ci->ci_flags & CPUF_PRESENT) == 0);
ci->ci_flags |= CPUF_PRESENT;
atomic_or_32(&ci->ci_flags, CPUF_PRESENT);
while ((ci->ci_flags & CPUF_GO) == 0) {
/* Don't use delay, boot CPU may be patching the text. */
for (i = 10000; i != 0; i--)