ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo2l.c
(Generate patch)

Comparing ray/src/hd/rholo2l.c (file contents):
Revision 3.5 by gregl, Mon Nov 24 15:18:47 1997 UTC vs.
Revision 3.16 by schorsch, Thu Jan 1 11:21:55 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for local rtrace execution
6   */
7  
8 + #include <signal.h>
9 + #include <sys/time.h>
10 + #include <string.h>
11 +
12   #include "rholo.h"
13   #include "random.h"
14 + #include "paths.h"
15   #include "selcall.h"
16 < #include <signal.h>
15 < #include <sys/time.h>
16 > #include "rtprocess.h"
17  
18   #ifndef MAXPROC
19 < #define MAXPROC         16
19 > #define MAXPROC         64
20   #endif
21  
22 < static char     PFILE[] = "/usr/tmp/RHpersist"; /* persist file name */
22 > int     nprocs = 0;                             /* running process count */
23  
24 < static int      rtpd[MAXPROC][3];               /* process descriptors */
24 > static char     pfile[] = TEMPLATE;             /* persist file name */
25 >
26 > static SUBPROC  rtpd[MAXPROC];          /* process descriptors */
27   static float    *rtbuf = NULL;                  /* allocated i/o buffer */
28   static int      maxqlen = 0;                    /* maximum packets per queue */
26 static int      nprocs = 0;                     /* number of processes */
29  
30   static PACKET   *pqueue[MAXPROC];               /* packet queues */
31   static int      pqlen[MAXPROC];                 /* packet queue lengths */
32  
33 + static int bestout(void);
34 + static int slots_avail(void);
35 + static void queue_packet(PACKET *p);
36 + static PACKET * get_packets(int poll);
37 + static void killpersist(void);
38  
39 < int
40 < start_rtrace()                  /* start rtrace process */
39 >
40 > extern int
41 > start_rtrace(void)                      /* start rtrace process */
42   {
43          static char     buf1[8];
44          int     rmaxpack = 0;
45 <        int     psiz, npt, n;
45 >        int     psiz, n;
46                                          /* get number of processes */
47 <        if ((npt = ncprocs) <= 0)
47 >        if (ncprocs <= 0 || nprocs > 0)
48                  return(0);
49 <        if (npt > MAXPROC) {
49 >        if (ncprocs > MAXPROC) {
50                  sprintf(errmsg,
51                          "number of rtrace processes reduced from %d to %d",
52 <                                npt, MAXPROC);
52 >                                ncprocs, MAXPROC);
53                  error(WARNING, errmsg);
54 <                npt = MAXPROC;
54 >                ncprocs = MAXPROC;
55          }
56 <                                        /* add compulsory options */
57 <        rtargv[rtargc++] = "-i-";
58 <        rtargv[rtargc++] = "-I-";
59 <        rtargv[rtargc++] = "-h-";
60 <        rtargv[rtargc++] = "-ld-";
61 <        sprintf(buf1, "%d", RPACKSIZ);
62 <        rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1;
63 <        rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0";
64 <        rtargv[rtargc++] = "-fff";
65 <        rtargv[rtargc++] = "-ovL";
66 <        rtargv[rtargc++] = nowarn ? "-w-" : "-w+";
67 <        if (npt > 1) {
68 <                rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = PFILE;
56 >        if (rtargv[rtargc-1] != vval(OCTREE)) {
57 >                                                /* add compulsory options */
58 >                rtargv[rtargc++] = "-i-";
59 >                rtargv[rtargc++] = "-I-";
60 >                rtargv[rtargc++] = "-h-";
61 >                rtargv[rtargc++] = "-ld-";
62 >                sprintf(buf1, "%d", RPACKSIZ);
63 >                rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1;
64 >                rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0";
65 >                rtargv[rtargc++] = "-fff";
66 >                rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL";
67 >                if (nowarn)
68 >                        rtargv[rtargc++] = "-w-";
69 >                if (ncprocs > 1) {
70 >                        mktemp(pfile);
71 >                        rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile;
72 >                }
73 >                rtargv[rtargc++] = vval(OCTREE);
74 >                rtargv[rtargc] = NULL;
75          }
62        rtargv[rtargc++] = vval(OCTREE);
63        rtargv[rtargc] = NULL;
76          maxqlen = 0;
77 <        for (nprocs = 0; nprocs < npt; nprocs++) {      /* spawn children */
78 <                psiz = open_process(rtpd[nprocs], rtargv);
77 >        for (nprocs = 0; nprocs < ncprocs; nprocs++) {  /* spawn children */
78 >                psiz = open_process(&rtpd[nprocs], rtargv);
79                  if (psiz <= 0)
80                          error(SYSTEM, "cannot start rtrace process");
81                  n = psiz/(RPACKSIZ*6*sizeof(float));
# Line 71 | Line 83 | start_rtrace()                 /* start rtrace process */
83                          if (!(maxqlen = n))
84                                  error(INTERNAL,
85                                          "bad pipe buffer size assumption");
86 +                        sleep(2);
87                  } else if (n != maxqlen)
88                          error(INTERNAL, "varying pipe buffer size!");
89                  rmaxpack += n;
# Line 83 | Line 96 | start_rtrace()                 /* start rtrace process */
96  
97  
98   static int
99 < bestout()                       /* get best process to process packet */
99 > bestout(void)                   /* get best process to process packet */
100   {
101          int     cnt;
102          register int    pn, i;
# Line 108 | Line 121 | bestout()                      /* get best process to process packet */
121   }
122  
123  
124 < int
125 < slots_avail()                   /* count packet slots available */
124 > static int
125 > slots_avail(void)                       /* count packet slots available */
126   {
127          register int    nslots = 0;
128          register int    i;
# Line 120 | Line 133 | slots_avail()                  /* count packet slots available */
133   }
134  
135  
136 < queue_packet(p)                 /* queue up a beam packet */
137 < register PACKET *p;
136 > static void
137 > queue_packet(                   /* queue up a beam packet */
138 >        register PACKET *p
139 > )
140   {
141          int     pn, n;
142                                  /* determine process to write to */
# Line 130 | Line 145 | register PACKET        *p;
145                                  /* write out the packet */
146          packrays(rtbuf, p);
147          if ((n = p->nr) < RPACKSIZ)     /* add flush block? */
148 <                bzero((char *)(rtbuf+6*n++), 6*sizeof(float));
149 <        if (writebuf(rtpd[pn][1], (char *)rtbuf, 6*sizeof(float)*n) < 0)
148 >                memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float));
149 >        if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0)
150                  error(SYSTEM, "write error in queue_packet");
151          p->next = NULL;
152          if (!pqlen[pn]++)       /* add it to the end of the queue */
# Line 145 | Line 160 | register PACKET        *p;
160   }
161  
162  
163 < PACKET *
164 < get_packets(poll)               /* read packets from rtrace processes */
165 < int     poll;
163 > static PACKET *
164 > get_packets(            /* read packets from rtrace processes */
165 >        int     poll
166 > )
167   {
168          static struct timeval   tpoll;  /* zero timeval struct */
169          fd_set  readset, errset;
# Line 160 | Line 176 | int    poll;
176          FD_ZERO(&readset); FD_ZERO(&errset); n = 0;
177          for (pn = nprocs; pn--; ) {
178                  if (pqlen[pn])
179 <                        FD_SET(rtpd[pn][0], &readset);
180 <                FD_SET(rtpd[pn][0], &errset);
181 <                if (rtpd[pn][0] >= n)
182 <                        n = rtpd[pn][0] + 1;
179 >                        FD_SET(rtpd[pn].r, &readset);
180 >                FD_SET(rtpd[pn].r, &errset);
181 >                if (rtpd[pn].r >= n)
182 >                        n = rtpd[pn].r + 1;
183          }
184                                          /* make the call */
185          n = select(n, &readset, (fd_set *)NULL, &errset,
# Line 177 | Line 193 | int    poll;
193                  return(NULL);
194                                          /* make read call(s) */
195          for (pn = 0; pn < nprocs; pn++) {
196 <                if (!FD_ISSET(rtpd[pn][0], &readset) &&
197 <                                !FD_ISSET(rtpd[pn][0], &errset))
196 >                if (!FD_ISSET(rtpd[pn].r, &readset) &&
197 >                                !FD_ISSET(rtpd[pn].r, &errset))
198                          continue;
199          reread:
200 <                n = read(rtpd[pn][0], (char *)rtbuf,
200 >                n = read(rtpd[pn].r, (char *)rtbuf,
201                                  4*sizeof(float)*RPACKSIZ*pqlen[pn]);
202                  if (n < 0) {
203 <                        if (errno == EINTR | errno == EAGAIN)
203 >                        if ((errno == EINTR) | (errno == EAGAIN))
204                                  goto reread;
205                          error(SYSTEM, "read error in get_packets");
206                  }
# Line 196 | Line 212 | int    poll;
212                                  nr++;                   /* add flush block */
213                          n -= 4*sizeof(float)*nr;
214                          if (n < 0) {                    /* get remainder */
215 <                                n += readbuf(rtpd[pn][0],
215 >                                n += readbuf(rtpd[pn].r,
216                                                  (char *)(bp+4*nr)+n, -n);
217                                  if (n)
218                                          goto eoferr;
# Line 220 | Line 236 | int    poll;
236          return(pldone);                         /* return finished packets */
237   eoferr:
238          error(USER, "rtrace process died");
239 +        return NULL; /* pro forma return */
240   }
241  
242  
243 < PACKET *
244 < do_packets(pl)                  /* queue a packet list, return finished */
245 < register PACKET *pl;
243 > extern PACKET *
244 > do_packets(                     /* queue a packet list, return finished */
245 >        register PACKET *pl
246 > )
247   {
248          register PACKET *p;
249                                          /* consistency check */
# Line 240 | Line 258 | register PACKET        *pl;
258   }
259  
260  
261 < PACKET *
262 < flush_queue()                   /* empty all rtrace queues */
261 > extern PACKET *
262 > flush_queue(void)                       /* empty all rtrace queues */
263   {
264          PACKET  *rpdone = NULL;
265 <        register PACKET *rpl;
265 >        register PACKET *rpl = NULL;
266          float   *bp;
267          register PACKET *p;
268          int     i, n, nr;
# Line 263 | Line 281 | flush_queue()                  /* empty all rtrace queues */
281                                  if (rpl->nr < RPACKSIZ)
282                                          nr++;           /* add flush block */
283                          }
284 <                        n = readbuf(rtpd[i][0], (char *)rtbuf,
284 >                        n = readbuf(rtpd[i].r, (char *)rtbuf,
285                                          4*sizeof(float)*nr);
286                          if (n < 0)
287                                  error(SYSTEM, "read failure in flush_queue");
# Line 285 | Line 303 | flush_queue()                  /* empty all rtrace queues */
303   }
304  
305  
306 < static
307 < killpersist()                   /* kill persistent process */
306 > static void
307 > killpersist(void)                       /* kill persistent process */
308   {
309          FILE    *fp;
310          int     pid;
311  
312 <        if ((fp = fopen(PFILE, "r")) == NULL)
312 >        if ((fp = fopen(pfile, "r")) == NULL)
313                  return;
314          if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0)
315 <                unlink(PFILE);
315 >                unlink(pfile);
316          fclose(fp);
317   }
318  
319  
320 < int
321 < end_rtrace()                    /* close rtrace process(es) */
320 > extern int
321 > end_rtrace(void)                        /* close rtrace process(es) */
322   {
323          int     status = 0, rv;
324  
325          if (nprocs > 1)
326                  killpersist();
327          while (nprocs > 0) {
328 <                rv = close_process(rtpd[--nprocs]);
328 >                rv = close_process(&rtpd[--nprocs]);
329                  if (rv > 0)
330                          status = rv;
331          }
332 <        free((char *)rtbuf);
332 >        free((void *)rtbuf);
333          rtbuf = NULL;
334          maxqlen = 0;
335          return(status);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines