From 057f071888b90e68a28d10736389cf27095618aa Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 2 Jul 2007 03:44:12 +0000 Subject: [PATCH] Increase SMP_MAXCPU to 31. Can't do 32 (boo hoo!) because spinlocks need a bit in the cpumask. Add DELAY()'s (usleep()'s) in the AP startup code where we spin on the MP lock. This greatly improves startup speed when you specify 31 cpus. Fix a bug in the kqueue interrupt init. The kqueue code was not registering its interrupt soon enough which could cause the timer to stop generating interrupts. --- sys/cpu/i386/include/param.h | 6 +++++- sys/platform/vkernel/i386/mp.c | 18 ++++++++++-------- sys/platform/vkernel/include/param.h | 11 ++++++++++- sys/platform/vkernel/platform/init.c | 18 ++++++++++++------ sys/platform/vkernel/platform/kqueue.c | 5 ++++- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/sys/cpu/i386/include/param.h b/sys/cpu/i386/include/param.h index c4a37a3f2b..8165c9128b 100644 --- a/sys/cpu/i386/include/param.h +++ b/sys/cpu/i386/include/param.h @@ -35,7 +35,7 @@ * * from: @(#)param.h 5.8 (Berkeley) 6/28/91 * $FreeBSD: src/sys/i386/include/param.h,v 1.54.2.8 2002/08/31 21:15:55 dillon Exp $ - * $DragonFly: src/sys/cpu/i386/include/param.h,v 1.13 2007/01/19 07:23:42 dillon Exp $ + * $DragonFly: src/sys/cpu/i386/include/param.h,v 1.14 2007/07/02 03:44:08 dillon Exp $ */ #ifndef _CPU_PARAM_H_ @@ -89,8 +89,12 @@ /* * Use SMP_MAXCPU instead of MAXCPU for structures that are intended to * remain compatible between UP and SMP builds. + * + * NOTE: Max supported cpus is 32 because we use 32 bit cpu masks. */ +#ifndef SMP_MAXCPU #define SMP_MAXCPU 16 +#endif #ifdef SMP #define MAXCPU SMP_MAXCPU #else diff --git a/sys/platform/vkernel/i386/mp.c b/sys/platform/vkernel/i386/mp.c index 9f24de1ab6..2f07611072 100644 --- a/sys/platform/vkernel/i386/mp.c +++ b/sys/platform/vkernel/i386/mp.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/platform/vkernel/i386/mp.c,v 1.4 2007/07/02 02:37:03 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/mp.c,v 1.5 2007/07/02 03:44:09 dillon Exp $ */ @@ -112,11 +112,13 @@ ap_finish(void) * of 'other' CPUs. */ rel_mplock(); - while (smp_active_mask != smp_startup_mask) + while (smp_active_mask != smp_startup_mask) { + DELAY(100000); cpu_lfence(); + } while (try_mplock() == 0) - ; + DELAY(100000); if (bootverbose) kprintf("Active CPU Mask: %08x\n", smp_active_mask); } @@ -301,10 +303,11 @@ ap_init(void) while (mp_finish == 0) { cpu_lfence(); + DELAY(500000); } ++curthread->td_mpcount; while (cpu_try_mplock() == 0) - ; + DELAY(100000); /* BSP may have changed PTD while we're waiting for the lock */ cpu_invltlb(); @@ -443,11 +446,10 @@ start_all_aps(u_int boot_addr) */ pthread_create(&ap_tids[x], NULL, start_ap, NULL); - while((smp_startup_mask & (1 << x)) == 0) + while((smp_startup_mask & (1 << x)) == 0) { cpu_lfence(); /* XXX spin until the AP has started */ - - /* XXX hack, sleep for a second to let the APs start up */ - sleep(1); + DELAY(1000); + } } return(ncpus - 1); diff --git a/sys/platform/vkernel/include/param.h b/sys/platform/vkernel/include/param.h index f063c4018b..9daed567b4 100644 --- a/sys/platform/vkernel/include/param.h +++ b/sys/platform/vkernel/include/param.h @@ -1,5 +1,5 @@ /* - * $DragonFly: src/sys/platform/vkernel/include/param.h,v 1.1 2007/01/19 07:23:43 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/include/param.h,v 1.2 2007/07/02 03:44:10 dillon Exp $ */ #ifndef _MACHINE_PARAM_H_ @@ -20,6 +20,15 @@ #endif +/* + * This is kinda silly but why not? We use a 32 bit bitmask so 31 is + * the most we can have. We use the msb bit for other purposes in the + * spinlock code so we can't have 32. + */ +#ifndef SMP_MAXCPU +#define SMP_MAXCPU 31 +#endif + #include #endif diff --git a/sys/platform/vkernel/platform/init.c b/sys/platform/vkernel/platform/init.c index a209f7a887..51bff71f69 100644 --- a/sys/platform/vkernel/platform/init.c +++ b/sys/platform/vkernel/platform/init.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/platform/vkernel/platform/init.c,v 1.41 2007/07/02 02:37:05 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/platform/init.c,v 1.42 2007/07/02 03:44:12 dillon Exp $ */ #include @@ -65,6 +65,7 @@ #include #include +#include #include #include #include @@ -111,7 +112,7 @@ static void init_disk(char *diskExp[], int diskFileNum, enum vkdisk_type type); static void init_netif(char *netifExp[], int netifFileNum); static void writepid( void ); static void cleanpid( void ); -static void usage(const char *str); +static void usage(const char *ctl, ...); static int save_ac; static char **save_av; @@ -214,8 +215,8 @@ main(int ac, char **av) */ #ifdef SMP optcpus = strtol(optarg, NULL, 0); - if (optcpus < 1 || optcpus > 32) - usage("Bad ncpus, valid range is 1-32"); + if (optcpus < 1 || optcpus > MAXCPU) + usage("Bad ncpus, valid range is 1-%d", MAXCPU); #else if (strtol(optarg, NULL, 0) != 1) { usage("You built a UP vkernel, only 1 cpu!"); @@ -1096,9 +1097,14 @@ cleanpid( void ) static void -usage(const char *str) +usage(const char *ctl, ...) { - fprintf(stderr, "%s\n", str); + va_list va; + + va_start(va, ctl); + vfprintf(stderr, ctl, va); + va_end(va); + fprintf(stderr, "\n"); exit(1); } diff --git a/sys/platform/vkernel/platform/kqueue.c b/sys/platform/vkernel/platform/kqueue.c index 2b52a08ac7..267c96a7fa 100644 --- a/sys/platform/vkernel/platform/kqueue.c +++ b/sys/platform/vkernel/platform/kqueue.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/platform/vkernel/platform/kqueue.c,v 1.5 2007/07/01 02:51:45 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/platform/kqueue.c,v 1.6 2007/07/02 03:44:12 dillon Exp $ */ #include @@ -134,6 +134,9 @@ kqueue_add_timer(void (*func)(void *, struct intrframe *), void *data) { struct kqueue_info *info; + if (VIntr1 == NULL) + VIntr1 = register_int(1, kqueue_intr, NULL, "kqueue", NULL, 0); + info = kmalloc(sizeof(*info), M_DEVBUF, M_ZERO|M_INTWAIT); info->func = func; info->data = data; -- 2.41.0