diff options
author | rsc <devnull@localhost> | 2007-04-21 19:40:55 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2007-04-21 19:40:55 +0000 |
commit | 27d28098203579f0735ba6400641e9be94eb12f8 (patch) | |
tree | 9e0f390ced0de8c582ef3226c420daa18d16ac24 /src/cmd/venti/srv/icache.c | |
parent | 33433b3fde56d9b3ac6de6ee2584416b82bc856f (diff) | |
download | plan9port-27d28098203579f0735ba6400641e9be94eb12f8.tar.gz plan9port-27d28098203579f0735ba6400641e9be94eb12f8.tar.bz2 plan9port-27d28098203579f0735ba6400641e9be94eb12f8.zip |
sync with mit plan 9 version
Diffstat (limited to 'src/cmd/venti/srv/icache.c')
-rw-r--r-- | src/cmd/venti/srv/icache.c | 146 |
1 files changed, 83 insertions, 63 deletions
diff --git a/src/cmd/venti/srv/icache.c b/src/cmd/venti/srv/icache.c index 49f741e7..56513aa2 100644 --- a/src/cmd/venti/srv/icache.c +++ b/src/cmd/venti/srv/icache.c @@ -86,99 +86,119 @@ fprint(2, "seed index cache with arena @%llud, (map %llud), %d clumps\n", arena- } } -/* -ZZZ need to think about evicting the correct IEntry, -and writing back the wtime. - * look up data score in the index cache - * if this fails, pull it in from the disk index table, if it exists. - * - * must be called with the lump for this score locked - */ int -lookupscore(u8int *score, int type, IAddr *ia, int *rac) +_lookupscore(u8int *score, int type, IAddr *ia, int *rac) { - IEntry d, *ie, *last; u32int h; - u64int aa; - Arena *load; - int i; - uint ms; - - load = nil; - aa = 0; - ms = msec(); - - trace(TraceLump, "lookupscore %V.%d", score, type); + IEntry *ie, *last; qlock(&icache.lock); h = hashbits(score, icache.bits); last = nil; for(ie = icache.heads[h]; ie != nil; ie = ie->next){ - if(ie->ia.type == type && scorecmp(ie->score, score)==0){ + if((ie->ia.type == type || type == -1) && scorecmp(ie->score, score)==0){ if(last != nil) last->next = ie->next; else icache.heads[h] = ie->next; addstat(StatIcacheHit, 1); - ie->rac = 1; + if(rac) + ie->rac = 1; trace(TraceLump, "lookupscore incache"); - goto found; + ie->next = icache.heads[h]; + icache.heads[h] = ie; + + *ia = ie->ia; + if(rac) + *rac = ie->rac; + qunlock(&icache.lock); + return 0; } last = ie; } addstat(StatIcacheMiss, 1); qunlock(&icache.lock); + return -1; +} - if(loadientry(mainindex, score, type, &d) < 0){ - ms = msec() - ms; - addstat2(StatIcacheRead, 1, StatIcacheReadTime, ms); - return -1; - } - - addstat(StatIcacheFill, 1); - trace(TraceLump, "lookupscore loaded"); +/* +ZZZ need to think about evicting the correct IEntry, +and writing back the wtime. + * look up data score in the index cache + * if this fails, pull it in from the disk index table, if it exists. + * + * must be called with the lump for this score locked + */ +int +lookupscore(u8int *score, int type, IAddr *ia, int *rac) +{ + IEntry d, *ie; + u32int h; + u64int aa; + Arena *load; + int i, ret; + uint ms; - /* - * no one else can load an entry for this score, - * since we have the overall score lock. - */ - qlock(&icache.lock); + aa = 0; + ms = msec(); + + trace(TraceLump, "lookupscore %V.%d", score, type); - /* - * If we notice that all the hits are coming from one arena, - * load the table of contents for that arena into the cache. - */ - ie = icachealloc(&d.ia, score); - if(icacheprefetch){ - icache.last[icache.nlast++%nelem(icache.last)] = amapitoa(mainindex, ie->ia.addr, &aa); - aa = ie->ia.addr - aa; /* compute base addr of arena */ - for(i=0; i<nelem(icache.last); i++) - if(icache.last[i] != icache.last[0]) - break; - if(i==nelem(icache.last) && icache.lastload != icache.last[0]){ - load = icache.last[0]; - icache.lastload = load; + ret = 0; + if(_lookupscore(score, type, ia, rac) < 0){ + if(loadientry(mainindex, score, type, &d) < 0){ + ret = -1; + goto out; } - } - -found: - ie->next = icache.heads[h]; - icache.heads[h] = ie; - *ia = ie->ia; - *rac = ie->rac; + /* failed in cache but found on disk - fill cache. */ + trace(TraceLump, "lookupscore loaded"); + addstat(StatIcacheFill, 1); - qunlock(&icache.lock); - - if(load){ - trace(TraceProc, "preload 0x%llux", aa); - loadarenaclumps(load, aa); + /* + * no one else can load an entry for this score, + * since we have this score's lump's lock. + */ + qlock(&icache.lock); + + /* + * If we notice that all the hits are coming from one arena, + * load the table of contents for that arena into the cache. + */ + load = nil; + h = hashbits(score, icache.bits); + ie = icachealloc(&d.ia, score); + if(icacheprefetch){ + icache.last[icache.nlast++%nelem(icache.last)] = amapitoa(mainindex, ie->ia.addr, &aa); + aa = ie->ia.addr - aa; /* compute base addr of arena */ + for(i=0; i<nelem(icache.last); i++) + if(icache.last[i] != icache.last[0]) + break; + if(i==nelem(icache.last) && icache.lastload != icache.last[0]){ + load = icache.last[0]; + icache.lastload = load; + } + } + + ie->next = icache.heads[h]; + icache.heads[h] = ie; + + *ia = ie->ia; + *rac = ie->rac; + + qunlock(&icache.lock); + if(load){ + trace(TraceProc, "preload 0x%llux", aa); + loadarenaclumps(load, aa); + } } + +out: ms = msec() - ms; addstat2(StatIcacheRead, 1, StatIcacheReadTime, ms); - return 0; + return ret; } /* |