shithub: riscv

Download patch

ref: 41383ad0120630edd42c5c897a287e2f9d9161b4
parent: dd8908cff003135095996d2b0b5ea250c615a0e2
author: cinap_lenrek <[email protected]>
date: Tue Jan 5 00:32:40 EST 2016

kernel: change active.machs from bitmap to char array to support up to 64 cpus on pc64

--- a/sys/src/9/alphapc/dat.h
+++ b/sys/src/9/alphapc/dat.h
@@ -184,8 +184,8 @@
 struct
 {
 	Lock;
-	short	machs;
-	short	exiting;
+	char	machs[MAXMACH];
+	int	exiting;
 }active;
 
 /*
--- a/sys/src/9/alphapc/main.c
+++ b/sys/src/9/alphapc/main.c
@@ -156,7 +156,7 @@
 	m->machno = n;
 
 	active.exiting = 0;
-	active.machs = 1;
+	active.machs[0] = 1;
 
 	cpu = (Hwcpu*) ((ulong)hwrpb + hwrpb->cpuoff + n*hwrpb->cpulen);
 	cpu->state &= ~Cpubootinprog;
--- a/sys/src/9/alphapc/trap.c
+++ b/sys/src/9/alphapc/trap.c
@@ -261,8 +261,8 @@
 		 */
 		iprint("cpu%d: spurious interrupt %d, last %d",
 			m->machno, vno-VectorPIC, m->lastintr);
-		for(i = 0; i < 32; i++){
-			if(!(active.machs & (1<<i)))
+		for(i = 0; i < MAXMACH; i++){
+			if(active.machs[i] == 0)
 				continue;
 			mach = MACHP(i);
 			if(m->machno == mach->machno)
--- a/sys/src/9/bcm/dat.h
+++ b/sys/src/9/bcm/dat.h
@@ -223,7 +223,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	exiting;		/* shutdown */
 }active;
 
--- a/sys/src/9/bcm/main.c
+++ b/sys/src/9/bcm/main.c
@@ -199,7 +199,7 @@
 
 	conf.nmach = 1;
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 
 	up = nil;
--- a/sys/src/9/bitsy/dat.h
+++ b/sys/src/9/bitsy/dat.h
@@ -178,7 +178,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	exiting;		/* shutdown */
 }active;
 
--- a/sys/src/9/bitsy/main.c
+++ b/sys/src/9/bitsy/main.c
@@ -26,7 +26,7 @@
 	memset(m, 0, sizeof(Mach));
 	m->ticks = 1;
 
-	active.machs = 1;
+	active.machs[0] = 1;
 
 	rs232power(1);
 	quotefmtinstall();
--- a/sys/src/9/kw/dat.h
+++ b/sys/src/9/kw/dat.h
@@ -194,7 +194,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	exiting;		/* shutdown */
 }active;
 
--- a/sys/src/9/kw/main.c
+++ b/sys/src/9/kw/main.c
@@ -349,7 +349,7 @@
 
 	conf.nmach = 1;
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 
 	up = nil;
--- a/sys/src/9/mtx/dat.h
+++ b/sys/src/9/mtx/dat.h
@@ -181,8 +181,8 @@
 struct
 {
 	Lock;
-	short	machs;
-	short	exiting;
+	char	machs[MAXMACH];
+	int	exiting;
 }active;
 
 /*
--- a/sys/src/9/mtx/main.c
+++ b/sys/src/9/mtx/main.c
@@ -59,7 +59,7 @@
 	/* turn on caches */
 	puthid0(gethid0() | BIT(16) | BIT(17));
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 }
 
--- a/sys/src/9/omap/dat.h
+++ b/sys/src/9/omap/dat.h
@@ -216,7 +216,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	exiting;		/* shutdown */
 }active;
 
--- a/sys/src/9/omap/main.c
+++ b/sys/src/9/omap/main.c
@@ -295,7 +295,7 @@
 
 	conf.nmach = 1;
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 
 	up = nil;
--- a/sys/src/9/pc/dat.h
+++ b/sys/src/9/pc/dat.h
@@ -270,7 +270,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	exiting;		/* shutdown */
 	int	thunderbirdsarego;	/* lets the added processors continue to schedinit */
 }active;
--- a/sys/src/9/pc/main.c
+++ b/sys/src/9/pc/main.c
@@ -181,7 +181,7 @@
 
 	machinit();
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 }
 
--- a/sys/src/9/pc/mmu.c
+++ b/sys/src/9/pc/mmu.c
@@ -685,7 +685,7 @@
 	for(i=0; i<conf.nmach; i++){
 		nm = MACHP(i);
 		if(nm != m)
-			while((active.machs&(1<<nm->machno)) && nm->flushmmu)
+			while(active.machs[nm->machno] && nm->flushmmu)
 				;
 	}
 }
