mp_startup.c revision 023e71de9e5670cebc23dd51162833661d3d2d3b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/sysmacros.h>
#include <sys/prom_plat.h>
#include <sys/prom_debug.h>
#include <vm/hat_sfmmu.h>
#include <vm/seg_kmem.h>
#include <sys/machsystm.h>
#include <sys/cpu_module.h>
#include <sys/traptrace.h>
#ifdef TRAPTRACE
#include <sys/bootconf.h>
#endif /* TRAPTRACE */
#include <sys/cpu_sgnblk_defs.h>
extern int cpu_intrq_setup(struct cpu *);
extern void cpu_intrq_cleanup(struct cpu *);
extern void cpu_intrq_register(struct cpu *);
#ifdef TRAPTRACE
#endif /* TRAPTRACE */
/* bit mask of cpus ready for x-calls, protected by cpu_lock */
/* bit mask used to communicate with cpus during bringup */
static cpuset_t proxy_ready_set;
static void slave_startup(void);
/*
* Defined in $KARCH/os/mach_mp_startup.c
*/
#pragma weak init_cpu_info
/*
* Amount of time (in milliseconds) we should wait before giving up on CPU
* initialization and assuming that the CPU we're trying to wake up is dead
* or out of control.
*/
#define CPU_WAKEUP_GRACE_MSEC 1000
#ifdef TRAPTRACE
/*
* This function sets traptrace buffers for all cpus
* other than boot cpu.
*/
calc_traptrace_sz(void)
{
}
#endif /* TRAPTRACE */
/*
* common slave cpu initialization code
*/
void
{
/*
* Allocate and initialize the startup thread for this CPU.
*/
/*
* Set state to TS_ONPROC since this thread will start running
* as soon as the CPU comes online.
*
* All the other fields of the thread structure are setup by
* thread_create().
*/
/*
* Setup thread to start in slave_startup.
*/
}
/*
* parametric flag setting functions. these routines set the cpu
* state just prior to releasing the slave cpu.
*/
void
cold_flag_set(int cpuid)
{
/*
* Add CPU_READY after the cpu_add_active() call
* to avoid pausing cp.
*/
}
static void
warm_flag_set(int cpuid)
{
/*
* warm start activates cpus into the OFFLINE state
*/
| CPU_OFFLINE | CPU_QUIESCED;
}
/*
* Internal cpu startup sequencer
* The sequence is as follows:
*
* MASTER SLAVE
* ------- ----------
* assume the kernel data is initialized
* clear the proxy bit
* start the slave cpu
* wait for the slave cpu to set the proxy
*
* the slave runs slave_startup and then sets the proxy
* the slave waits for the master to add slave to the ready set
*
* the master finishes the initialization and
* adds the slave to the ready set
*
* the slave exits the startup thread and is running
*/
void
{
extern void cpu_startup(int);
int timout;
/*
* Before we begin the dance, tell DTrace that we're about to start
* a CPU.
*/
if (dtrace_cpustart_init != NULL)
(*dtrace_cpustart_init)();
/* start the slave cpu */
if (prom_test("SUNW,start-cpu-by-cpuid") == 0) {
cpuid);
} else {
/* "by-cpuid" interface didn't exist. Do it the old way */
}
/* wait for the slave cpu to check in. */
break;
DELAY(1000);
}
if (timout == 0) {
}
/*
* The slave has started; we can tell DTrace that it's safe again.
*/
if (dtrace_cpustart_fini != NULL)
(*dtrace_cpustart_fini)();
/* run the master side of stick synchronization for the slave cpu */
/*
* deal with the cpu flags in a phase-specific manner
* for various reasons, this needs to run after the slave
* is checked in but before the slave is released.
*/
/* release the slave */
}
#ifdef TRAPTRACE
int trap_trace_inuse[NCPU];
#endif /* TRAPTRACE */
#define cpu_next_free cpu_prev
/*
* Routine to set up a CPU to prepare for starting it up.
*/
int
setup_cpu_common(int cpuid)
{
#ifdef TRAPTRACE
int tt_index;
#endif /* TRAPTRACE */
extern void idle();
int rval;
#ifdef TRAPTRACE
/*
* allocate a traptrace buffer for this CPU.
*/
if (!trap_tr0_inuse) {
trap_tr0_inuse = 1;
tt_index = -1;
} else {
if (!trap_trace_inuse[tt_index])
break;
}
#endif /* TRAPTRACE */
/*
* initialize hv traptrace buffer for this CPU
*/
/*
* Obtain pointer to the appropriate cpu structure.
*/
} else {
/*
* When dynamically allocating cpu structs,
* cpus is used as a pointer to a list of freed
* cpu structs.
*/
if (cpus) {
/* grab the first cpu struct on the free list */
if (cp->cpu_next_free)
else
}
}
/*
* Initialize ptl1_panic stack
*/
/*
* Initialize the dispatcher for this CPU.
*/
/*
* Bootstrap the CPU's PG data
*/
/*
* Now, initialize per-CPU idle thread for this CPU.
*/
/*
* Registering a thread in the callback table is usually
* done in the initialization code of the thread. In this
* case, we do it right after thread creation to avoid
* blocking idle thread while registering itself. It also
* avoids the possibility of reregistration in case a CPU
* restarts its idle thread.
*/
/*
* Initialize the interrupt threads for this CPU
*/
/*
* Add CPU to list of available CPUs.
* It'll be on the active list after it is started.
*/
/*
* Allocate and init cpu module private data structures,
* including scrubber.
*/
/*
* Initialize the CPUs physical ID cache, and processor groups
*/
return (rval);
}
/*
* Initialize MMU context domain information.
*/
return (0);
}
/*
* Routine to clean up a CPU after shutting it down.
*/
int
cleanup_cpu_common(int cpuid)
{
#ifdef TRAPTRACE
int i;
#endif /* TRAPTRACE */
/* Free cpu module private data structures, including scrubber. */
/* Free cpu ID string and brand string. */
if (cp->cpu_brandstr)
/*
* Remove CPU from list of available CPUs.
*/
/*
* Clean any machine specific interrupt states.
*/
/*
* At this point, the only threads bound to this CPU should be
* special per-cpu threads: it's idle thread, it's pause thread,
* and it's interrupt threads. Clean these up.
*/
/*
* Free the interrupt stack.
*/
/*
* Free hv traptrace buffer for this CPU.
*/
#ifdef TRAPTRACE
/*
* Free the traptrace buffer for this CPU.
*/
((i >= 0) && (i < (max_ncpus-1)))) {
/*
* This CPU got it's trap trace buffer from the
* boot-alloc'd bunch of them.
*/
trap_trace_inuse[i] = 0;
trap_tr0_inuse = 0;
} else {
cpuid);
}
#endif /* TRAPTRACE */
/*
* There is a race condition with mutex_vector_enter() which
* caches a cpu pointer. The race is detected by checking cpu_next.
*/
if (CPU_MMU_CTXP(cp))
/*
* Place the freed cpu structure on the list of freed cpus.
*/
if (cpus) {
}
else
}
return (0);
}
/*
* This routine is used to start a previously powered off processor.
* Note that restarted cpus are initialized into the offline state.
*/
void
restart_other_cpu(int cpuid)
{
extern void idle();
/*
* Obtain pointer to the appropriate cpu structure.
*/
/*
* idle thread t_lock is held when the idle thread is suspended.
* Manually unlock the t_lock of idle loop so that we can resume
* the suspended idle thread.
* Also adjust the PC of idle thread for re-retry.
*/
/*
* restart the cpu now
*/
start_cpus();
/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
cpuid);
}
/*
* Startup function executed on 'other' CPUs. This is the first
* C function after cpu_start sets up the cpu registers.
*/
static void
slave_startup(void)
{
/* acknowledge that we are done with initialization */
/* synchronize STICK */
/*
* the slave will wait here forever -- assuming that the master
* will get back to us. if it doesn't we've got bigger problems
* than a master not replying to this slave.
* the small delay improves the slave's responsiveness to the
* master's ack and decreases the time window between master and
* slave operations.
*/
DELAY(1);
/* enable interrupts */
(void) spl0();
/*
* Signature block update to indicate that this CPU is in OS now.
* This needs to be done after the PIL is lowered since on
* some platforms the update code may block.
*/
/*
* to finish configuring this CPU before proceeding to thread_exit().
*/
DELAY(1);
/*
* Initialize CPC CPU state.
*/
/*
* Notify the PG subsystem that the CPU has started
*/
/*
* Now we are done with the startup thread, so free it up.
*/
thread_exit();
/*NOTREACHED*/
}
/*
* can be used during debugging to control which processors are brought
* online at boot time. The variable represents a bitmap of the id's
* of the processors that will be brought online. The initialization
* of this variable depends on the type of cpuset_t, which varies
* depending on the number of processors supported (see cpuvar.h).
*/
/*
* Generic start-all cpus entry. Typically used during cold initialization.
* Note that cold start cpus are initialized into the online state.
*/
/*ARGSUSED*/
void
start_other_cpus(int flag)
{
int cpuid;
extern void idlestop_init(void);
int bootcpu;
/*
* Check if cpu_bringup_set has been explicitly set before
* initializing it.
*/
if (CPUSET_ISNULL(cpu_bringup_set)) {
}
if (&cpu_feature_init)
/*
* Initialize CPC.
*/
kcpc_hw_init();
/*
* Initialize our own cpu_info.
*/
/*
* Initialize CPU 0 cpu module private data area, including scrubber.
*/
/*
* perform such initialization as is needed
* to be able to take CPUs on- and off-line.
*/
xc_init(); /* initialize processor crosscalls */
if (!use_mp) {
return;
}
/*
* should we be initializing this cpu?
*/
bootcpu = getprocessorid();
/*
* launch all the slave cpus now
*/
continue;
"of cpu_bringup_set, adding it");
}
continue;
}
continue;
if (setup_cpu_common(cpuid)) {
}
/*
* Because slave_startup() gets fired off after init()
* starts, we can't use the '?' trick to do 'boot -v'
* printing - so we always direct the 'cpu .. online'
* messages to the log.
*/
cpuid);
if (dtrace_cpu_init != NULL)
(*dtrace_cpu_init)(cpuid);
}
/*
* since all the cpus are online now, redistribute interrupts to them.
*/
/*
* Start the Ecache scrubber. Must be done after all calls to
* cpu_init_private for every cpu (including CPU 0).
*/
if (&cpu_mp_init)
cpu_mp_init();
}