From 701a12b4c5e8d25bf457a04090522ac15e84d8c7 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 29 Oct 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-10-29 --- gnot/scsibuf.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ port/devscsi.c | 43 +--------------------------------- port/portfns.h | 1 + ss/main.c | 2 +- ss/scsibuf.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 43 deletions(-) create mode 100644 gnot/scsibuf.c create mode 100644 ss/scsibuf.c diff --git a/gnot/scsibuf.c b/gnot/scsibuf.c new file mode 100644 index 0000000000000000000000000000000000000000..cc6edda894648d72ddf5c16fd676c195fb8e3991 --- /dev/null +++ b/gnot/scsibuf.c @@ -0,0 +1,63 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "../port/error.h" +#include "io.h" + +/* + * The following routines + * scsibufreset, scsibuf, scsifree and scsialloc + * provide a pool of buffers used for scsi i/o. + * This is simplistic at best, and opportunities for + * deadlock abound. + */ +#define Nbuf 2 + +struct { + Lock; + Scsibuf *free; +} scsibufalloc; + +void +scsibufreset(ulong datasize) +{ + int i; + + for(i = 0; i < Nbuf; i++) + scsifree(scsialloc(datasize)); + lock(&scsibufalloc); + unlock(&scsibufalloc); +} + +/* + * get a scsi io buffer of DATASIZE size + */ +Scsibuf * +scsibuf(void) +{ + Scsibuf *b; + + for(;;) { + lock(&scsibufalloc); + b = scsibufalloc.free; + if(b != 0) { + scsibufalloc.free = b->next; + unlock(&scsibufalloc); + return b; + } + unlock(&scsibufalloc); + resrcwait(0); + } + return 0; /* not reached */ +} + +void +scsifree(Scsibuf *b) +{ + lock(&scsibufalloc); + b->next = scsibufalloc.free; + scsibufalloc.free = b; + unlock(&scsibufalloc); +} diff --git a/port/devscsi.c b/port/devscsi.c index 989b21fea18f71b79934991eb16bab8e18286cff..baba654e235429a513eab1691f6d182cca18f9f4 100644 --- a/port/devscsi.c +++ b/port/devscsi.c @@ -8,15 +8,10 @@ #define DPRINT if(debug)kprint -#define Nbuf 2 #define DATASIZE (32*512) #undef DATASIZE #define DATASIZE (64*1024) -struct{ - Lock; - Scsibuf *free; -}scsibufalloc; static Scsi staticcmd; /* BUG: should be one per scsi device */ @@ -83,12 +78,7 @@ scsigen(Chan *c, Dirtab *tab, long ntab, long s, Dir *dp) void scsireset(void) { - int i; - - for(i = 0; i < Nbuf; i++) - scsifree(scsialloc(DATASIZE)); - lock(&scsibufalloc); - unlock(&scsibufalloc); + scsibufreset(DATASIZE); resetscsi(); } @@ -543,34 +533,3 @@ scsibwrite(int dev, Scsibuf *b, long n, long blocksize, long blockno) qunlock(cmd); return n; } - -/* - * get a scsi io buffer of DATASIZE size - */ -Scsibuf * -scsibuf(void) -{ - Scsibuf *b; - - for(;;) { - lock(&scsibufalloc); - b = scsibufalloc.free; - if(b != 0) { - scsibufalloc.free = b->next; - unlock(&scsibufalloc); - return b; - } - unlock(&scsibufalloc); - resrcwait(0); - } - return 0; /* not reached */ -} - -void -scsifree(Scsibuf *b) -{ - lock(&scsibufalloc); - b->next = scsibufalloc.free; - scsibufalloc.free = b; - unlock(&scsibufalloc); -} diff --git a/port/portfns.h b/port/portfns.h index 49410090568cae686272990bb8342d014071a355..d84e37638df2f080567ce56e45a662137220964c 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -203,6 +203,7 @@ int screenbits(void); Scsibuf* scsialloc(ulong); int scsibread(int, Scsibuf*, long, long, long); Scsibuf* scsibuf(void); +void scsibufreset(ulong); int scsibwrite(int, Scsibuf*, long, long, long); int scsicap(int, void*); Scsi* scsicmd(int, int, Scsibuf*, long); diff --git a/ss/main.c b/ss/main.c index 6bcf0bd3d5d1f05906fb20768d05786bbbd50cd7..053a221ac5c96fcc95c0dd8e17e2a10c218bae75 100644 --- a/ss/main.c +++ b/ss/main.c @@ -420,7 +420,7 @@ confinit(void) v = mempres[i]; for(j=i+1; jmemscan && mempres[j]>v; j++) v = mempres[j]; - npg = ((v+1)-mempres[i])*MB/BY2PG; + npg = (j-i)*MB/BY2PG; if(conf.npage0 == 0){ conf.base0 = i*MB; conf.npage0 = npg; diff --git a/ss/scsibuf.c b/ss/scsibuf.c new file mode 100644 index 0000000000000000000000000000000000000000..cc6edda894648d72ddf5c16fd676c195fb8e3991 --- /dev/null +++ b/ss/scsibuf.c @@ -0,0 +1,63 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "../port/error.h" +#include "io.h" + +/* + * The following routines + * scsibufreset, scsibuf, scsifree and scsialloc + * provide a pool of buffers used for scsi i/o. + * This is simplistic at best, and opportunities for + * deadlock abound. + */ +#define Nbuf 2 + +struct { + Lock; + Scsibuf *free; +} scsibufalloc; + +void +scsibufreset(ulong datasize) +{ + int i; + + for(i = 0; i < Nbuf; i++) + scsifree(scsialloc(datasize)); + lock(&scsibufalloc); + unlock(&scsibufalloc); +} + +/* + * get a scsi io buffer of DATASIZE size + */ +Scsibuf * +scsibuf(void) +{ + Scsibuf *b; + + for(;;) { + lock(&scsibufalloc); + b = scsibufalloc.free; + if(b != 0) { + scsibufalloc.free = b->next; + unlock(&scsibufalloc); + return b; + } + unlock(&scsibufalloc); + resrcwait(0); + } + return 0; /* not reached */ +} + +void +scsifree(Scsibuf *b) +{ + lock(&scsibufalloc); + b->next = scsibufalloc.free; + scsibufalloc.free = b; + unlock(&scsibufalloc); +}