From 80db8bc5ef17347e11d7d2b0c7b24f57cc3df8c1 Mon Sep 17 00:00:00 2001 From: Joe Talbott Date: Mon, 25 Jun 2007 10:47:32 -0400 Subject: [PATCH] Convert to lwp_create versus pthread_create since sched.h isn't easily available. This version compiles and doesn't seem to leave the vkernel process in an unkillable state. --- sys/platform/vkernel/i386/mp.c | 43 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/sys/platform/vkernel/i386/mp.c b/sys/platform/vkernel/i386/mp.c index 3e706e6b27..6be43fb342 100644 --- a/sys/platform/vkernel/i386/mp.c +++ b/sys/platform/vkernel/i386/mp.c @@ -54,13 +54,15 @@ #include #include +#if 0 #include +#endif #include extern pt_entry_t *KPTphys; volatile u_int stopped_cpus; -cpumask_t smp_active_mask = 1; /* which cpus are ready for IPIs etc? */ +cpumask_t smp_active_mask = 0; /* which cpus are ready for IPIs etc? */ static int boot_address; static cpumask_t smp_startup_mask = 1; /* which cpus have been started */ int mp_naps; /* # of Applications processors */ @@ -78,7 +80,7 @@ static int bootAP; /* XXX these need to go into the appropriate header file */ static int start_all_aps(u_int); void init_secondary(void); -void *start_ap(void *); +void start_ap(void *); #if 0 u_int mp_lock; @@ -107,7 +109,7 @@ ap_finish(void) smp_active_mask, smp_startup_mask, ncpus_mask); printf("ncpus2_mask: %d, ncpus_fit_mask: %d\n", ncpus2_mask, ncpus_fit_mask); - while (smp_startup_mask != ncpus_mask || smp_active_mask != smp_startup_mask) { + while (smp_active_mask != smp_startup_mask) { /* kprintf("smp_active_mask: %d, smp_startup_mask: %d\n", smp_active_mask, smp_startup_mask); @@ -125,7 +127,7 @@ ap_finish(void) SYSINIT(finishsmp, SI_BOOT2_FINISH_SMP, SI_ORDER_FIRST, ap_finish, NULL) -void * +void start_ap(void *arg) { int ap_id = *(int *)arg; @@ -148,11 +150,16 @@ start_ap(void *arg) */ bootstrap_idle(); +#if 0 return(NULL); /* NOTREACHED */ +#endif } /* storage for AP thread IDs */ +#if 0 pthread_t ap_tids[MAXCPU]; +#endif +lwpid_t ap_tids[MAXCPU]; void mp_start(void) @@ -384,11 +391,12 @@ static int start_all_aps(u_int boot_addr) { int x, i, count; + int *arg; struct mdglobaldata *gd; struct privatespace *ps; vm_page_t m; vm_offset_t va; - int *arg; + struct lwp_params params; /* store the mappings so we can populate gd_CMAP[0-2] and gd_PMAP3 */ vpte_t *SMPpt2[4]; @@ -407,7 +415,7 @@ start_all_aps(u_int boot_addr) SMPpt2[count] = pmap_kpte(va); } - for (i = 0; i < sizeof(CPU_prvspace[0].idlestack); i += PAGE_SIZE) { + for (i = 0; i < sizeof(CPU_prvspace[x].idlestack); i += PAGE_SIZE) { va =(vm_offset_t)&CPU_prvspace[x].idlestack + i; m = vm_page_alloc(&kernel_object, va, VM_ALLOC_SYSTEM); pmap_kenter_quick(va, m->phys_addr); @@ -494,17 +502,23 @@ start_all_aps(u_int boot_addr) * Setup the AP's lwp, this is the 'cpu' */ arg = (int *)kmem_alloc(&kernel_map, sizeof(int)); - bzero(arg, sizeof(int)); *arg = x; -#if 0 - arg2 = x; + + bzero(¶ms, sizeof(params)); params.func = start_ap; - params.arg = &arg2; - params.stack = &CPU_prvspace[x].idlestack; - params.tid1 = &ap_tids[x]; - params.tid2 = &ap_tids[x]; + params.arg = arg; + params.stack = &CPU_prvspace[x].idlestack + sizeof(CPU_prvspace[x].idlestack); + params.stack = bootSTK; + /*params.tid1 = &ap_tids[x];*/ + params.tid1 = NULL; lwp_create(¶ms); -#endif + + /* XXX hack, sleep for a second to let the APs start up */ + sleep(1); + + /* set cpu0 active so the ap_finish can run*/ + smp_active_mask |= 1; +#if 0 kprintf("arg: %p, value = %d\n", arg, *arg); pthread_create(&ap_tids[x], NULL, start_ap, arg); kprintf("smp_active_mask: %d, smp_startup_mask: %d\n", @@ -517,6 +531,7 @@ start_all_aps(u_int boot_addr) cpu_lfence(); /* XXX spin until the AP has started */ kprintf("2 smp_startup_mask: %d, (1 << x): %d, smp_startup_mask & (1 << x): %d\n", smp_startup_mask, (1 << x),smp_startup_mask & (1 << x)); +#endif } return(ncpus - 1); -- 2.11.4.GIT