| 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) |
| 202 |
|
maxdisk = 0; |
| 203 |
|
else |
| 204 |
|
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; |
| 205 |
|
/* set up memory cache */ |
| 206 |
|
if (outdev == NULL) |
| 207 |
|
hdcachesize = 0; /* manual flushing */ |
| 213 |
|
if (*s && freopen(s, "a", stderr) == NULL) |
| 214 |
|
quit(2); |
| 215 |
|
} |
| 216 |
+ |
/* mark the starting time */ |
| 217 |
+ |
starttime = time(NULL); |
| 218 |
+ |
/* compute end time */ |
| 219 |
+ |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
| 220 |
+ |
endtime = 0; |
| 221 |
+ |
else |
| 222 |
+ |
endtime = starttime + vflt(TIME)*3600. + .5; |
| 223 |
|
/* start rtrace */ |
| 224 |
|
if (ncprocs > 0) { |
| 225 |
|
i = start_rtrace(); |
| 233 |
|
freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); |
| 234 |
|
if (freepacks == NULL) |
| 235 |
|
goto memerr; |
| 236 |
+ |
if (!(avgqlen = i/nprocs)) /* record mean queue length */ |
| 237 |
+ |
avgqlen = 1; |
| 238 |
|
freepacks[--i].nr = 0; |
| 239 |
|
freepacks[i].next = NULL; |
| 240 |
|
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
| 273 |
|
{ |
| 274 |
|
static int idle = 0; |
| 275 |
|
PACKET *pl = NULL, *plend; |
| 276 |
+ |
int pksiz; |
| 277 |
|
register PACKET *p; |
| 278 |
|
time_t t; |
| 269 |
– |
long l; |
| 279 |
|
/* check display */ |
| 280 |
|
if (nprocs <= 0) |
| 281 |
|
idle = 1; |
| 292 |
|
done_rtrace(); |
| 293 |
|
return(1); /* comes back */ |
| 294 |
|
} |
| 295 |
< |
/* check time */ |
| 287 |
< |
if (endtime > 0 || reporttime > 0) |
| 288 |
< |
t = time(NULL); |
| 295 |
> |
t = time(NULL); /* check time */ |
| 296 |
|
if (endtime > 0 && t >= endtime) { |
| 297 |
|
error(WARNING, "time limit exceeded"); |
| 298 |
|
done_rtrace(); |
| 300 |
|
} |
| 301 |
|
if (reporttime > 0 && t >= reporttime) |
| 302 |
|
report(t); |
| 303 |
+ |
/* figure out good packet size */ |
| 304 |
+ |
#if MAXQTIME |
| 305 |
+ |
pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); |
| 306 |
+ |
if (pksiz < 1) |
| 307 |
+ |
pksiz = 1; |
| 308 |
+ |
else if (pksiz > RPACKSIZ) |
| 309 |
+ |
#endif |
| 310 |
+ |
pksiz = RPACKSIZ; |
| 311 |
|
idle = 0; /* get packets to process */ |
| 312 |
|
while (freepacks != NULL) { |
| 313 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
| 314 |
< |
if (!next_packet(p)) { |
| 314 |
> |
if (!next_packet(p, pksiz)) { |
| 315 |
|
p->next = freepacks; freepacks = p; |
| 316 |
|
idle = 1; |
| 317 |
|
break; |
| 496 |
|
if (outdev != NULL) /* display it */ |
| 497 |
|
disp_packet((PACKHEAD *)p); |
| 498 |
|
if (hdcachesize <= 0) /* manual flushing */ |
| 499 |
< |
n2flush += p->nr; |
| 499 |
> |
n2flush++; |
| 500 |
|
nraysdone += p->nr; |
| 501 |
|
npacksdone++; |
| 502 |
+ |
p->nr = 0; |
| 503 |
|
} |
| 504 |
< |
p->nr = 0; /* push onto free list */ |
| 489 |
< |
p->next = freepacks; |
| 504 |
> |
p->next = freepacks; /* push onto free list */ |
| 505 |
|
freepacks = p; |
| 506 |
|
} |
| 507 |
< |
if (n2flush > 512*RPACKSIZ*nprocs) { |
| 507 |
> |
if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { |
| 508 |
|
hdflush(NULL); /* flush holodeck buffers */ |
| 509 |
|
n2flush = 0; |
| 510 |
|
} |