use larger, allocated cpu stacks

This commit is contained in:
rsc 2007-09-27 19:32:43 +00:00
parent 0fe118f3f6
commit 4721271961
2 changed files with 16 additions and 23 deletions

35
main.c
View file

@ -6,13 +6,13 @@
#include "x86.h" #include "x86.h"
static void bootothers(void); static void bootothers(void);
static void mpmain(void) __attribute__((noreturn));
// Bootstrap processor starts running C code here. // Bootstrap processor starts running C code here.
int int
main(void) main(void)
{ {
int i; int bcpu, i;
static volatile int bcpu; // cannot be on stack
extern char edata[], end[]; extern char edata[], end[];
// clear BSS // clear BSS
@ -20,15 +20,10 @@ main(void)
// splhi() every processor during bootstrap. // splhi() every processor during bootstrap.
for(i=0; i<NCPU; i++) for(i=0; i<NCPU; i++)
cpus[i].nsplhi = 1; cpus[i].nsplhi = 1; // no interrupts during bootstrap
mp_init(); // collect info about this machine mp_init(); // collect info about this machine
bcpu = mp_bcpu(); bcpu = mp_bcpu();
// Switch to bootstrap processor's stack
asm volatile("movl %0, %%esp" : : "r" (cpus[bcpu].mpstack+MPSTACK-32));
asm volatile("movl %0, %%ebp" : : "r" (cpus[bcpu].mpstack+MPSTACK));
lapic_init(bcpu); lapic_init(bcpu);
cprintf("\ncpu%d: starting xv6\n\n", cpu()); cprintf("\ncpu%d: starting xv6\n\n", cpu());
@ -38,34 +33,34 @@ main(void)
ioapic_init(); // another interrupt controller ioapic_init(); // another interrupt controller
kinit(); // physical memory allocator kinit(); // physical memory allocator
tvinit(); // trap vectors tvinit(); // trap vectors
idtinit(); // interrupt descriptor table
fileinit(); // file table fileinit(); // file table
iinit(); // inode cache iinit(); // inode cache
setupsegs(0); // segments & TSS
console_init(); // I/O devices & their interrupts console_init(); // I/O devices & their interrupts
ide_init(); // disk ide_init(); // disk
bootothers(); // boot other CPUs
if(!ismp) if(!ismp)
timer_init(); // uniprocessor timer timer_init(); // uniprocessor timer
cprintf("ismp %d\n", ismp);
cprintf("userinit\n");
userinit(); // first user process userinit(); // first user process
// enable interrupts on this processor. // Allocate scheduler stacks and boot the other CPUs.
spllo(); for(i=0; i<ncpu; i++)
cpus[i].stack = kalloc(KSTACKSIZE);
bootothers();
cprintf("scheduler\n"); // Switch to our scheduler stack and continue with mpmain.
scheduler(); asm volatile("movl %0, %%esp" : : "r" (cpus[bcpu].stack+KSTACKSIZE));
mpmain();
} }
// Additional processors start here. // Additional processors start here.
static void static void
mpmain(void) mpmain(void)
{ {
cprintf("cpu%d: starting\n", cpu()); cprintf("cpu%d: mpmain\n", cpu());
idtinit(); idtinit();
lapic_init(cpu()); if(cpu() != mp_bcpu())
lapic_init(cpu());
setupsegs(0); setupsegs(0);
asm volatile("movl %0, %%ss" :: "r" (SEG_CPUSTACK << 3));
cpuid(0, 0, 0, 0, 0); // memory barrier cpuid(0, 0, 0, 0, 0); // memory barrier
cpus[cpu()].booted = 1; cpus[cpu()].booted = 1;
spllo(); spllo();
@ -89,7 +84,7 @@ bootothers(void)
continue; continue;
// Fill in %esp, %eip and start code on cpu. // Fill in %esp, %eip and start code on cpu.
*(void**)(code-4) = c->mpstack + MPSTACK; *(void**)(code-4) = c->stack + KSTACKSIZE;
*(void**)(code-8) = mpmain; *(void**)(code-8) = mpmain;
lapic_startap(c->apicid, (uint)code); lapic_startap(c->apicid, (uint)code);

4
proc.h
View file

@ -49,8 +49,6 @@ struct proc {
// fixed-size stack // fixed-size stack
// expandable heap // expandable heap
#define MPSTACK 512
// Per-CPU state // Per-CPU state
struct cpu { struct cpu {
uchar apicid; // Local APIC ID uchar apicid; // Local APIC ID
@ -58,7 +56,7 @@ struct cpu {
struct context context; // Switch here to enter scheduler struct context context; // Switch here to enter scheduler
struct taskstate ts; // Used by x86 to find stack for interrupt struct taskstate ts; // Used by x86 to find stack for interrupt
struct segdesc gdt[NSEGS]; // x86 global descriptor table struct segdesc gdt[NSEGS]; // x86 global descriptor table
char mpstack[MPSTACK]; // Per-CPU startup stack char *stack;
volatile int booted; // Has the CPU started? volatile int booted; // Has the CPU started?
int nsplhi; // Depth of splhi nesting. int nsplhi; // Depth of splhi nesting.
}; };