From 3e1eb67a243ace3c11dca32572f209466201b43e Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 15 Apr 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-04-15 --- pc/apic.c | 3 --- pc/archmp.c | 37 ++++++++++++++++++++++++++++++++++++- pc/dat.h | 4 +++- pc/fns.h | 3 ++- pc/i8253.c | 2 +- pc/mp.c | 2 ++ port/proc.c | 3 ++- 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/pc/apic.c b/pc/apic.c index 894935f7efa937d62817d72212b006f68bf90e64..6ce82741fcdb794aabc0e534ca80319a10063a30 100644 --- a/pc/apic.c +++ b/pc/apic.c @@ -343,8 +343,6 @@ ioapicinit(Apic* apic, int apicno) ioapicrdtw(apic, v, hi, lo); } -ulong lapicperiodset[32]; - void lapictimerset(uvlong next) { @@ -366,7 +364,6 @@ lapictimerset(uvlong next) } lapicw(LapicTICR, period); - lapicperiodset[m->machno]++; unlock(&m->apictimerlock); splx(x); diff --git a/pc/archmp.c b/pc/archmp.c index 1d06f56d42b51e4945d359093331b67b98bc70a8..0440d141e9f134ee7dfd289999a2cb287200a650 100644 --- a/pc/archmp.c +++ b/pc/archmp.c @@ -89,12 +89,47 @@ identify(void) return 0; } +Lock mpsynclock; + +void +syncclock(void) +{ + uvlong x; + + if(m->machno == 0){ + wrmsr(0x10, 0); + m->tscticks = 0; + m->tscoff = 0; + } else { + x = MACHP(0)->tscticks; + while(x == MACHP(0)->tscticks) + ; + m->tscoff = MACHP(0)->tscticks; + wrmsr(0x10, 0); + m->tscticks = 0; + } +} + +uvlong +tscticks(uvlong *hz) +{ + uvlong t; + + if(hz != nil) + *hz = m->cpuhz; + + rdtsc(&t); + m->tscticks = t; + + return t+m->tscoff; +} + PCArch archmp = { .id= "_MP_", .ident= identify, .reset= mpshutdown, .intrinit= mpinit, .intrenable= mpintrenable, -.fastclock= i8253read, +.fastclock= tscticks, .timerset= lapictimerset, }; diff --git a/pc/dat.h b/pc/dat.h index a2ed325f79922b126faf8af8b584260971121900..e757e0bb0d2cadf940a377689e1fa309e54817f2 100644 --- a/pc/dat.h +++ b/pc/dat.h @@ -185,13 +185,15 @@ struct Mach Lock apictimerlock; int cpumhz; - vlong cpuhz; + uvlong cpuhz; int cpuidax; int cpuiddx; char cpuidid[16]; char* cpuidtype; int havetsc; int havepge; + uvlong tscticks; + uvlong tscoff; vlong mtrrcap; vlong mtrrdef; diff --git a/pc/fns.h b/pc/fns.h index 498b7b7e582cb7150a437fa9acb105fb91efe314..75432ea59d8c93190867a9fa6e7b344cd911d62b 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -121,11 +121,12 @@ void procsetup(Proc*); void putcr3(ulong); void putcr4(ulong); void rdmsr(int, vlong*); -void rdtsc(vlong*); +void rdtsc(uvlong*); void screeninit(void); int screenprint(char*, ...); /* debugging */ void (*screenputs)(char*, int); void sfence(void); +void syncclock(void); void touser(void*); void trapenable(int, void (*)(Ureg*, void*), void*, char*); void trapinit(void); diff --git a/pc/i8253.c b/pc/i8253.c index d5182aaef6b9f7b2f414fc27ff71e1087b910d0f..e13a455617e9e1fbfb3256ecb5209a366f31251c 100644 --- a/pc/i8253.c +++ b/pc/i8253.c @@ -116,7 +116,7 @@ void guesscpuhz(int aalcycles) { int cpufreq, loops, incr, x, y; - vlong a, b; + uvlong a, b; /* find biggest loop that doesn't wrap */ incr = 16000000/(aalcycles*HZ*2); diff --git a/pc/mp.c b/pc/mp.c index 720c561390cd95efa2e583575a30ef7851264711..f5a9f99e44aada9fd6e6b2b5576d0f52076aebbb 100644 --- a/pc/mp.c +++ b/pc/mp.c @@ -365,6 +365,7 @@ squidboy(Apic* apic) lapicinit(apic); lapiconline(); + syncclock(); timersinit(); lock(&active); @@ -460,6 +461,7 @@ mpinit(void) Apic *apic, *bpapic; i8259init(); + syncclock(); if(_mp_ == 0) return; diff --git a/port/proc.c b/port/proc.c index acad435ae0ea44c206cacab3498e8a314c98f1ea..c0aa2e182c42eacdd79d4444b296c2482daf7c83 100644 --- a/port/proc.c +++ b/port/proc.c @@ -263,7 +263,7 @@ found: l = 0; for(p = rq->head; p; p = p->rnext){ - if(p->mp == MACHP(m->machno) || p->movetime < MACHP(0)->ticks) + if(p->mp == MACHP(m->machno) || p->movetime <= MACHP(0)->ticks) break; l = p; } @@ -359,6 +359,7 @@ newproc(void) p->errbuf1[0] = '\0'; p->nlocks = 0; p->delaysched = 0; + p->movetime = 0; kstrdup(&p->user, "*nouser"); kstrdup(&p->text, "*notext"); kstrdup(&p->args, "");