14 |
|
#include <sys/types.h> |
15 |
|
#include <sys/stat.h> |
16 |
|
|
17 |
+ |
#ifndef MAXQTIME |
18 |
+ |
#define MAXQTIME 5 /* target maximum seconds in queue */ |
19 |
+ |
#endif |
20 |
|
/* the following must be consistent with rholo.h */ |
21 |
|
int NVARS = NRHVARS; /* total number of variables */ |
22 |
|
|
51 |
|
long npacksdone = 0L; /* number of packets done */ |
52 |
|
|
53 |
|
PACKET *freepacks; /* available packets */ |
54 |
+ |
int avgqlen; /* average queue length when full */ |
55 |
|
|
56 |
|
char *sigerr[NSIG]; /* signal error messages */ |
57 |
|
|
63 |
|
char *argv[]; |
64 |
|
{ |
65 |
|
int i; |
66 |
< |
/* mark start time */ |
63 |
< |
starttime = time(NULL); |
66 |
> |
|
67 |
|
initurand(16384); /* initialize urand */ |
68 |
|
progname = argv[0]; /* get arguments */ |
69 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
91 |
|
goto userr; |
92 |
|
} |
93 |
|
/* get root file name */ |
94 |
+ |
if (i >= argc) |
95 |
+ |
goto userr; |
96 |
|
rootname(froot, hdkfile=argv[i++]); |
97 |
|
/* load variables? */ |
98 |
|
if (i < argc) |
109 |
|
} |
110 |
|
/* check settings */ |
111 |
|
checkvalues(); |
112 |
< |
/* load RIF if any */ |
113 |
< |
getradfile(); |
112 |
> |
/* load RIF if rtrace */ |
113 |
> |
if (ncprocs) |
114 |
> |
getradfile(); |
115 |
|
|
116 |
|
if (hdlist[0] == NULL) { /* create new holodeck */ |
117 |
|
HDGRID hdg[HDMAX]; |
203 |
|
maxdisk = 0; |
204 |
|
else |
205 |
|
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
200 |
– |
/* record end time */ |
201 |
– |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
202 |
– |
endtime = 0; |
203 |
– |
else |
204 |
– |
endtime = starttime + vflt(TIME)*3600. + .5; |
206 |
|
/* set up memory cache */ |
207 |
|
if (outdev == NULL) |
208 |
|
hdcachesize = 0; /* manual flushing */ |
214 |
|
if (*s && freopen(s, "a", stderr) == NULL) |
215 |
|
quit(2); |
216 |
|
} |
217 |
+ |
/* mark the starting time */ |
218 |
+ |
starttime = time(NULL); |
219 |
+ |
/* compute end time */ |
220 |
+ |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
221 |
+ |
endtime = 0; |
222 |
+ |
else |
223 |
+ |
endtime = starttime + vflt(TIME)*3600. + .5; |
224 |
|
/* start rtrace */ |
225 |
|
if (ncprocs > 0) { |
226 |
|
i = start_rtrace(); |
234 |
|
freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); |
235 |
|
if (freepacks == NULL) |
236 |
|
goto memerr; |
237 |
+ |
if (!(avgqlen = i/nprocs)) /* record mean queue length */ |
238 |
+ |
avgqlen = 1; |
239 |
|
freepacks[--i].nr = 0; |
240 |
|
freepacks[i].next = NULL; |
241 |
|
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
274 |
|
{ |
275 |
|
static int idle = 0; |
276 |
|
PACKET *pl = NULL, *plend; |
277 |
+ |
int pksiz; |
278 |
|
register PACKET *p; |
279 |
|
time_t t; |
269 |
– |
long l; |
280 |
|
/* check display */ |
281 |
|
if (nprocs <= 0) |
282 |
|
idle = 1; |
293 |
|
done_rtrace(); |
294 |
|
return(1); /* comes back */ |
295 |
|
} |
296 |
< |
/* check time */ |
287 |
< |
if (endtime > 0 || reporttime > 0) |
288 |
< |
t = time(NULL); |
296 |
> |
t = time(NULL); /* check time */ |
297 |
|
if (endtime > 0 && t >= endtime) { |
298 |
|
error(WARNING, "time limit exceeded"); |
299 |
|
done_rtrace(); |
301 |
|
} |
302 |
|
if (reporttime > 0 && t >= reporttime) |
303 |
|
report(t); |
304 |
+ |
/* figure out good packet size */ |
305 |
+ |
#if MAXQTIME |
306 |
+ |
pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); |
307 |
+ |
if (pksiz < 1) |
308 |
+ |
pksiz = 1; |
309 |
+ |
else if (pksiz > RPACKSIZ) |
310 |
+ |
#endif |
311 |
+ |
pksiz = RPACKSIZ; |
312 |
|
idle = 0; /* get packets to process */ |
313 |
|
while (freepacks != NULL) { |
314 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
315 |
< |
if (!next_packet(p)) { |
315 |
> |
if (!next_packet(p, pksiz)) { |
316 |
|
p->next = freepacks; freepacks = p; |
317 |
|
idle = 1; |
318 |
|
break; |
497 |
|
if (outdev != NULL) /* display it */ |
498 |
|
disp_packet((PACKHEAD *)p); |
499 |
|
if (hdcachesize <= 0) /* manual flushing */ |
500 |
< |
n2flush += p->nr; |
500 |
> |
n2flush++; |
501 |
|
nraysdone += p->nr; |
502 |
|
npacksdone++; |
503 |
+ |
p->nr = 0; |
504 |
|
} |
505 |
< |
p->nr = 0; /* push onto free list */ |
489 |
< |
p->next = freepacks; |
505 |
> |
p->next = freepacks; /* push onto free list */ |
506 |
|
freepacks = p; |
507 |
|
} |
508 |
< |
if (n2flush > 1024*RPACKSIZ*nprocs) { |
508 |
> |
if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { |
509 |
|
hdflush(NULL); /* flush holodeck buffers */ |
510 |
|
n2flush = 0; |
511 |
|
} |