--- ray/src/hd/rholo2l.c 1997/11/24 15:18:47 3.5 +++ ray/src/hd/rholo2l.c 2003/06/30 14:59:12 3.14 @@ -1,29 +1,31 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rholo2l.c,v 3.14 2003/06/30 14:59:12 schorsch Exp $"; #endif - /* * Routines for local rtrace execution */ +#include +#include +#include + #include "rholo.h" #include "random.h" +#include "paths.h" #include "selcall.h" -#include -#include +#include "rtprocess.h" #ifndef MAXPROC -#define MAXPROC 16 +#define MAXPROC 64 #endif -static char PFILE[] = "/usr/tmp/RHpersist"; /* persist file name */ +int nprocs = 0; /* running process count */ -static int rtpd[MAXPROC][3]; /* process descriptors */ +static char pfile[] = TEMPLATE; /* persist file name */ + +static SUBPROC rtpd[MAXPROC]; /* process descriptors */ static float *rtbuf = NULL; /* allocated i/o buffer */ static int maxqlen = 0; /* maximum packets per queue */ -static int nprocs = 0; /* number of processes */ static PACKET *pqueue[MAXPROC]; /* packet queues */ static int pqlen[MAXPROC]; /* packet queue lengths */ @@ -34,36 +36,40 @@ start_rtrace() /* start rtrace process */ { static char buf1[8]; int rmaxpack = 0; - int psiz, npt, n; + int psiz, n; /* get number of processes */ - if ((npt = ncprocs) <= 0) + if (ncprocs <= 0 || nprocs > 0) return(0); - if (npt > MAXPROC) { + if (ncprocs > MAXPROC) { sprintf(errmsg, "number of rtrace processes reduced from %d to %d", - npt, MAXPROC); + ncprocs, MAXPROC); error(WARNING, errmsg); - npt = MAXPROC; + ncprocs = MAXPROC; } - /* add compulsory options */ - rtargv[rtargc++] = "-i-"; - rtargv[rtargc++] = "-I-"; - rtargv[rtargc++] = "-h-"; - rtargv[rtargc++] = "-ld-"; - sprintf(buf1, "%d", RPACKSIZ); - rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; - rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; - rtargv[rtargc++] = "-fff"; - rtargv[rtargc++] = "-ovL"; - rtargv[rtargc++] = nowarn ? "-w-" : "-w+"; - if (npt > 1) { - rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = PFILE; + if (rtargv[rtargc-1] != vval(OCTREE)) { + /* add compulsory options */ + rtargv[rtargc++] = "-i-"; + rtargv[rtargc++] = "-I-"; + rtargv[rtargc++] = "-h-"; + rtargv[rtargc++] = "-ld-"; + sprintf(buf1, "%d", RPACKSIZ); + rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; + rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; + rtargv[rtargc++] = "-fff"; + rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; + if (nowarn) + rtargv[rtargc++] = "-w-"; + if (ncprocs > 1) { + mktemp(pfile); + rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; + } + rtargv[rtargc++] = vval(OCTREE); + rtargv[rtargc] = NULL; } - rtargv[rtargc++] = vval(OCTREE); - rtargv[rtargc] = NULL; maxqlen = 0; - for (nprocs = 0; nprocs < npt; nprocs++) { /* spawn children */ - psiz = open_process(rtpd[nprocs], rtargv); + for (nprocs = 0; nprocs < ncprocs; nprocs++) { /* spawn children */ + psiz = open_process(&rtpd[nprocs], rtargv); if (psiz <= 0) error(SYSTEM, "cannot start rtrace process"); n = psiz/(RPACKSIZ*6*sizeof(float)); @@ -71,6 +77,7 @@ start_rtrace() /* start rtrace process */ if (!(maxqlen = n)) error(INTERNAL, "bad pipe buffer size assumption"); + sleep(2); } else if (n != maxqlen) error(INTERNAL, "varying pipe buffer size!"); rmaxpack += n; @@ -130,8 +137,8 @@ register PACKET *p; /* write out the packet */ packrays(rtbuf, p); if ((n = p->nr) < RPACKSIZ) /* add flush block? */ - bzero((char *)(rtbuf+6*n++), 6*sizeof(float)); - if (writebuf(rtpd[pn][1], (char *)rtbuf, 6*sizeof(float)*n) < 0) + memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float)); + if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0) error(SYSTEM, "write error in queue_packet"); p->next = NULL; if (!pqlen[pn]++) /* add it to the end of the queue */ @@ -160,10 +167,10 @@ int poll; FD_ZERO(&readset); FD_ZERO(&errset); n = 0; for (pn = nprocs; pn--; ) { if (pqlen[pn]) - FD_SET(rtpd[pn][0], &readset); - FD_SET(rtpd[pn][0], &errset); - if (rtpd[pn][0] >= n) - n = rtpd[pn][0] + 1; + FD_SET(rtpd[pn].r, &readset); + FD_SET(rtpd[pn].r, &errset); + if (rtpd[pn].r >= n) + n = rtpd[pn].r + 1; } /* make the call */ n = select(n, &readset, (fd_set *)NULL, &errset, @@ -177,11 +184,11 @@ int poll; return(NULL); /* make read call(s) */ for (pn = 0; pn < nprocs; pn++) { - if (!FD_ISSET(rtpd[pn][0], &readset) && - !FD_ISSET(rtpd[pn][0], &errset)) + if (!FD_ISSET(rtpd[pn].r, &readset) && + !FD_ISSET(rtpd[pn].r, &errset)) continue; reread: - n = read(rtpd[pn][0], (char *)rtbuf, + n = read(rtpd[pn].r, (char *)rtbuf, 4*sizeof(float)*RPACKSIZ*pqlen[pn]); if (n < 0) { if (errno == EINTR | errno == EAGAIN) @@ -196,7 +203,7 @@ int poll; nr++; /* add flush block */ n -= 4*sizeof(float)*nr; if (n < 0) { /* get remainder */ - n += readbuf(rtpd[pn][0], + n += readbuf(rtpd[pn].r, (char *)(bp+4*nr)+n, -n); if (n) goto eoferr; @@ -263,7 +270,7 @@ flush_queue() /* empty all rtrace queues */ if (rpl->nr < RPACKSIZ) nr++; /* add flush block */ } - n = readbuf(rtpd[i][0], (char *)rtbuf, + n = readbuf(rtpd[i].r, (char *)rtbuf, 4*sizeof(float)*nr); if (n < 0) error(SYSTEM, "read failure in flush_queue"); @@ -291,10 +298,10 @@ killpersist() /* kill persistent process */ FILE *fp; int pid; - if ((fp = fopen(PFILE, "r")) == NULL) + if ((fp = fopen(pfile, "r")) == NULL) return; if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0) - unlink(PFILE); + unlink(pfile); fclose(fp); } @@ -307,11 +314,11 @@ end_rtrace() /* close rtrace process(es) */ if (nprocs > 1) killpersist(); while (nprocs > 0) { - rv = close_process(rtpd[--nprocs]); + rv = close_process(&rtpd[--nprocs]); if (rv > 0) status = rv; } - free((char *)rtbuf); + free((void *)rtbuf); rtbuf = NULL; maxqlen = 0; return(status);