From 41383ad0120630edd42c5c897a287e2f9d9161b4 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 5 Jan 2016 05:32:40 +0100 Subject: [PATCH] kernel: change active.machs from bitmap to char array to support up to 64 cpus on pc64 --- sys/src/9/alphapc/dat.h | 4 ++-- sys/src/9/alphapc/main.c | 2 +- sys/src/9/alphapc/trap.c | 4 ++-- sys/src/9/bcm/dat.h | 2 +- sys/src/9/bcm/main.c | 2 +- sys/src/9/bitsy/dat.h | 2 +- sys/src/9/bitsy/main.c | 2 +- sys/src/9/kw/dat.h | 2 +- sys/src/9/kw/main.c | 2 +- sys/src/9/mtx/dat.h | 4 ++-- sys/src/9/mtx/main.c | 2 +- sys/src/9/omap/dat.h | 2 +- sys/src/9/omap/main.c | 2 +- sys/src/9/pc/dat.h | 2 +- sys/src/9/pc/main.c | 2 +- sys/src/9/pc/mmu.c | 2 +- sys/src/9/pc/mp.c | 4 +++- sys/src/9/pc/squidboy.c | 2 +- sys/src/9/pc/trap.c | 4 ++-- sys/src/9/pc64/dat.h | 2 +- sys/src/9/pc64/main.c | 2 +- sys/src/9/pc64/mem.h | 2 +- sys/src/9/pc64/squidboy.c | 2 +- sys/src/9/pc64/trap.c | 4 ++-- sys/src/9/port/devcons.c | 14 +++++++------- sys/src/9/port/portclock.c | 2 +- sys/src/9/ppc/dat.h | 4 ++-- sys/src/9/ppc/m8260.c | 2 +- sys/src/9/ppc/msaturn.c | 2 +- sys/src/9/sgi/dat.h | 2 +- sys/src/9/sgi/main.c | 2 +- sys/src/9/teg2/archtegra.c | 2 +- sys/src/9/teg2/dat.h | 2 +- sys/src/9/teg2/main.c | 14 ++++---------- sys/src/9/xen/main.c | 2 +- sys/src/9/xen/trap.c | 4 ++-- sys/src/9/zynq/dat.h | 2 +- sys/src/9/zynq/main.c | 2 +- 38 files changed, 56 insertions(+), 60 deletions(-) diff --git a/sys/src/9/alphapc/dat.h b/sys/src/9/alphapc/dat.h index 250d607e0..5af7a0fdc 100644 --- a/sys/src/9/alphapc/dat.h +++ b/sys/src/9/alphapc/dat.h @@ -184,8 +184,8 @@ struct Mach struct { Lock; - short machs; - short exiting; + char machs[MAXMACH]; + int exiting; }active; /* diff --git a/sys/src/9/alphapc/main.c b/sys/src/9/alphapc/main.c index 9175c2627..c9d10faee 100644 --- a/sys/src/9/alphapc/main.c +++ b/sys/src/9/alphapc/main.c @@ -156,7 +156,7 @@ machinit(void) 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; diff --git a/sys/src/9/alphapc/trap.c b/sys/src/9/alphapc/trap.c index 07d4ea3a7..5f26c5393 100644 --- a/sys/src/9/alphapc/trap.c +++ b/sys/src/9/alphapc/trap.c @@ -261,8 +261,8 @@ intr(Ureg *ur) */ iprint("cpu%d: spurious interrupt %d, last %d", m->machno, vno-VectorPIC, m->lastintr); - for(i = 0; i < 32; i++){ - if(!(active.machs & (1<machno == mach->machno) diff --git a/sys/src/9/bcm/dat.h b/sys/src/9/bcm/dat.h index 76d4012c3..56a5383ec 100644 --- a/sys/src/9/bcm/dat.h +++ b/sys/src/9/bcm/dat.h @@ -223,7 +223,7 @@ typedef void KMap; struct { Lock; - int machs; /* bitmap of active CPUs */ + char machs[MAXMACH]; /* active CPUs */ int exiting; /* shutdown */ }active; diff --git a/sys/src/9/bcm/main.c b/sys/src/9/bcm/main.c index a39637a21..36ca703b7 100644 --- a/sys/src/9/bcm/main.c +++ b/sys/src/9/bcm/main.c @@ -199,7 +199,7 @@ machinit(void) conf.nmach = 1; - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; up = nil; diff --git a/sys/src/9/bitsy/dat.h b/sys/src/9/bitsy/dat.h index 6b5d190a7..896dc986b 100644 --- a/sys/src/9/bitsy/dat.h +++ b/sys/src/9/bitsy/dat.h @@ -178,7 +178,7 @@ typedef void KMap; struct { Lock; - int machs; /* bitmap of active CPUs */ + char machs[MAXMACH]; /* active CPUs */ int exiting; /* shutdown */ }active; diff --git a/sys/src/9/bitsy/main.c b/sys/src/9/bitsy/main.c index 203428e73..b1e3c17c9 100644 --- a/sys/src/9/bitsy/main.c +++ b/sys/src/9/bitsy/main.c @@ -26,7 +26,7 @@ main(void) memset(m, 0, sizeof(Mach)); m->ticks = 1; - active.machs = 1; + active.machs[0] = 1; rs232power(1); quotefmtinstall(); diff --git a/sys/src/9/kw/dat.h b/sys/src/9/kw/dat.h index a6623abac..95804e329 100644 --- a/sys/src/9/kw/dat.h +++ b/sys/src/9/kw/dat.h @@ -194,7 +194,7 @@ typedef void KMap; struct { Lock; - int machs; /* bitmap of active CPUs */ + char machs[MAXMACH]; /* active CPUs */ int exiting; /* shutdown */ }active; diff --git a/sys/src/9/kw/main.c b/sys/src/9/kw/main.c index e938660b3..8d16c0b43 100644 --- a/sys/src/9/kw/main.c +++ b/sys/src/9/kw/main.c @@ -349,7 +349,7 @@ machinit(void) conf.nmach = 1; - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; up = nil; diff --git a/sys/src/9/mtx/dat.h b/sys/src/9/mtx/dat.h index 4e3c7414d..3db9d2290 100644 --- a/sys/src/9/mtx/dat.h +++ b/sys/src/9/mtx/dat.h @@ -181,8 +181,8 @@ struct Mach struct { Lock; - short machs; - short exiting; + char machs[MAXMACH]; + int exiting; }active; /* diff --git a/sys/src/9/mtx/main.c b/sys/src/9/mtx/main.c index f3c5a1568..1ce07155b 100644 --- a/sys/src/9/mtx/main.c +++ b/sys/src/9/mtx/main.c @@ -59,7 +59,7 @@ machinit(void) /* turn on caches */ puthid0(gethid0() | BIT(16) | BIT(17)); - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; } diff --git a/sys/src/9/omap/dat.h b/sys/src/9/omap/dat.h index 982e18b74..0f0c5d6a4 100644 --- a/sys/src/9/omap/dat.h +++ b/sys/src/9/omap/dat.h @@ -216,7 +216,7 @@ typedef void KMap; struct { Lock; - int machs; /* bitmap of active CPUs */ + char machs[MAXMACH]; /* active CPUs */ int exiting; /* shutdown */ }active; diff --git a/sys/src/9/omap/main.c b/sys/src/9/omap/main.c index 42ce8ba5a..f16ca5d6d 100644 --- a/sys/src/9/omap/main.c +++ b/sys/src/9/omap/main.c @@ -295,7 +295,7 @@ machinit(void) conf.nmach = 1; - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; up = nil; diff --git a/sys/src/9/pc/dat.h b/sys/src/9/pc/dat.h index 19b7dfae2..581bdf73e 100644 --- a/sys/src/9/pc/dat.h +++ b/sys/src/9/pc/dat.h @@ -270,7 +270,7 @@ void kunmap(KMap*); 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; diff --git a/sys/src/9/pc/main.c b/sys/src/9/pc/main.c index 6d8341997..02ca17d81 100644 --- a/sys/src/9/pc/main.c +++ b/sys/src/9/pc/main.c @@ -181,7 +181,7 @@ mach0init(void) machinit(); - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; } diff --git a/sys/src/9/pc/mmu.c b/sys/src/9/pc/mmu.c index cfcdf8793..b48155084 100644 --- a/sys/src/9/pc/mmu.c +++ b/sys/src/9/pc/mmu.c @@ -685,7 +685,7 @@ vunmap(void *v, int size) for(i=0; imachno)) && nm->flushmmu) + while(active.machs[nm->machno] && nm->flushmmu) ; } } diff --git a/sys/src/9/pc/mp.c b/sys/src/9/pc/mp.c index 8bfc52204..ee3fdd363 100644 --- a/sys/src/9/pc/mp.c +++ b/sys/src/9/pc/mp.c @@ -198,6 +198,8 @@ mpinit(void) for(i=0; imachno >= MAXMACH) + continue; if(ncpu <= 1) break; if((apic->flags & (PcmpBP|PcmpEN)) == PcmpEN){ @@ -574,7 +576,7 @@ mpshutdown(void) for(;;) idle(); } - print("mpshutdown: active = %#8.8ux\n", active.machs); + print("mpshutdown\n"); delay(1000); splhi(); diff --git a/sys/src/9/pc/squidboy.c b/sys/src/9/pc/squidboy.c index 593016595..85c3992d1 100644 --- a/sys/src/9/pc/squidboy.c +++ b/sys/src/9/pc/squidboy.c @@ -30,7 +30,7 @@ squidboy(Apic* apic) fpoff(); lock(&active); - active.machs |= 1<machno; + active.machs[m->machno] = 1; unlock(&active); while(!active.thunderbirdsarego) diff --git a/sys/src/9/pc/trap.c b/sys/src/9/pc/trap.c index 071278d03..3fa728975 100644 --- a/sys/src/9/pc/trap.c +++ b/sys/src/9/pc/trap.c @@ -400,8 +400,8 @@ trap(Ureg* ureg) 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<machno == mach->machno) diff --git a/sys/src/9/pc64/dat.h b/sys/src/9/pc64/dat.h index 5558f331a..b6333c5ff 100644 --- a/sys/src/9/pc64/dat.h +++ b/sys/src/9/pc64/dat.h @@ -233,7 +233,7 @@ typedef void KMap; 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; diff --git a/sys/src/9/pc64/main.c b/sys/src/9/pc64/main.c index 4805bcc9e..040a01831 100644 --- a/sys/src/9/pc64/main.c +++ b/sys/src/9/pc64/main.c @@ -326,7 +326,7 @@ mach0init(void) machinit(); - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; } diff --git a/sys/src/9/pc64/mem.h b/sys/src/9/pc64/mem.h index 0a82a378d..fa0a03a10 100644 --- 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 */ diff --git a/sys/src/9/pc64/squidboy.c b/sys/src/9/pc64/squidboy.c index 653802955..218f4971a 100644 --- a/sys/src/9/pc64/squidboy.c +++ b/sys/src/9/pc64/squidboy.c @@ -24,7 +24,7 @@ squidboy(Apic* apic) timersinit(); lock(&active); - active.machs |= 1<machno; + active.machs[m->machno] = 1; unlock(&active); while(!active.thunderbirdsarego) diff --git a/sys/src/9/pc64/trap.c b/sys/src/9/pc64/trap.c index 6dae1b283..e84b199a3 100644 --- a/sys/src/9/pc64/trap.c +++ b/sys/src/9/pc64/trap.c @@ -394,8 +394,8 @@ trap(Ureg *ureg) 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<machno == mach->machno) diff --git a/sys/src/9/port/devcons.c b/sys/src/9/port/devcons.c index 78f56afd1..da1e9fcd4 100644 --- a/sys/src/9/port/devcons.c +++ b/sys/src/9/port/devcons.c @@ -568,8 +568,8 @@ consread(Chan *c, void *buf, long n, vlong off) 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<cs = 0; mp->intr = 0; @@ -1051,8 +1051,8 @@ cpushutdown(void) int ms, once; lock(&active); - once = active.machs & (1<machno); - active.machs &= ~(1<machno); + once = active.machs[m->machno]; + active.machs[m->machno] = 0; active.exiting = 1; unlock(&active); @@ -1063,7 +1063,7 @@ cpushutdown(void) 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; } } diff --git a/sys/src/9/port/portclock.c b/sys/src/9/port/portclock.c index 0bbbc92f1..4b52f6d30 100644 --- a/sys/src/9/port/portclock.c +++ b/sys/src/9/port/portclock.c @@ -145,7 +145,7 @@ hzclock(Ureg *ur) if(kproftimer != nil) kproftimer(ur->pc); - if((active.machs&(1<machno)) == 0) + if(active.machs[m->machno] == 0) return; if(active.exiting) diff --git a/sys/src/9/ppc/dat.h b/sys/src/9/ppc/dat.h index d10559f01..b04362794 100644 --- a/sys/src/9/ppc/dat.h +++ b/sys/src/9/ppc/dat.h @@ -189,8 +189,8 @@ struct Mach struct { Lock; - short machs; - short exiting; + char machs[MAXMACH]; + int exiting; }active; /* diff --git a/sys/src/9/ppc/m8260.c b/sys/src/9/ppc/m8260.c index 4f84ec135..0c441a209 100644 --- a/sys/src/9/ppc/m8260.c +++ b/sys/src/9/ppc/m8260.c @@ -214,7 +214,7 @@ machinit(void) vco 198 */ - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; putmsr(getmsr() | MSR_ME); diff --git a/sys/src/9/ppc/msaturn.c b/sys/src/9/ppc/msaturn.c index 94aa1fb17..ca2a599c7 100644 --- a/sys/src/9/ppc/msaturn.c +++ b/sys/src/9/ppc/msaturn.c @@ -140,7 +140,7 @@ machinit(void) m->cpuhz = 200000000; /* 750FX? */ m->cyclefreq = m->bushz / 4; - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; putmsr(getmsr() | MSR_ME); diff --git a/sys/src/9/sgi/dat.h b/sys/src/9/sgi/dat.h index 771b755ce..2a2ab273c 100644 --- a/sys/src/9/sgi/dat.h +++ b/sys/src/9/sgi/dat.h @@ -204,7 +204,7 @@ struct Softtlb struct { Lock; - long machs; /* bitmap of processors */ + char machs[MAXMACH]; /* active cpus */ short exiting; }active; diff --git a/sys/src/9/sgi/main.c b/sys/src/9/sgi/main.c index 08c6c85b8..6e5a8ae42 100644 --- a/sys/src/9/sgi/main.c +++ b/sys/src/9/sgi/main.c @@ -172,7 +172,7 @@ main(void) confinit(); machinit(); /* calls clockinit */ active.exiting = 0; - active.machs = 1; + active.machs[0] = 1; print("\nPlan 9\n"); kmapinit(); diff --git a/sys/src/9/teg2/archtegra.c b/sys/src/9/teg2/archtegra.c index 8f1ad6831..0a486bad3 100644 --- a/sys/src/9/teg2/archtegra.c +++ b/sys/src/9/teg2/archtegra.c @@ -676,7 +676,7 @@ cpustart(void) Power *pwr; up = nil; - if (active.machs & (1<machno)) { + if (active.machs[m->machno]) { serialputc('?'); serialputc('r'); panic("cpu%d: resetting after start", m->machno); diff --git a/sys/src/9/teg2/dat.h b/sys/src/9/teg2/dat.h index 80068975c..0152c76b3 100644 --- a/sys/src/9/teg2/dat.h +++ b/sys/src/9/teg2/dat.h @@ -246,7 +246,7 @@ typedef void KMap; 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 */ diff --git a/sys/src/9/teg2/main.c b/sys/src/9/teg2/main.c index 6847f3a91..e26d8bd87 100644 --- a/sys/src/9/teg2/main.c +++ b/sys/src/9/teg2/main.c @@ -208,13 +208,10 @@ getenv(char* name, char* buf, int n) 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 @@ machon(uint cpu) 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); } diff --git a/sys/src/9/xen/main.c b/sys/src/9/xen/main.c index 33b800579..ab6272081 100644 --- a/sys/src/9/xen/main.c +++ b/sys/src/9/xen/main.c @@ -121,7 +121,7 @@ mach0init(void) machinit(); - active.machs = 1; + active.machs[0] = 1; active.exiting = 0; } diff --git a/sys/src/9/xen/trap.c b/sys/src/9/xen/trap.c index a81182a8b..d524b403c 100644 --- a/sys/src/9/xen/trap.c +++ b/sys/src/9/xen/trap.c @@ -393,8 +393,8 @@ trap(Ureg* ureg) 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<machno == mach->machno) diff --git a/sys/src/9/zynq/dat.h b/sys/src/9/zynq/dat.h index 4172407b4..a1d50b40b 100644 --- a/sys/src/9/zynq/dat.h +++ b/sys/src/9/zynq/dat.h @@ -175,7 +175,7 @@ struct ISAConf struct { Lock; - int machs; /* bitmap of active CPUs */ + char machs[MAXMACH]; /* active CPUs */ int exiting; /* shutdown */ }active; diff --git a/sys/src/9/zynq/main.c b/sys/src/9/zynq/main.c index 91206e0a3..ec23af843 100644 --- a/sys/src/9/zynq/main.c +++ b/sys/src/9/zynq/main.c @@ -385,7 +385,7 @@ mpinit(void) void main(void) { - active.machs |= (1 << m->machno); + active.machs[m->machno] = 1; if(m->machno != 0){ uartputs("\n", 1); mmuinit();