mp_startup.c revision 70f54ead78cbbb40e97bd3ff9f175c5c71783c3c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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>
#ifdef TRAPTRACE
#include <sys/traptrace.h>
#include <sys/bootconf.h>
#endif /* TRAPTRACE */
#include <sys/cpu_sgnblk_defs.h>
extern void cpu_intrq_setup(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
/*
* MP configurations may reserve additional interrupt request entries.
* intr_add_{div,max} can be modified to tune memory usage.
*/
size_t intr_add_max = 0;
/* intr_add_{pools,head,tail} calculated based on intr_add_{div,max} */
#ifdef DEBUG
#endif /* DEBUG */
#ifdef TRAPTRACE
/*
* This function bop allocs traptrace buffers for all cpus
* other than boot cpu.
*/
{
extern int max_ncpus;
if (max_ncpus == 1) {
return (base);
}
panic("traptrace_alloc: can't bop alloc");
}
ttrace_buf = vaddr;
}
#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 caddr_t cpu_startup;
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.
*/
void
setup_cpu_common(int cpuid)
{
#ifdef TRAPTRACE
int tt_index;
#endif /* TRAPTRACE */
extern void idle();
extern void init_intr_threads(struct cpu *);
#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;
}
/*
* initialize HV trap trace buffer for other cpus
*/
#endif /* TRAPTRACE */
/*
* 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.
*/
/*
* 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.
*/
/*
* Associate this CPU with a physical processor
*/
}
/*
* 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. */
/*
* Remove CPU from list of available CPUs.
*/
/*
* Clean up the interrupt pool.
*/
/*
* 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.
*/
#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.
*/
/*
* 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)
{
#ifdef TRAPTRACE
#endif
/* 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 CMT subsystem that the slave has started
*/
/*
* Now we are done with the startup thread, so free it up.
*/
thread_exit();
/*NOTREACHED*/
}
/*
* 4163850 changes the allocation method for cpu structs. cpu structs
* are dynamically allocated. This routine now determines if additional
* per-cpu intr_req entries need to be allocated.
*/
int
{
extern int niobus;
if (niobus > 1) {
/*
* Allocate additional intr_req entries if we have more than
* one io bus. The memory to allocate is calculated from four
* variables: niobus, max_ncpus, intr_add_div, and intr_add_max.
* Allocate multiple of INTR_POOL_SIZE bytes (512). Each cpu
* already reserves 512 bytes in its machcpu structure, so the
* worst case is (512 * (niobus - 1) * max_ncpus) add'l bytes.
*
* While niobus and max_ncpus reflect the h/w, the following
* may be tuned (before boot):
*
* intr_add_div - divisor for scaling the number of
* additional intr_req entries. use '1'
* for worst case memory, '2' for half,
* etc.
*
* intr_add_max - upper limit on bytes of memory to reserve
*/
/* tune memory usage by applying divisor and maximum */
if (intr_add_max == 0)
/* round down to multiple of (max_ncpus * INTR_POOL_SIZE) */
/* actually reserve the space */
if (intr_add_head == NULL)
return (-1);
#ifdef DEBUG
intr_add_tail = (struct intr_req *)
#endif /* DEBUG */
}
return (0);
}
extern void setup_cpu_common(int);
extern void common_startup_init(cpu_t *, int);
extern void cold_flag_set(int cpuid);
/*
* 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)) {
#ifdef MPSAS
/* just CPU 0 */
#else
#endif
}
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;
/*
* 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);
/*
* XXX: register_cpu_setup() callbacks should be called here
* with a new setup code, CPU_BOOT (or something).
*/
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();
}