1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 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 FRAGWARN |
18 |
+ |
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
19 |
+ |
#endif |
20 |
|
#ifndef MAXQTIME |
21 |
|
#define MAXQTIME 5 /* target maximum seconds in queue */ |
22 |
|
#endif |
29 |
|
char *hdkfile; /* holodeck file name */ |
30 |
|
char froot[256]; /* root file name */ |
31 |
|
|
29 |
– |
int nowarn = 0; /* turn warnings off? */ |
30 |
– |
|
32 |
|
int ncprocs = 0; /* desired number of compute processes */ |
33 |
|
|
34 |
|
char *outdev = NULL; /* output device name */ |
52 |
|
long npacksdone = 0L; /* number of packets done */ |
53 |
|
|
54 |
|
PACKET *freepacks; /* available packets */ |
55 |
< |
int avgqlen; /* average queue length when full */ |
55 |
> |
int totqlen; /* maximum queue length when full */ |
56 |
|
|
57 |
|
char *sigerr[NSIG]; /* signal error messages */ |
58 |
|
|
59 |
+ |
extern int nowarn; /* turn warnings off? */ |
60 |
+ |
|
61 |
|
extern time_t time(); |
62 |
|
|
63 |
|
|
112 |
|
} |
113 |
|
/* check settings */ |
114 |
|
checkvalues(); |
115 |
< |
/* load RIF if rtrace */ |
116 |
< |
if (ncprocs) |
114 |
< |
getradfile(); |
115 |
> |
/* load rad input file */ |
116 |
> |
getradfile(); |
117 |
|
|
118 |
|
if (hdlist[0] == NULL) { /* create new holodeck */ |
119 |
|
HDGRID hdg[HDMAX]; |
150 |
|
if (gotsig++) /* two signals and we're gone! */ |
151 |
|
_exit(signo); |
152 |
|
|
153 |
< |
alarm(60); /* allow 60 seconds to clean up */ |
153 |
> |
alarm(120); /* allow 2 minutes to clean up */ |
154 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
155 |
|
eputs("signal - "); |
156 |
|
eputs(sigerr[signo]); |
178 |
|
if (fstat(fd, &stbuf) < 0) |
179 |
|
error(SYSTEM, "cannot stat open holodeck file"); |
180 |
|
mod &= stbuf.st_mode; /* always more restrictive */ |
181 |
< |
if (mod == stbuf.st_mode) |
181 |
> |
if (mod == (stbuf.st_mode & 0777)) |
182 |
|
return(-1); /* already set */ |
183 |
|
/* else change it */ |
184 |
|
if (fchmod(fd, mod) < 0) { |
225 |
|
endtime = starttime + vflt(TIME)*3600. + .5; |
226 |
|
/* start rtrace */ |
227 |
|
if (ncprocs > 0) { |
228 |
< |
i = start_rtrace(); |
228 |
> |
totqlen = i = start_rtrace(); |
229 |
|
if (i < 1) |
230 |
|
error(USER, "cannot start rtrace process(es)"); |
231 |
|
if (vdef(REPORT)) { /* make first report */ |
236 |
|
freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); |
237 |
|
if (freepacks == NULL) |
238 |
|
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)) { |
272 |
|
|
273 |
|
rholo() /* holodeck main loop */ |
274 |
|
{ |
275 |
+ |
static long nextfragwarn = 100*(1L<<20); |
276 |
|
static int idle = 0; |
277 |
|
PACKET *pl = NULL, *plend; |
278 |
+ |
long fsiz; |
279 |
|
int pksiz; |
280 |
|
register PACKET *p; |
281 |
|
time_t t; |
289 |
|
return(1); |
290 |
|
} else if (idle) |
291 |
|
return(0); /* all done */ |
292 |
< |
/* check file size */ |
293 |
< |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
292 |
> |
fsiz = hdfilen(hdlist[0]->fd); /* check file size */ |
293 |
> |
if (maxdisk > 0 && fsiz >= maxdisk) { |
294 |
|
error(WARNING, "file limit exceeded"); |
295 |
|
done_rtrace(); |
296 |
|
return(1); /* comes back */ |
297 |
|
} |
298 |
+ |
#if FRAGWARN |
299 |
+ |
if (fsiz >= nextfragwarn && |
300 |
+ |
(fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { |
301 |
+ |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
302 |
+ |
100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); |
303 |
+ |
error(WARNING, errmsg); |
304 |
+ |
nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ |
305 |
+ |
} |
306 |
+ |
#endif |
307 |
|
t = time(NULL); /* check time */ |
308 |
|
if (endtime > 0 && t >= endtime) { |
309 |
|
error(WARNING, "time limit exceeded"); |
314 |
|
report(t); |
315 |
|
/* figure out good packet size */ |
316 |
|
#if MAXQTIME |
317 |
< |
pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); |
317 |
> |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
318 |
|
if (pksiz < 1) |
319 |
|
pksiz = 1; |
320 |
|
else if (pksiz > RPACKSIZ) |
344 |
|
extern char *atos(); |
345 |
|
register int i; |
346 |
|
int n; |
347 |
< |
double len[3], maxlen, d; |
347 |
> |
double len[3], d; |
348 |
|
char buf[64]; |
349 |
|
|
350 |
|
if (!vdef(SECTION)) { |
378 |
|
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
379 |
|
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
380 |
|
badvalue(SECTION); |
370 |
– |
maxlen = 0.; |
381 |
|
for (i = 0; i < 3; i++) |
382 |
< |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
383 |
< |
maxlen = len[i]; |
384 |
< |
if (!vdef(GRID)) |
385 |
< |
d = 0.125*maxlen; |
386 |
< |
else if ((d = vflt(GRID)) <= FTINY) |
382 |
> |
len[i] = VLEN(gp->xv[i]); |
383 |
> |
if (!vdef(GRID)) { |
384 |
> |
d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] + |
385 |
> |
len[2]*len[2] + 4*len[1]*len[2]) |
386 |
> |
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
387 |
> |
+ 4*len[0]*len[1]*len[2]*len[2] ); |
388 |
> |
d = sqrt(sqrt(d)); |
389 |
> |
} else if ((d = vflt(GRID)) <= FTINY) |
390 |
|
badvalue(GRID); |
391 |
|
for (i = 0; i < 3; i++) |
392 |
|
if (gp->grid[i] <= 0) |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
+ |
int |
438 |
|
headline(s) /* process information header line */ |
439 |
|
char *s; |
440 |
|
{ |
448 |
|
HOLOFMT, hdkfile, FMTSTR, fmt); |
449 |
|
error(USER, errmsg); |
450 |
|
} |
451 |
< |
return; |
451 |
> |
return(0); |
452 |
|
} |
453 |
|
for (cp = s; *cp; cp++) /* take off any comments */ |
454 |
|
if (*cp == '#') { |
456 |
|
break; |
457 |
|
} |
458 |
|
setvariable(s, matchvar); /* don't flag errors */ |
459 |
+ |
return(0); |
460 |
|
} |
461 |
|
|
462 |
|
|
469 |
|
int4 nextloc; |
470 |
|
/* open holodeck file */ |
471 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
472 |
< |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
473 |
< |
ncprocs>0 ? "appending" : "reading"); |
472 |
> |
sprintf(errmsg, "cannot %s \"%s\"", |
473 |
> |
ncprocs>0 ? "append" : "read", hdkfile); |
474 |
|
error(SYSTEM, errmsg); |
475 |
|
} |
476 |
|
/* load variables from header */ |
520 |
|
p->next = freepacks; /* push onto free list */ |
521 |
|
freepacks = p; |
522 |
|
} |
523 |
< |
if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { |
524 |
< |
hdflush(NULL); /* flush holodeck buffers */ |
523 |
> |
#if MAXQTIME |
524 |
> |
if (n2flush > 300/MAXQTIME*totqlen) { |
525 |
> |
#else |
526 |
> |
if (n2flush > 50*totqlen) { |
527 |
> |
#endif |
528 |
> |
if (outdev == NULL) |
529 |
> |
hdflush(NULL); /* flush holodeck buffers */ |
530 |
> |
else |
531 |
> |
hdsync(NULL, 1); /* sync holodeck file */ |
532 |
|
n2flush = 0; |
533 |
|
} |
534 |
|
} |
573 |
|
fflush(stderr); |
574 |
|
midline = 0; |
575 |
|
} |
554 |
– |
} |
555 |
– |
|
556 |
– |
|
557 |
– |
wputs(s) /* put warning string to stderr */ |
558 |
– |
char *s; |
559 |
– |
{ |
560 |
– |
if (!nowarn) |
561 |
– |
eputs(s); |
576 |
|
} |
577 |
|
|
578 |
|
|