From 6bbc6be280c7cad0522c20cd2158362919c13472 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 26 Jun 2000 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2000-06-26 --- pc/trap.c | 8 +------- port/tod.c | 54 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/pc/trap.c b/pc/trap.c index 453f057dfb790e4db04bb3e7b261f09c02bdf124..07050fff83737dab78ac3dff0b1d118d9739797e 100644 --- a/pc/trap.c +++ b/pc/trap.c @@ -19,7 +19,7 @@ void intrenable(int irq, void (*f)(Ureg*, void*), void* a, int tbdf, char *name) { int vno; - Vctl *v, *p; + Vctl *v; v = xalloc(sizeof(Vctl)); v->isintr = 1; @@ -36,12 +36,6 @@ intrenable(int irq, void (*f)(Ureg*, void*), void* a, int tbdf, char *name) iunlock(&vctllock); print("intrenable: couldn't enable irq %d, tbdf 0x%uX for %s\n", irq, tbdf, v->name); - if(p=vctl[vno]){ - print("intrenable: irq %d is already used by", irq); - for(; p; p=p->next) - print(" %s", p->name); - print("\n"); - } xfree(v); return; } diff --git a/port/tod.c b/port/tod.c index ed2ac075340471d4d054f9e48eab2fb54cc1031c..371e9a086853b0b428f9851e62ca07193945bb27 100644 --- a/port/tod.c +++ b/port/tod.c @@ -22,12 +22,16 @@ // // each time f is set. f is normally set by a user level // program writing to /dev/fastclock. +// +// We assume that the cpu's of a multiprocessor are synchronized. +// This assumption needs to be questioned with each new architecture. // frequency of the tod clock #define TODFREQ 1000000000LL struct { + ulong cnt; Lock; vlong multiplier; // t = off + (multiplier*ticks)>>31 vlong hz; // frequency of fast clock @@ -103,37 +107,30 @@ todget(vlong *ticksp) else ticks = fastticks(nil); - /* since 64 bit ops are not atomix, we have to lock around them */ + // since 64 bit loads are not atomic, we have to lock around them ilock(&tod); - diff = ticks - tod.last; + tod.cnt++; + + // add in correction + if(tod.sstart != tod.send){ + t = MACHP(0)->ticks; + if(t >= tod.send) + t = tod.send; + tod.off = tod.off + tod.delta*(t - tod.sstart); + tod.sstart = t; + } // convert to epoch + diff = ticks - tod.last; x = (diff * tod.multiplier) >> 31; x = x + tod.off; - if(m->machno == 0){ - - // add in correction - if(tod.sstart != tod.send){ - t = MACHP(0)->ticks; - if(t >= tod.send) - t = tod.send; - tod.off = tod.off + tod.delta*(t - tod.sstart); - tod.sstart = t; - } - - // protect against overflows - if(diff > tod.hz){ - tod.last = ticks; - tod.off = x; - } - } - // time can't go backwards if(x < tod.lasttime) x = tod.lasttime; else tod.lasttime = x; + iunlock(&tod); if(ticksp != nil) @@ -149,12 +146,25 @@ void todfix(void) { vlong ticks, diff; + uvlong x; ticks = fastticks(nil); diff = ticks - tod.last; - if(diff > tod.hz) - todget(nil); + if(diff > tod.hz){ + ilock(&tod); + + // convert to epoch + diff = ticks - tod.last; + x = (diff * tod.multiplier) >> 31; + x = x + tod.off; + + // protect against overflows + tod.last = ticks; + tod.off = x; + + iunlock(&tod); + } } long