1 |
< |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
11 |
|
#include "rholo.h" |
12 |
|
#include "random.h" |
13 |
|
#include <signal.h> |
14 |
– |
#include <sys/types.h> |
14 |
|
#include <sys/stat.h> |
15 |
|
|
16 |
+ |
#ifndef FRAGWARN |
17 |
+ |
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
18 |
+ |
#endif |
19 |
|
#ifndef MAXQTIME |
20 |
|
#define MAXQTIME 5 /* target maximum seconds in queue */ |
21 |
|
#endif |
22 |
+ |
/* manual cache flushing frequency */ |
23 |
+ |
#ifndef RTFLUSH |
24 |
+ |
#if MAXQTIME |
25 |
+ |
#define RTFLUSH (300/MAXQTIME*totqlen) /* <= 5 minutes */ |
26 |
+ |
#else |
27 |
+ |
#define RTFLUSH (50*totqlen) /* just guess */ |
28 |
+ |
#endif |
29 |
+ |
#endif |
30 |
|
/* the following must be consistent with rholo.h */ |
31 |
|
int NVARS = NRHVARS; /* total number of variables */ |
32 |
|
|
59 |
|
long npacksdone = 0L; /* number of packets done */ |
60 |
|
|
61 |
|
PACKET *freepacks; /* available packets */ |
62 |
< |
int totqlen; /* maximum queue length when full */ |
62 |
> |
int totqlen; /* maximum queue length (number of packets) */ |
63 |
|
|
64 |
|
char *sigerr[NSIG]; /* signal error messages */ |
65 |
|
|
154 |
|
{ |
155 |
|
static int gotsig = 0; |
156 |
|
|
157 |
< |
if (gotsig++) /* two signals and we're gone! */ |
157 |
> |
if (gotsig > 1) /* we're going as fast as we can! */ |
158 |
> |
return; |
159 |
> |
if (gotsig++) { /* two signals and we split */ |
160 |
> |
hdsync(NULL, 0); /* don't leave w/o saying goodbye */ |
161 |
|
_exit(signo); |
162 |
< |
|
163 |
< |
alarm(60); /* allow 60 seconds to clean up */ |
151 |
< |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
162 |
> |
} |
163 |
> |
alarm(300); /* allow 5 minutes to clean up */ |
164 |
|
eputs("signal - "); |
165 |
|
eputs(sigerr[signo]); |
166 |
|
eputs("\n"); |
216 |
|
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
217 |
|
/* set up memory cache */ |
218 |
|
if (outdev == NULL) |
219 |
< |
hdcachesize = 0; /* manual flushing */ |
219 |
> |
hdcachesize = 0; /* manual flushing */ |
220 |
|
else if (vdef(CACHE)) |
221 |
|
hdcachesize = 1024.*1024.*vflt(CACHE); |
222 |
|
/* open report file */ |
271 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
272 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
273 |
|
#endif |
274 |
< |
/* protect holodeck file */ |
274 |
> |
/* protect holodeck file */ |
275 |
|
orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); |
276 |
|
return; |
277 |
|
memerr: |
281 |
|
|
282 |
|
rholo() /* holodeck main loop */ |
283 |
|
{ |
284 |
+ |
static long nextfragwarn = 100*(1L<<20); |
285 |
|
static int idle = 0; |
286 |
|
PACKET *pl = NULL, *plend; |
287 |
+ |
long fsiz; |
288 |
|
int pksiz; |
289 |
|
register PACKET *p; |
290 |
|
time_t t; |
298 |
|
return(1); |
299 |
|
} else if (idle) |
300 |
|
return(0); /* all done */ |
301 |
< |
/* check file size */ |
302 |
< |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
301 |
> |
fsiz = hdfilen(hdlist[0]->fd); /* check file size */ |
302 |
> |
if (maxdisk > 0 && fsiz >= maxdisk) { |
303 |
|
error(WARNING, "file limit exceeded"); |
304 |
|
done_rtrace(); |
305 |
|
return(1); /* comes back */ |
306 |
|
} |
307 |
+ |
#if FRAGWARN |
308 |
+ |
if (fsiz >= nextfragwarn && |
309 |
+ |
(fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { |
310 |
+ |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
311 |
+ |
100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); |
312 |
+ |
error(WARNING, errmsg); |
313 |
+ |
nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ |
314 |
+ |
} |
315 |
+ |
#endif |
316 |
|
t = time(NULL); /* check time */ |
317 |
|
if (endtime > 0 && t >= endtime) { |
318 |
|
error(WARNING, "time limit exceeded"); |
322 |
|
if (reporttime > 0 && t >= reporttime) |
323 |
|
report(t); |
324 |
|
/* figure out good packet size */ |
325 |
+ |
pksiz = RPACKSIZ; |
326 |
|
#if MAXQTIME |
327 |
< |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
328 |
< |
if (pksiz < 1) |
329 |
< |
pksiz = 1; |
330 |
< |
else if (pksiz > RPACKSIZ) |
327 |
> |
if (!chunkycmp) { |
328 |
> |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
329 |
> |
if (pksiz < 1) pksiz = 1; |
330 |
> |
else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ; |
331 |
> |
} |
332 |
|
#endif |
308 |
– |
pksiz = RPACKSIZ; |
333 |
|
idle = 0; /* get packets to process */ |
334 |
|
while (freepacks != NULL) { |
335 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
391 |
|
for (i = 0; i < 3; i++) |
392 |
|
len[i] = VLEN(gp->xv[i]); |
393 |
|
if (!vdef(GRID)) { |
394 |
< |
d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] + |
394 |
> |
d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] + |
395 |
|
len[2]*len[2] + 4*len[1]*len[2]) |
396 |
|
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
397 |
|
+ 4*len[0]*len[1]*len[2]*len[2] ); |
521 |
|
p->nr*sizeof(RAYVAL)); |
522 |
|
if (outdev != NULL) /* display it */ |
523 |
|
disp_packet((PACKHEAD *)p); |
524 |
< |
if (hdcachesize <= 0) /* manual flushing */ |
524 |
> |
if (hdcachesize <= 0) |
525 |
|
n2flush++; |
526 |
|
nraysdone += p->nr; |
527 |
|
npacksdone++; |
530 |
|
p->next = freepacks; /* push onto free list */ |
531 |
|
freepacks = p; |
532 |
|
} |
533 |
< |
#if MAXQTIME |
534 |
< |
if (n2flush > 300/MAXQTIME*totqlen) { |
535 |
< |
#else |
512 |
< |
if (n2flush > 50*totqlen) { |
513 |
< |
#endif |
514 |
< |
if (outdev == NULL) |
515 |
< |
hdflush(NULL); /* flush holodeck buffers */ |
533 |
> |
if (n2flush >= RTFLUSH) { |
534 |
> |
if (outdev != NULL) |
535 |
> |
hdsync(NULL, 1); |
536 |
|
else |
537 |
< |
hdsync(NULL, 1); /* sync holodeck file */ |
537 |
> |
hdflush(NULL); |
538 |
|
n2flush = 0; |
539 |
|
} |
540 |
|
} |