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 */ |
36 |
|
{ |
37 |
|
static char buf1[8]; |
38 |
|
int rmaxpack = 0; |
39 |
< |
int psiz, npt, n; |
39 |
> |
int psiz, n; |
40 |
|
/* get number of processes */ |
41 |
< |
if ((npt = ncprocs) <= 0) |
41 |
> |
if (ncprocs <= 0 || nprocs > 0) |
42 |
|
return(0); |
43 |
< |
if (npt > MAXPROC) { |
43 |
> |
if (ncprocs > MAXPROC) { |
44 |
|
sprintf(errmsg, |
45 |
|
"number of rtrace processes reduced from %d to %d", |
46 |
< |
npt, MAXPROC); |
46 |
> |
ncprocs, MAXPROC); |
47 |
|
error(WARNING, errmsg); |
48 |
< |
npt = MAXPROC; |
48 |
> |
ncprocs = MAXPROC; |
49 |
|
} |
50 |
< |
/* add compulsory options */ |
51 |
< |
rtargv[rtargc++] = "-i-"; |
52 |
< |
rtargv[rtargc++] = "-I-"; |
53 |
< |
rtargv[rtargc++] = "-h-"; |
54 |
< |
rtargv[rtargc++] = "-ld-"; |
55 |
< |
sprintf(buf1, "%d", RPACKSIZ); |
56 |
< |
rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; |
57 |
< |
rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; |
58 |
< |
rtargv[rtargc++] = "-fff"; |
59 |
< |
rtargv[rtargc++] = "-ovL"; |
60 |
< |
rtargv[rtargc++] = nowarn ? "-w-" : "-w+"; |
61 |
< |
if (npt > 1) { |
62 |
< |
rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = PFILE; |
50 |
> |
if (rtargv[rtargc-1] != vval(OCTREE)) { |
51 |
> |
/* add compulsory options */ |
52 |
> |
rtargv[rtargc++] = "-i-"; |
53 |
> |
rtargv[rtargc++] = "-I-"; |
54 |
> |
rtargv[rtargc++] = "-h-"; |
55 |
> |
rtargv[rtargc++] = "-ld-"; |
56 |
> |
sprintf(buf1, "%d", RPACKSIZ); |
57 |
> |
rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; |
58 |
> |
rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; |
59 |
> |
rtargv[rtargc++] = "-fff"; |
60 |
> |
rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; |
61 |
> |
if (nowarn) |
62 |
> |
rtargv[rtargc++] = "-w-"; |
63 |
> |
if (ncprocs > 1) { |
64 |
> |
mktemp(pfile); |
65 |
> |
rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; |
66 |
> |
} |
67 |
> |
rtargv[rtargc++] = vval(OCTREE); |
68 |
> |
rtargv[rtargc] = NULL; |
69 |
|
} |
62 |
– |
rtargv[rtargc++] = vval(OCTREE); |
63 |
– |
rtargv[rtargc] = NULL; |
70 |
|
maxqlen = 0; |
71 |
< |
for (nprocs = 0; nprocs < npt; nprocs++) { /* spawn children */ |
72 |
< |
psiz = open_process(rtpd[nprocs], rtargv); |
71 |
> |
for (nprocs = 0; nprocs < ncprocs; nprocs++) { /* spawn children */ |
72 |
> |
psiz = open_process(&rtpd[nprocs], rtargv); |
73 |
|
if (psiz <= 0) |
74 |
|
error(SYSTEM, "cannot start rtrace process"); |
75 |
|
n = psiz/(RPACKSIZ*6*sizeof(float)); |
77 |
|
if (!(maxqlen = n)) |
78 |
|
error(INTERNAL, |
79 |
|
"bad pipe buffer size assumption"); |
80 |
+ |
sleep(2); |
81 |
|
} else if (n != maxqlen) |
82 |
|
error(INTERNAL, "varying pipe buffer size!"); |
83 |
|
rmaxpack += n; |
137 |
|
/* write out the packet */ |
138 |
|
packrays(rtbuf, p); |
139 |
|
if ((n = p->nr) < RPACKSIZ) /* add flush block? */ |
140 |
< |
bzero((char *)(rtbuf+6*n++), 6*sizeof(float)); |
141 |
< |
if (writebuf(rtpd[pn][1], (char *)rtbuf, 6*sizeof(float)*n) < 0) |
140 |
> |
memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float)); |
141 |
> |
if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0) |
142 |
|
error(SYSTEM, "write error in queue_packet"); |
143 |
|
p->next = NULL; |
144 |
|
if (!pqlen[pn]++) /* add it to the end of the queue */ |
167 |
|
FD_ZERO(&readset); FD_ZERO(&errset); n = 0; |
168 |
|
for (pn = nprocs; pn--; ) { |
169 |
|
if (pqlen[pn]) |
170 |
< |
FD_SET(rtpd[pn][0], &readset); |
171 |
< |
FD_SET(rtpd[pn][0], &errset); |
172 |
< |
if (rtpd[pn][0] >= n) |
173 |
< |
n = rtpd[pn][0] + 1; |
170 |
> |
FD_SET(rtpd[pn].r, &readset); |
171 |
> |
FD_SET(rtpd[pn].r, &errset); |
172 |
> |
if (rtpd[pn].r >= n) |
173 |
> |
n = rtpd[pn].r + 1; |
174 |
|
} |
175 |
|
/* make the call */ |
176 |
|
n = select(n, &readset, (fd_set *)NULL, &errset, |
184 |
|
return(NULL); |
185 |
|
/* make read call(s) */ |
186 |
|
for (pn = 0; pn < nprocs; pn++) { |
187 |
< |
if (!FD_ISSET(rtpd[pn][0], &readset) && |
188 |
< |
!FD_ISSET(rtpd[pn][0], &errset)) |
187 |
> |
if (!FD_ISSET(rtpd[pn].r, &readset) && |
188 |
> |
!FD_ISSET(rtpd[pn].r, &errset)) |
189 |
|
continue; |
190 |
|
reread: |
191 |
< |
n = read(rtpd[pn][0], (char *)rtbuf, |
191 |
> |
n = read(rtpd[pn].r, (char *)rtbuf, |
192 |
|
4*sizeof(float)*RPACKSIZ*pqlen[pn]); |
193 |
|
if (n < 0) { |
194 |
|
if (errno == EINTR | errno == EAGAIN) |
203 |
|
nr++; /* add flush block */ |
204 |
|
n -= 4*sizeof(float)*nr; |
205 |
|
if (n < 0) { /* get remainder */ |
206 |
< |
n += readbuf(rtpd[pn][0], |
206 |
> |
n += readbuf(rtpd[pn].r, |
207 |
|
(char *)(bp+4*nr)+n, -n); |
208 |
|
if (n) |
209 |
|
goto eoferr; |
270 |
|
if (rpl->nr < RPACKSIZ) |
271 |
|
nr++; /* add flush block */ |
272 |
|
} |
273 |
< |
n = readbuf(rtpd[i][0], (char *)rtbuf, |
273 |
> |
n = readbuf(rtpd[i].r, (char *)rtbuf, |
274 |
|
4*sizeof(float)*nr); |
275 |
|
if (n < 0) |
276 |
|
error(SYSTEM, "read failure in flush_queue"); |
298 |
|
FILE *fp; |
299 |
|
int pid; |
300 |
|
|
301 |
< |
if ((fp = fopen(PFILE, "r")) == NULL) |
301 |
> |
if ((fp = fopen(pfile, "r")) == NULL) |
302 |
|
return; |
303 |
|
if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0) |
304 |
< |
unlink(PFILE); |
304 |
> |
unlink(pfile); |
305 |
|
fclose(fp); |
306 |
|
} |
307 |
|
|
314 |
|
if (nprocs > 1) |
315 |
|
killpersist(); |
316 |
|
while (nprocs > 0) { |
317 |
< |
rv = close_process(rtpd[--nprocs]); |
317 |
> |
rv = close_process(&rtpd[--nprocs]); |
318 |
|
if (rv > 0) |
319 |
|
status = rv; |
320 |
|
} |
321 |
< |
free((char *)rtbuf); |
321 |
> |
free((void *)rtbuf); |
322 |
|
rtbuf = NULL; |
323 |
|
maxqlen = 0; |
324 |
|
return(status); |