| 23 |
|
|
| 24 |
|
static char pfile[] = TEMPLATE; /* persist file name */ |
| 25 |
|
|
| 26 |
< |
static SUBPROC rtpd[MAXPROC]; /* process descriptors */ |
| 26 |
> |
static SUBPROC rtpd[MAXPROC]; /* process descriptors */ |
| 27 |
|
static float *rtbuf = NULL; /* allocated i/o buffer */ |
| 28 |
< |
static int maxqlen = 0; /* maximum packets per queue */ |
| 28 |
> |
static int maxqlen; /* maximum packets per queue */ |
| 29 |
|
|
| 30 |
|
static PACKET *pqueue[MAXPROC]; /* packet queues */ |
| 31 |
|
static int pqlen[MAXPROC]; /* packet queue lengths */ |
| 37 |
|
static void killpersist(void); |
| 38 |
|
|
| 39 |
|
|
| 40 |
< |
extern int |
| 40 |
> |
int |
| 41 |
|
start_rtrace(void) /* start rtrace process */ |
| 42 |
|
{ |
| 43 |
|
static char buf1[8]; |
| 59 |
|
rtargv[rtargc++] = "-I-"; |
| 60 |
|
rtargv[rtargc++] = "-h-"; |
| 61 |
|
rtargv[rtargc++] = "-ld-"; |
| 62 |
+ |
rtargv[rtargc++] = "-pRGB"; |
| 63 |
|
sprintf(buf1, "%d", RPACKSIZ); |
| 64 |
|
rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; |
| 65 |
|
rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; |
| 79 |
|
psiz = open_process(&rtpd[nprocs], rtargv); |
| 80 |
|
if (psiz <= 0) |
| 81 |
|
error(SYSTEM, "cannot start rtrace process"); |
| 82 |
< |
n = psiz/(RPACKSIZ*6*sizeof(float)); |
| 83 |
< |
if (maxqlen == 0) { |
| 84 |
< |
if (!(maxqlen = n)) |
| 84 |
< |
error(INTERNAL, |
| 85 |
< |
"bad pipe buffer size assumption"); |
| 82 |
> |
n = psiz/(RPACKSIZ*6*sizeof(float)) + 1; |
| 83 |
> |
if (!maxqlen) { |
| 84 |
> |
maxqlen = n; |
| 85 |
|
sleep(2); |
| 86 |
|
} else if (n != maxqlen) |
| 87 |
|
error(INTERNAL, "varying pipe buffer size!"); |
| 98 |
|
bestout(void) /* get best process to process packet */ |
| 99 |
|
{ |
| 100 |
|
int cnt; |
| 101 |
< |
register int pn, i; |
| 101 |
> |
int pn, i; |
| 102 |
|
|
| 103 |
|
pn = 0; /* find shortest queue */ |
| 104 |
|
for (i = 1; i < nprocs; i++) |
| 112 |
|
if (pqlen[i] == pqlen[pn]) |
| 113 |
|
cnt++; |
| 114 |
|
/* break ties fairly */ |
| 115 |
< |
if ((cnt = random() % cnt)) |
| 115 |
> |
if ((cnt = irandom(cnt))) |
| 116 |
|
for (i = pn; i < nprocs; i++) |
| 117 |
|
if (pqlen[i] == pqlen[pn] && !cnt--) |
| 118 |
|
return(i); |
| 123 |
|
static int |
| 124 |
|
slots_avail(void) /* count packet slots available */ |
| 125 |
|
{ |
| 126 |
< |
register int nslots = 0; |
| 127 |
< |
register int i; |
| 126 |
> |
int nslots = 0; |
| 127 |
> |
int i; |
| 128 |
|
|
| 129 |
|
for (i = nprocs; i--; ) |
| 130 |
|
nslots += maxqlen - pqlen[i]; |
| 134 |
|
|
| 135 |
|
static void |
| 136 |
|
queue_packet( /* queue up a beam packet */ |
| 137 |
< |
register PACKET *p |
| 137 |
> |
PACKET *p |
| 138 |
|
) |
| 139 |
|
{ |
| 140 |
|
int pn, n; |
| 145 |
|
packrays(rtbuf, p); |
| 146 |
|
if ((n = p->nr) < RPACKSIZ) /* add flush block? */ |
| 147 |
|
memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float)); |
| 148 |
< |
if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0) |
| 148 |
> |
if (writebuf(rtpd[pn].w, rtbuf, 6*sizeof(float)*n) < 0) |
| 149 |
|
error(SYSTEM, "write error in queue_packet"); |
| 150 |
|
p->next = NULL; |
| 151 |
|
if (!pqlen[pn]++) /* add it to the end of the queue */ |
| 152 |
|
pqueue[pn] = p; |
| 153 |
|
else { |
| 154 |
< |
register PACKET *rpl = pqueue[pn]; |
| 154 |
> |
PACKET *rpl = pqueue[pn]; |
| 155 |
|
while (rpl->next != NULL) |
| 156 |
|
rpl = rpl->next; |
| 157 |
|
rpl->next = p; |
| 167 |
|
static struct timeval tpoll; /* zero timeval struct */ |
| 168 |
|
fd_set readset, errset; |
| 169 |
|
PACKET *pldone = NULL, *plend; |
| 170 |
< |
register PACKET *p; |
| 170 |
> |
PACKET *p; |
| 171 |
|
int n, nr; |
| 172 |
< |
register int pn; |
| 172 |
> |
int pn; |
| 173 |
|
float *bp; |
| 174 |
|
/* prepare select call */ |
| 175 |
|
FD_ZERO(&readset); FD_ZERO(&errset); n = 0; |
| 239 |
|
} |
| 240 |
|
|
| 241 |
|
|
| 242 |
< |
extern PACKET * |
| 242 |
> |
PACKET * |
| 243 |
|
do_packets( /* queue a packet list, return finished */ |
| 244 |
< |
register PACKET *pl |
| 244 |
> |
PACKET *pl |
| 245 |
|
) |
| 246 |
|
{ |
| 247 |
< |
register PACKET *p; |
| 247 |
> |
PACKET *p; |
| 248 |
|
/* consistency check */ |
| 249 |
|
if (nprocs < 1) |
| 250 |
|
error(CONSISTENCY, "do_packets called with no active process"); |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
< |
extern PACKET * |
| 260 |
> |
PACKET * |
| 261 |
|
flush_queue(void) /* empty all rtrace queues */ |
| 262 |
|
{ |
| 263 |
|
PACKET *rpdone = NULL; |
| 264 |
< |
register PACKET *rpl = NULL; |
| 264 |
> |
PACKET *rpl = NULL; |
| 265 |
|
float *bp; |
| 266 |
< |
register PACKET *p; |
| 266 |
> |
PACKET *p; |
| 267 |
|
int i, n, nr; |
| 268 |
|
|
| 269 |
|
for (i = 0; i < nprocs; i++) |
| 280 |
|
if (rpl->nr < RPACKSIZ) |
| 281 |
|
nr++; /* add flush block */ |
| 282 |
|
} |
| 283 |
< |
n = readbuf(rtpd[i].r, (char *)rtbuf, |
| 285 |
< |
4*sizeof(float)*nr); |
| 283 |
> |
n = readbuf(rtpd[i].r, rtbuf, 4*sizeof(float)*nr); |
| 284 |
|
if (n < 0) |
| 285 |
|
error(SYSTEM, "read failure in flush_queue"); |
| 286 |
|
bp = rtbuf; /* process packets */ |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 318 |
< |
extern int |
| 318 |
> |
int |
| 319 |
|
end_rtrace(void) /* close rtrace process(es) */ |
| 320 |
|
{ |
| 321 |
|
int status = 0, rv; |