--- a/sys/src/9/pc/mp.c
+++ b/sys/src/9/pc/mp.c
@@ -198,6 +198,8 @@
 	for(i=0; i<nelem(mpapic); i++){
 		if((apic = mpapic[i]) == nil)
 			continue;
+		if(apic->machno >= MAXMACH)
+			continue;
 		if(ncpu <= 1)
 			break;
 		if((apic->flags & (PcmpBP|PcmpEN)) == PcmpEN){
@@ -574,7 +576,7 @@
 		for(;;) idle();
 	}
 
-	print("mpshutdown: active = %#8.8ux\n", active.machs);
+	print("mpshutdown\n");
 	delay(1000);
 	splhi();
 
--- a/sys/src/9/pc/squidboy.c
+++ b/sys/src/9/pc/squidboy.c
@@ -30,7 +30,7 @@
 	fpoff();
 
 	lock(&active);
-	active.machs |= 1<<m->machno;
+	active.machs[m->machno] = 1;
 	unlock(&active);
 
 	while(!active.thunderbirdsarego)
--- a/sys/src/9/pc/trap.c
+++ b/sys/src/9/pc/trap.c
@@ -400,8 +400,8 @@
 		if(0)print("cpu%d: spurious interrupt %d, last %d\n",
 			m->machno, vno, m->lastintr);
 		if(0)if(conf.nmach > 1){
-			for(i = 0; i < 32; i++){
-				if(!(active.machs & (1<<i)))
+			for(i = 0; i < MAXMACH; i++){
+				if(active.machs[i] == 0)
 					continue;
 				mach = MACHP(i);
 				if(m->machno == mach->machno)
--- a/sys/src/9/pc64/dat.h
+++ b/sys/src/9/pc64/dat.h
@@ -233,7 +233,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* bitmap of active CPUs */
 	int	exiting;		/* shutdown */
 	int	thunderbirdsarego;	/* lets the added processors continue to schedinit */
 }active;
--- a/sys/src/9/pc64/main.c
+++ b/sys/src/9/pc64/main.c
@@ -326,7 +326,7 @@
 
 	machinit();
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 }
 
--- 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		32			/* max # cpus system can run */
+#define	MAXMACH		64			/* 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
@@ -24,7 +24,7 @@
 	timersinit();
 
 	lock(&active);
-	active.machs |= 1<<m->machno;
+	active.machs[m->machno] = 1;
 	unlock(&active);
 
 	while(!active.thunderbirdsarego)
--- a/sys/src/9/pc64/trap.c
+++ b/sys/src/9/pc64/trap.c
@@ -394,8 +394,8 @@
 		if(0)print("cpu%d: spurious interrupt %d, last %d\n",
 			m->machno, vno, m->lastintr);
 		if(0)if(conf.nmach > 1){
-			for(i = 0; i < 32; i++){
-				if(!(active.machs & (1<<i)))
+			for(i = 0; i < MAXMACH; i++){
+				if(active.machs[i] == 0)
 					continue;
 				mach = MACHP(i);
 				if(m->machno == mach->machno)
--- a/sys/src/9/port/devcons.c
+++ b/sys/src/9/port/devcons.c
@@ -568,8 +568,8 @@
 	case Qsysstat:
 		b = smalloc(conf.nmach*(NUMSIZE*11+1) + 1);	/* +1 for NUL */
 		bp = b;
-		for(id = 0; id < 32; id++) {
-			if(active.machs & (1<<id)) {
+		for(id = 0; id < MAXMACH; id++) {
+			if(active.machs[id]) {
 				mp = MACHP(id);
 				readnum(0, bp, NUMSIZE, id, NUMSIZE);
 				bp += NUMSIZE;
@@ -767,8 +767,8 @@
 		break;
 
 	case Qsysstat:
-		for(id = 0; id < 32; id++) {
-			if(active.machs & (1<<id)) {
+		for(id = 0; id < MAXMACH; id++) {
+			if(active.machs[id]) {
 				mp = MACHP(id);
 				mp->cs = 0;
 				mp->intr = 0;
@@ -1051,8 +1051,8 @@
 	int ms, once;
 
 	lock(&active);
-	once = active.machs & (1<<m->machno);
-	active.machs &= ~(1<<m->machno);
+	once = active.machs[m->machno];
+	active.machs[m->machno] = 0;
 	active.exiting = 1;
 	unlock(&active);
 
@@ -1063,7 +1063,7 @@
 	spllo();
 	for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
 		delay(TK2MS(2));
-		if(active.machs == 0 && consactive() == 0)
+		if(memchr(active.machs, 1, MAXMACH) == nil && consactive() == 0)
 			break;
 	}
 }
--- a/sys/src/9/port/portclock.c
+++ b/sys/src/9/port/portclock.c
@@ -145,7 +145,7 @@
 	if(kproftimer != nil)
 		kproftimer(ur->pc);
 
-	if((active.machs&(1<<m->machno)) == 0)
+	if(active.machs[m->machno] == 0)
 		return;
 
 	if(active.exiting)
--- a/sys/src/9/ppc/dat.h
+++ b/sys/src/9/ppc/dat.h
@@ -189,8 +189,8 @@
 struct
 {
 	Lock;
-	short	machs;
-	short	exiting;
+	char	machs[MAXMACH];
+	int	exiting;
 }active;
 
 /*
--- a/sys/src/9/ppc/m8260.c
+++ b/sys/src/9/ppc/m8260.c
@@ -214,7 +214,7 @@
 	vco		198
 */
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 
 	putmsr(getmsr() | MSR_ME);
--- a/sys/src/9/ppc/msaturn.c
+++ b/sys/src/9/ppc/msaturn.c
@@ -140,7 +140,7 @@
 		m->cpuhz = 200000000;		/* 750FX? */
 	m->cyclefreq = m->bushz / 4;
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 
 	putmsr(getmsr() | MSR_ME);
--- a/sys/src/9/sgi/dat.h
+++ b/sys/src/9/sgi/dat.h
@@ -204,7 +204,7 @@
 struct
 {
 	Lock;
-	long	machs;		/* bitmap of processors */
+	char	machs[MAXMACH];		/* active cpus */
 	short	exiting;
 }active;
 
--- a/sys/src/9/sgi/main.c
+++ b/sys/src/9/sgi/main.c
@@ -172,7 +172,7 @@
 	confinit();
 	machinit();			/* calls clockinit */
 	active.exiting = 0;
-	active.machs = 1;
+	active.machs[0] = 1;
 	print("\nPlan 9\n");
 
 	kmapinit();
--- a/sys/src/9/teg2/archtegra.c
+++ b/sys/src/9/teg2/archtegra.c
@@ -676,7 +676,7 @@
 	Power *pwr;
 
 	up = nil;
-	if (active.machs & (1<<m->machno)) {
+	if (active.machs[m->machno]) {
 		serialputc('?');
 		serialputc('r');
 		panic("cpu%d: resetting after start", m->machno);
--- a/sys/src/9/teg2/dat.h
+++ b/sys/src/9/teg2/dat.h
@@ -246,7 +246,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	wfi;			/* bitmap of CPUs in WFI state */
 	int	stopped;		/* bitmap of CPUs stopped */
 	int	exiting;		/* shutdown */
--- a/sys/src/9/teg2/main.c
+++ b/sys/src/9/teg2/main.c
@@ -208,13 +208,10 @@
 void
 machon(uint cpu)
 {
-	ulong cpubit;
-
-	cpubit = 1 << cpu;
 	lock(&active);
-	if ((active.machs & cpubit) == 0) {	/* currently off? */
+	if (active.machs[cpu] == 0) {	/* currently off? */
+		active.machs[cpu] = 1;
 		conf.nmach++;
-		active.machs |= cpubit;
 	}
 	unlock(&active);
 }
@@ -223,13 +220,10 @@
 void
 machoff(uint cpu)
 {
-	ulong cpubit;
-
-	cpubit = 1 << cpu;
 	lock(&active);
-	if (active.machs & cpubit) {		/* currently on? */
+	if (active.machs[cpu]) {		/* currently on? */
+		active.machs[cpu] = 0;
 		conf.nmach--;
-		active.machs &= ~cpubit;
 	}
 	unlock(&active);
 }
--- a/sys/src/9/xen/main.c
+++ b/sys/src/9/xen/main.c
@@ -121,7 +121,7 @@
 
 	machinit();
 
-	active.machs = 1;
+	active.machs[0] = 1;
 	active.exiting = 0;
 }
 
--- a/sys/src/9/xen/trap.c
+++ b/sys/src/9/xen/trap.c
@@ -393,8 +393,8 @@
 		iprint("cpu%d: spurious interrupt %d, last %d\n",
 			m->machno, vno, m->lastintr);
 		if(0)if(conf.nmach > 1){
-			for(i = 0; i < 32; i++){
-				if(!(active.machs & (1<<i)))
+			for(i = 0; i < MAXMACH; i++){
+				if(active.machs[i] == 0)
 					continue;
 				mach = MACHP(i);
 				if(m->machno == mach->machno)
--- a/sys/src/9/zynq/dat.h
+++ b/sys/src/9/zynq/dat.h
@@ -175,7 +175,7 @@
 struct
 {
 	Lock;
-	int	machs;			/* bitmap of active CPUs */
+	char	machs[MAXMACH];		/* active CPUs */
 	int	exiting;		/* shutdown */
 }active;
 
--- a/sys/src/9/zynq/main.c
+++ b/sys/src/9/zynq/main.c
@@ -385,7 +385,7 @@
 void
 main(void)
 {
-	active.machs |= (1 << m->machno);
+	active.machs[m->machno] = 1;
 	if(m->machno != 0){
 		uartputs("\n", 1);
 		mmuinit();