1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
14 |
|
#include <sys/types.h> |
15 |
|
#include <sys/stat.h> |
16 |
|
|
17 |
+ |
#ifndef RTFLUSH |
18 |
+ |
#define RTFLUSH 0 /* flush one at a time in batch */ |
19 |
+ |
#endif |
20 |
+ |
#ifndef FRAGWARN |
21 |
+ |
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
22 |
+ |
#endif |
23 |
+ |
#ifndef MAXQTIME |
24 |
+ |
#define MAXQTIME 5 /* target maximum seconds in queue */ |
25 |
+ |
#endif |
26 |
|
/* the following must be consistent with rholo.h */ |
27 |
|
int NVARS = NRHVARS; /* total number of variables */ |
28 |
|
|
32 |
|
char *hdkfile; /* holodeck file name */ |
33 |
|
char froot[256]; /* root file name */ |
34 |
|
|
26 |
– |
int nowarn = 0; /* turn warnings off? */ |
27 |
– |
|
35 |
|
int ncprocs = 0; /* desired number of compute processes */ |
36 |
|
|
37 |
|
char *outdev = NULL; /* output device name */ |
55 |
|
long npacksdone = 0L; /* number of packets done */ |
56 |
|
|
57 |
|
PACKET *freepacks; /* available packets */ |
58 |
+ |
int totqlen; /* maximum queue length when full */ |
59 |
|
|
60 |
|
char *sigerr[NSIG]; /* signal error messages */ |
61 |
|
|
62 |
+ |
extern int nowarn; /* turn warnings off? */ |
63 |
+ |
|
64 |
|
extern time_t time(); |
65 |
|
|
66 |
|
|
69 |
|
char *argv[]; |
70 |
|
{ |
71 |
|
int i; |
72 |
< |
/* mark start time */ |
63 |
< |
starttime = time(NULL); |
72 |
> |
|
73 |
|
initurand(16384); /* initialize urand */ |
74 |
|
progname = argv[0]; /* get arguments */ |
75 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
97 |
|
goto userr; |
98 |
|
} |
99 |
|
/* get root file name */ |
100 |
+ |
if (i >= argc) |
101 |
+ |
goto userr; |
102 |
|
rootname(froot, hdkfile=argv[i++]); |
103 |
|
/* load variables? */ |
104 |
|
if (i < argc) |
115 |
|
} |
116 |
|
/* check settings */ |
117 |
|
checkvalues(); |
118 |
< |
/* load RIF if any */ |
118 |
> |
/* load rad input file */ |
119 |
|
getradfile(); |
120 |
|
|
121 |
|
if (hdlist[0] == NULL) { /* create new holodeck */ |
150 |
|
{ |
151 |
|
static int gotsig = 0; |
152 |
|
|
153 |
< |
if (gotsig++) /* two signals and we're gone! */ |
153 |
> |
if (gotsig > 1) /* we're going as fast as we can! */ |
154 |
> |
return; |
155 |
> |
if (gotsig++) { /* two signals and we split */ |
156 |
> |
hdsync(NULL, 0); /* don't leave w/o saying goodbye */ |
157 |
|
_exit(signo); |
158 |
< |
|
159 |
< |
alarm(60); /* allow 60 seconds to clean up */ |
146 |
< |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
158 |
> |
} |
159 |
> |
alarm(300); /* allow 5 minutes to clean up */ |
160 |
|
eputs("signal - "); |
161 |
|
eputs(sigerr[signo]); |
162 |
|
eputs("\n"); |
183 |
|
if (fstat(fd, &stbuf) < 0) |
184 |
|
error(SYSTEM, "cannot stat open holodeck file"); |
185 |
|
mod &= stbuf.st_mode; /* always more restrictive */ |
186 |
< |
if (mod == stbuf.st_mode) |
186 |
> |
if (mod == (stbuf.st_mode & 0777)) |
187 |
|
return(-1); /* already set */ |
188 |
|
/* else change it */ |
189 |
|
if (fchmod(fd, mod) < 0) { |
210 |
|
maxdisk = 0; |
211 |
|
else |
212 |
|
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; |
213 |
|
/* set up memory cache */ |
214 |
|
if (outdev == NULL) |
215 |
|
hdcachesize = 0; /* manual flushing */ |
221 |
|
if (*s && freopen(s, "a", stderr) == NULL) |
222 |
|
quit(2); |
223 |
|
} |
224 |
+ |
/* mark the starting time */ |
225 |
+ |
starttime = time(NULL); |
226 |
+ |
/* compute end time */ |
227 |
+ |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
228 |
+ |
endtime = 0; |
229 |
+ |
else |
230 |
+ |
endtime = starttime + vflt(TIME)*3600. + .5; |
231 |
|
/* start rtrace */ |
232 |
|
if (ncprocs > 0) { |
233 |
< |
i = start_rtrace(); |
233 |
> |
totqlen = i = start_rtrace(); |
234 |
|
if (i < 1) |
235 |
|
error(USER, "cannot start rtrace process(es)"); |
236 |
|
if (vdef(REPORT)) { /* make first report */ |
277 |
|
|
278 |
|
rholo() /* holodeck main loop */ |
279 |
|
{ |
280 |
+ |
static long nextfragwarn = 100*(1L<<20); |
281 |
|
static int idle = 0; |
282 |
|
PACKET *pl = NULL, *plend; |
283 |
+ |
long fsiz; |
284 |
+ |
int pksiz; |
285 |
|
register PACKET *p; |
286 |
|
time_t t; |
269 |
– |
long l; |
287 |
|
/* check display */ |
288 |
|
if (nprocs <= 0) |
289 |
|
idle = 1; |
294 |
|
return(1); |
295 |
|
} else if (idle) |
296 |
|
return(0); /* all done */ |
297 |
< |
/* check file size */ |
298 |
< |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
297 |
> |
fsiz = hdfilen(hdlist[0]->fd); /* check file size */ |
298 |
> |
if (maxdisk > 0 && fsiz >= maxdisk) { |
299 |
|
error(WARNING, "file limit exceeded"); |
300 |
|
done_rtrace(); |
301 |
|
return(1); /* comes back */ |
302 |
|
} |
303 |
< |
/* check time */ |
304 |
< |
if (endtime > 0 || reporttime > 0) |
305 |
< |
t = time(NULL); |
303 |
> |
#if FRAGWARN |
304 |
> |
if (fsiz >= nextfragwarn && |
305 |
> |
(fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { |
306 |
> |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
307 |
> |
100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); |
308 |
> |
error(WARNING, errmsg); |
309 |
> |
nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ |
310 |
> |
} |
311 |
> |
#endif |
312 |
> |
t = time(NULL); /* check time */ |
313 |
|
if (endtime > 0 && t >= endtime) { |
314 |
|
error(WARNING, "time limit exceeded"); |
315 |
|
done_rtrace(); |
317 |
|
} |
318 |
|
if (reporttime > 0 && t >= reporttime) |
319 |
|
report(t); |
320 |
+ |
/* figure out good packet size */ |
321 |
+ |
pksiz = RPACKSIZ; |
322 |
+ |
#if MAXQTIME |
323 |
+ |
if (!chunkycmp) { |
324 |
+ |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
325 |
+ |
if (pksiz < 1) pksiz = 1; |
326 |
+ |
else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ; |
327 |
+ |
} |
328 |
+ |
#endif |
329 |
|
idle = 0; /* get packets to process */ |
330 |
|
while (freepacks != NULL) { |
331 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
332 |
< |
if (!next_packet(p)) { |
332 |
> |
if (!next_packet(p, pksiz)) { |
333 |
|
p->next = freepacks; freepacks = p; |
334 |
|
idle = 1; |
335 |
|
break; |
350 |
|
extern char *atos(); |
351 |
|
register int i; |
352 |
|
int n; |
353 |
< |
double len[3], maxlen, d; |
353 |
> |
double len[3], d; |
354 |
|
char buf[64]; |
355 |
|
|
356 |
|
if (!vdef(SECTION)) { |
384 |
|
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
385 |
|
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
386 |
|
badvalue(SECTION); |
354 |
– |
maxlen = 0.; |
387 |
|
for (i = 0; i < 3; i++) |
388 |
< |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
389 |
< |
maxlen = len[i]; |
390 |
< |
if (!vdef(GRID)) |
391 |
< |
d = 0.125*maxlen; |
392 |
< |
else if ((d = vflt(GRID)) <= FTINY) |
388 |
> |
len[i] = VLEN(gp->xv[i]); |
389 |
> |
if (!vdef(GRID)) { |
390 |
> |
d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] + |
391 |
> |
len[2]*len[2] + 4*len[1]*len[2]) |
392 |
> |
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
393 |
> |
+ 4*len[0]*len[1]*len[2]*len[2] ); |
394 |
> |
d = sqrt(sqrt(d)); |
395 |
> |
} else if ((d = vflt(GRID)) <= FTINY) |
396 |
|
badvalue(GRID); |
397 |
|
for (i = 0; i < 3; i++) |
398 |
|
if (gp->grid[i] <= 0) |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
+ |
int |
444 |
|
headline(s) /* process information header line */ |
445 |
|
char *s; |
446 |
|
{ |
454 |
|
HOLOFMT, hdkfile, FMTSTR, fmt); |
455 |
|
error(USER, errmsg); |
456 |
|
} |
457 |
< |
return; |
457 |
> |
return(0); |
458 |
|
} |
459 |
|
for (cp = s; *cp; cp++) /* take off any comments */ |
460 |
|
if (*cp == '#') { |
462 |
|
break; |
463 |
|
} |
464 |
|
setvariable(s, matchvar); /* don't flag errors */ |
465 |
+ |
return(0); |
466 |
|
} |
467 |
|
|
468 |
|
|
475 |
|
int4 nextloc; |
476 |
|
/* open holodeck file */ |
477 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
478 |
< |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
479 |
< |
ncprocs>0 ? "appending" : "reading"); |
478 |
> |
sprintf(errmsg, "cannot %s \"%s\"", |
479 |
> |
ncprocs>0 ? "append" : "read", hdkfile); |
480 |
|
error(SYSTEM, errmsg); |
481 |
|
} |
482 |
|
/* load variables from header */ |
517 |
|
p->nr*sizeof(RAYVAL)); |
518 |
|
if (outdev != NULL) /* display it */ |
519 |
|
disp_packet((PACKHEAD *)p); |
520 |
< |
if (hdcachesize <= 0) /* manual flushing */ |
521 |
< |
n2flush += p->nr; |
520 |
> |
if (hdcachesize <= 0) { |
521 |
> |
#if RTFLUSH |
522 |
> |
if (outdev == NULL) |
523 |
> |
hdfreebeam(hdlist[p->hd], p->bi); |
524 |
> |
#endif |
525 |
> |
n2flush++; |
526 |
> |
} |
527 |
|
nraysdone += p->nr; |
528 |
|
npacksdone++; |
529 |
+ |
p->nr = 0; |
530 |
|
} |
531 |
< |
p->nr = 0; /* push onto free list */ |
489 |
< |
p->next = freepacks; |
531 |
> |
p->next = freepacks; /* push onto free list */ |
532 |
|
freepacks = p; |
533 |
|
} |
534 |
< |
if (n2flush > 1024*RPACKSIZ*nprocs) { |
535 |
< |
hdflush(NULL); /* flush holodeck buffers */ |
534 |
> |
#if MAXQTIME |
535 |
> |
if (n2flush > 300/MAXQTIME*totqlen) { |
536 |
> |
#else |
537 |
> |
if (n2flush > 50*totqlen) { |
538 |
> |
#endif |
539 |
> |
#if RTFLUSH |
540 |
> |
hdsync(NULL, outdev!=NULL); /* sync beams & directories */ |
541 |
> |
#else |
542 |
> |
if (outdev != NULL) |
543 |
> |
hdsync(NULL, 1); |
544 |
> |
else |
545 |
> |
hdflush(NULL); |
546 |
> |
#endif |
547 |
|
n2flush = 0; |
548 |
|
} |
549 |
|
} |
588 |
|
fflush(stderr); |
589 |
|
midline = 0; |
590 |
|
} |
538 |
– |
} |
539 |
– |
|
540 |
– |
|
541 |
– |
wputs(s) /* put warning string to stderr */ |
542 |
– |
char *s; |
543 |
– |
{ |
544 |
– |
if (!nowarn) |
545 |
– |
eputs(s); |
591 |
|
} |
592 |
|
|
593 |
|
|