1 |
< |
/* Copyright (c) 1998 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 FRAGWARN |
18 |
+ |
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
19 |
+ |
#endif |
20 |
|
#ifndef MAXQTIME |
21 |
|
#define MAXQTIME 5 /* target maximum seconds in queue */ |
22 |
|
#endif |
23 |
+ |
/* manual cache flushing frequency */ |
24 |
+ |
#ifndef RTFLUSH |
25 |
+ |
#if MAXQTIME |
26 |
+ |
#define RTFLUSH (300/MAXQTIME*totqlen) /* <= 5 minutes */ |
27 |
+ |
#else |
28 |
+ |
#define RTFLUSH (50*totqlen) /* just guess */ |
29 |
+ |
#endif |
30 |
+ |
#endif |
31 |
|
/* the following must be consistent with rholo.h */ |
32 |
|
int NVARS = NRHVARS; /* total number of variables */ |
33 |
|
|
60 |
|
long npacksdone = 0L; /* number of packets done */ |
61 |
|
|
62 |
|
PACKET *freepacks; /* available packets */ |
63 |
< |
int totqlen; /* maximum queue length when full */ |
63 |
> |
int totqlen; /* maximum queue length (number of packets) */ |
64 |
|
|
65 |
|
char *sigerr[NSIG]; /* signal error messages */ |
66 |
|
|
155 |
|
{ |
156 |
|
static int gotsig = 0; |
157 |
|
|
158 |
< |
if (gotsig++) /* two signals and we're gone! */ |
158 |
> |
if (gotsig > 1) /* we're going as fast as we can! */ |
159 |
> |
return; |
160 |
> |
if (gotsig++) { /* two signals and we split */ |
161 |
> |
hdsync(NULL, 0); /* don't leave w/o saying goodbye */ |
162 |
|
_exit(signo); |
163 |
< |
|
164 |
< |
alarm(60); /* allow 60 seconds to clean up */ |
151 |
< |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
163 |
> |
} |
164 |
> |
alarm(300); /* allow 5 minutes to clean up */ |
165 |
|
eputs("signal - "); |
166 |
|
eputs(sigerr[signo]); |
167 |
|
eputs("\n"); |
282 |
|
|
283 |
|
rholo() /* holodeck main loop */ |
284 |
|
{ |
285 |
+ |
static long nextfragwarn = 100*(1L<<20); |
286 |
|
static int idle = 0; |
287 |
|
PACKET *pl = NULL, *plend; |
288 |
+ |
long fsiz; |
289 |
|
int pksiz; |
290 |
|
register PACKET *p; |
291 |
|
time_t t; |
299 |
|
return(1); |
300 |
|
} else if (idle) |
301 |
|
return(0); /* all done */ |
302 |
< |
/* check file size */ |
303 |
< |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
302 |
> |
fsiz = hdfilen(hdlist[0]->fd); /* check file size */ |
303 |
> |
if (maxdisk > 0 && fsiz >= maxdisk) { |
304 |
|
error(WARNING, "file limit exceeded"); |
305 |
|
done_rtrace(); |
306 |
|
return(1); /* comes back */ |
307 |
|
} |
308 |
+ |
#if FRAGWARN |
309 |
+ |
if (fsiz >= nextfragwarn && |
310 |
+ |
(fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { |
311 |
+ |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
312 |
+ |
100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); |
313 |
+ |
error(WARNING, errmsg); |
314 |
+ |
nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ |
315 |
+ |
} |
316 |
+ |
#endif |
317 |
|
t = time(NULL); /* check time */ |
318 |
|
if (endtime > 0 && t >= endtime) { |
319 |
|
error(WARNING, "time limit exceeded"); |
323 |
|
if (reporttime > 0 && t >= reporttime) |
324 |
|
report(t); |
325 |
|
/* figure out good packet size */ |
326 |
+ |
pksiz = RPACKSIZ; |
327 |
|
#if MAXQTIME |
328 |
< |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
329 |
< |
if (pksiz < 1) |
330 |
< |
pksiz = 1; |
331 |
< |
else if (pksiz > RPACKSIZ) |
328 |
> |
if (!chunkycmp) { |
329 |
> |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
330 |
> |
if (pksiz < 1) pksiz = 1; |
331 |
> |
else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ; |
332 |
> |
} |
333 |
|
#endif |
308 |
– |
pksiz = RPACKSIZ; |
334 |
|
idle = 0; /* get packets to process */ |
335 |
|
while (freepacks != NULL) { |
336 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
522 |
|
p->nr*sizeof(RAYVAL)); |
523 |
|
if (outdev != NULL) /* display it */ |
524 |
|
disp_packet((PACKHEAD *)p); |
525 |
< |
if (hdcachesize <= 0) /* manual flushing */ |
525 |
> |
if (hdcachesize <= 0) |
526 |
|
n2flush++; |
527 |
|
nraysdone += p->nr; |
528 |
|
npacksdone++; |
531 |
|
p->next = freepacks; /* push onto free list */ |
532 |
|
freepacks = p; |
533 |
|
} |
534 |
< |
#if MAXQTIME |
535 |
< |
if (n2flush > 300/MAXQTIME*totqlen) { |
536 |
< |
#else |
512 |
< |
if (n2flush > 50*totqlen) { |
513 |
< |
#endif |
514 |
< |
if (outdev == NULL) |
515 |
< |
hdflush(NULL); /* flush holodeck buffers */ |
534 |
> |
if (n2flush > RTFLUSH) { |
535 |
> |
if (outdev != NULL) |
536 |
> |
hdsync(NULL, 1); |
537 |
|
else |
538 |
< |
hdsync(NULL, 1); /* sync holodeck file */ |
538 |
> |
hdflush(NULL); |
539 |
|
n2flush = 0; |
540 |
|
} |
541 |
|
} |