git: 9front

Download patch

ref: 4d8fb1ac11dd865127302828e8447d18f84c0cdf
parent: 2c389cefec9f0bb96293417055533e839c4ec7bc
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Jan 11 01:47:52 EST 2016

pc/pc64: bring up ap's one after another, use idlehands() while waiting for thunderbirdsarego

when testing in qemu, launching each ap became slower and slower
because all the ap's where spinning in syncclock() waiting for
cpu0 to update its mach0->tscticks, which happens only much later
after all cpu's have been started up.

now we wait for each cpu to do its timer callibration and
manually update our tscticks while we wait and each cpu will
not spin but halt while waiting for active.thunderbirdsarego.
this reduces the system load and noise for timer callibration
and makes the mp startup linear with regard to the number of
cores.

--- a/sys/src/9/pc/devarch.c
+++ b/sys/src/9/pc/devarch.c
@@ -783,7 +783,6 @@
 			wrmsr(0x10, 0);
 	}
 
-
 	/*
 	 *  use i8253 to guess our cpu speed
 	 */
--- a/sys/src/9/pc/mp.c
+++ b/sys/src/9/pc/mp.c
@@ -196,10 +196,8 @@
 		ncpu = MAXMACH;
 	memmove((void*)APBOOTSTRAP, apbootstrap, sizeof(apbootstrap));
 	for(i=0; i<nelem(mpapic); i++){
-		if((apic = mpapic[i]) == nil)
+		if((apic = mpapic[i]) == nil || apic->machno == 0 || apic->machno >= MAXMACH)
 			continue;
-		if(apic->machno >= MAXMACH)
-			continue;
 		if(ncpu <= 1)
 			break;
 		if((apic->flags & (PcmpBP|PcmpEN)) == PcmpEN){
@@ -206,6 +204,17 @@
 			mpstartap(apic);
 			conf.nmach++;
 			ncpu--;
+
+			if(!apic->online){
+				print("LAPIC%d: cpu%d did not startup\n", i, apic->machno);
+				continue;
+			}
+
+			/* update tscticks for ap's syncclock() */
+			while(!active.machs[apic->machno]){
+				if(arch->fastclock == tscticks)
+					cycles(&m->tscticks);
+			}
 		}
 	}
 
--- a/sys/src/9/pc/squidboy.c
+++ b/sys/src/9/pc/squidboy.c
@@ -34,7 +34,7 @@
 	unlock(&active);
 
 	while(!active.thunderbirdsarego)
-		microdelay(100);
+		idlehands();
 
 	schedinit();
 }
--- a/sys/src/9/pc64/mem.h
+++ b/sys/src/9/pc64/mem.h
@@ -28,7 +28,7 @@
 #define	BLOCKALIGN	8
 #define	FPalign		16
 
-#define	MAXMACH		64			/* max # cpus system can run */
+#define	MAXMACH		128			/* max # cpus system can run */
 
 #define KSTACK		(16*KiB)		/* Size of Proc kernel stack */
 
--- a/sys/src/9/pc64/squidboy.c
+++ b/sys/src/9/pc64/squidboy.c
@@ -15,6 +15,7 @@
 	mmuinit();
 	cpuidentify();
 	cpuidprint();
+
 	apic->online = 1;
 	coherence();
 
@@ -28,7 +29,7 @@
 	unlock(&active);
 
 	while(!active.thunderbirdsarego)
-		microdelay(100);
+		idlehands();
 
 	schedinit();
 }
--