From ee56fa4695e4e27ca03d543f2b91118584f3d049 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 6 Aug 1999 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1999-08-06 --- mpc/devsac.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ mpc/main.c | 2 +- port/tod.c | 8 ++++---- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/mpc/devsac.c b/mpc/devsac.c index 11a2e547d81961fd0bd1f10056e3516668a61993..10092996347378cb4e4eec14d178df120c4e7412 100644 --- a/mpc/devsac.c +++ b/mpc/devsac.c @@ -17,12 +17,14 @@ enum { OPERM = 0x3, /* mask of all permission types in open mode */ Nram = 512, + CacheSize = 20, }; typedef struct SacPath SacPath; typedef struct Sac Sac; typedef struct SacHeader SacHeader; typedef struct SacDir SacDir; +typedef struct Cache Cache; enum { Magic = 0x5acf5, @@ -64,6 +66,13 @@ struct SacPath int entry; }; +struct Cache +{ + long block; + ulong age; + uchar *data; +}; + enum { Pexec = 1, @@ -77,6 +86,8 @@ enum static uchar *data = SACMEM; static int blocksize; static Sac root; +static Cache cache[CacheSize]; +static ulong cacheage; static void sacdir(Chan *, SacDir*, char*); static ulong getl(void *p); @@ -91,6 +102,9 @@ static void sacinit(void) { SacHeader *hdr; + uchar *p; + int i; + print("sacinit\n"); hdr = (SacHeader*)data; if(getl(hdr->magic) != Magic) { @@ -99,6 +113,13 @@ print("devsac: bad magic\n"); } blocksize = getl(hdr->blocksize); root.SacDir = *(SacDir*)(data + sizeof(SacHeader)); + p = malloc(CacheSize*blocksize); + if(p == nil) + error("allocating cache"); + for(i=0; i 0 && n > delta) n = delta; - delta /= n; + delta = delta/n; tod.sstart = MACHP(0)->ticks; tod.send = tod.sstart + n; tod.delta = delta; @@ -111,13 +111,13 @@ todget(vlong *ticksp) t = MACHP(0)->ticks; if(t >= tod.send) t = tod.send; - tod.off += tod.delta*(t - tod.sstart); + tod.off = tod.off + tod.delta*(t - tod.sstart); tod.sstart = t; } // convert to epoch x = (diff * tod.multiplier) >> 31; - x += tod.off; + x = x + tod.off; // protect against overflows if(diff > tod.hz){ @@ -159,7 +159,7 @@ seconds(void) int i; x = todget(nil); - x /= TODFREQ; + x = x/TODFREQ; i = x; return i; }