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 |
|
|
11 |
– |
#include "rholo.h" |
12 |
– |
#include "random.h" |
8 |
|
#include <signal.h> |
9 |
|
#include <sys/time.h> |
10 |
|
|
11 |
+ |
#include "rholo.h" |
12 |
+ |
#include "random.h" |
13 |
+ |
#include "paths.h" |
14 |
+ |
#include "selcall.h" |
15 |
+ |
#include "rtprocess.h" |
16 |
+ |
|
17 |
|
#ifndef MAXPROC |
18 |
< |
#define MAXPROC 16 |
18 |
> |
#define MAXPROC 64 |
19 |
|
#endif |
20 |
|
|
21 |
< |
static char PFILE[] = "/usr/tmp/RHpersist"; /* persist file name */ |
21 |
> |
int nprocs = 0; /* running process count */ |
22 |
|
|
23 |
< |
static int rtpd[MAXPROC][3]; /* process descriptors */ |
23 |
> |
static char pfile[] = TEMPLATE; /* persist file name */ |
24 |
> |
|
25 |
> |
static SUBPROC rtpd[MAXPROC]; /* process descriptors */ |
26 |
|
static float *rtbuf = NULL; /* allocated i/o buffer */ |
27 |
|
static int maxqlen = 0; /* maximum packets per queue */ |
25 |
– |
static int nprocs = 0; /* number of processes */ |
28 |
|
|
29 |
|
static PACKET *pqueue[MAXPROC]; /* packet queues */ |
30 |
|
static int pqlen[MAXPROC]; /* packet queue lengths */ |
35 |
|
{ |
36 |
|
static char buf1[8]; |
37 |
|
int rmaxpack = 0; |
38 |
< |
int psiz, npt, n; |
38 |
> |
int psiz, n; |
39 |
|
/* get number of processes */ |
40 |
< |
if ((npt = ncprocs) <= 0) |
40 |
> |
if (ncprocs <= 0 || nprocs > 0) |
41 |
|
return(0); |
42 |
< |
if (npt > MAXPROC) { |
42 |
> |
if (ncprocs > MAXPROC) { |
43 |
|
sprintf(errmsg, |
44 |
|
"number of rtrace processes reduced from %d to %d", |
45 |
< |
npt, MAXPROC); |
45 |
> |
ncprocs, MAXPROC); |
46 |
|
error(WARNING, errmsg); |
47 |
< |
npt = MAXPROC; |
47 |
> |
ncprocs = MAXPROC; |
48 |
|
} |
49 |
< |
/* add compulsory options */ |
50 |
< |
rtargv[rtargc++] = "-i-"; |
51 |
< |
rtargv[rtargc++] = "-I-"; |
52 |
< |
rtargv[rtargc++] = "-h-"; |
53 |
< |
rtargv[rtargc++] = "-ld-"; |
54 |
< |
sprintf(buf1, "%d", RPACKSIZ); |
55 |
< |
rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; |
56 |
< |
rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; |
57 |
< |
rtargv[rtargc++] = "-fff"; |
58 |
< |
rtargv[rtargc++] = "-ovl"; |
59 |
< |
rtargv[rtargc++] = nowarn ? "-w-" : "-w+"; |
60 |
< |
if (npt > 1) { |
61 |
< |
rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = PFILE; |
49 |
> |
if (rtargv[rtargc-1] != vval(OCTREE)) { |
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++] = vbool(VDIST) ? "-ovl" : "-ovL"; |
60 |
> |
if (nowarn) |
61 |
> |
rtargv[rtargc++] = "-w-"; |
62 |
> |
if (ncprocs > 1) { |
63 |
> |
mktemp(pfile); |
64 |
> |
rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; |
65 |
> |
} |
66 |
> |
rtargv[rtargc++] = vval(OCTREE); |
67 |
> |
rtargv[rtargc] = NULL; |
68 |
|
} |
61 |
– |
rtargv[rtargc++] = vval(OCTREE); |
62 |
– |
rtargv[rtargc] = NULL; |
69 |
|
maxqlen = 0; |
70 |
< |
for (nprocs = 0; nprocs < npt; nprocs++) { /* spawn children */ |
71 |
< |
psiz = open_process(rtpd[nprocs], rtargv); |
70 |
> |
for (nprocs = 0; nprocs < ncprocs; nprocs++) { /* spawn children */ |
71 |
> |
psiz = open_process(&rtpd[nprocs], rtargv); |
72 |
|
if (psiz <= 0) |
73 |
|
error(SYSTEM, "cannot start rtrace process"); |
74 |
|
n = psiz/(RPACKSIZ*6*sizeof(float)); |
76 |
|
if (!(maxqlen = n)) |
77 |
|
error(INTERNAL, |
78 |
|
"bad pipe buffer size assumption"); |
79 |
+ |
sleep(2); |
80 |
|
} else if (n != maxqlen) |
81 |
|
error(INTERNAL, "varying pipe buffer size!"); |
82 |
|
rmaxpack += n; |
137 |
|
packrays(rtbuf, p); |
138 |
|
if ((n = p->nr) < RPACKSIZ) /* add flush block? */ |
139 |
|
bzero((char *)(rtbuf+6*n++), 6*sizeof(float)); |
140 |
< |
if (writebuf(rtpd[pn][1], (char *)rtbuf, 6*sizeof(float)*n) < 0) |
140 |
> |
if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0) |
141 |
|
error(SYSTEM, "write error in queue_packet"); |
142 |
|
p->next = NULL; |
143 |
|
if (!pqlen[pn]++) /* add it to the end of the queue */ |
166 |
|
FD_ZERO(&readset); FD_ZERO(&errset); n = 0; |
167 |
|
for (pn = nprocs; pn--; ) { |
168 |
|
if (pqlen[pn]) |
169 |
< |
FD_SET(rtpd[pn][0], &readset); |
170 |
< |
FD_SET(rtpd[pn][0], &errset); |
171 |
< |
if (rtpd[pn][0] >= n) |
172 |
< |
n = rtpd[pn][0] + 1; |
169 |
> |
FD_SET(rtpd[pn].r, &readset); |
170 |
> |
FD_SET(rtpd[pn].r, &errset); |
171 |
> |
if (rtpd[pn].r >= n) |
172 |
> |
n = rtpd[pn].r + 1; |
173 |
|
} |
174 |
|
/* make the call */ |
175 |
|
n = select(n, &readset, (fd_set *)NULL, &errset, |
183 |
|
return(NULL); |
184 |
|
/* make read call(s) */ |
185 |
|
for (pn = 0; pn < nprocs; pn++) { |
186 |
< |
if (!FD_ISSET(rtpd[pn][0], &readset) && |
187 |
< |
!FD_ISSET(rtpd[pn][0], &errset)) |
186 |
> |
if (!FD_ISSET(rtpd[pn].r, &readset) && |
187 |
> |
!FD_ISSET(rtpd[pn].r, &errset)) |
188 |
|
continue; |
189 |
|
reread: |
190 |
< |
n = read(rtpd[pn][0], (char *)rtbuf, |
190 |
> |
n = read(rtpd[pn].r, (char *)rtbuf, |
191 |
|
4*sizeof(float)*RPACKSIZ*pqlen[pn]); |
192 |
|
if (n < 0) { |
193 |
|
if (errno == EINTR | errno == EAGAIN) |
202 |
|
nr++; /* add flush block */ |
203 |
|
n -= 4*sizeof(float)*nr; |
204 |
|
if (n < 0) { /* get remainder */ |
205 |
< |
n += readbuf(rtpd[pn][0], |
205 |
> |
n += readbuf(rtpd[pn].r, |
206 |
|
(char *)(bp+4*nr)+n, -n); |
207 |
|
if (n) |
208 |
|
goto eoferr; |
225 |
|
} |
226 |
|
return(pldone); /* return finished packets */ |
227 |
|
eoferr: |
228 |
< |
error(USER, "unexpected EOF from rtrace process"); |
228 |
> |
error(USER, "rtrace process died"); |
229 |
|
} |
230 |
|
|
231 |
|
|
259 |
|
if (pqlen[i]) { |
260 |
|
if (rpdone == NULL) { /* tack on queue */ |
261 |
|
rpdone = rpl = pqueue[i]; |
262 |
< |
nr = rpl->nr; |
262 |
> |
if ((nr = rpl->nr) < RPACKSIZ) nr++; |
263 |
|
} else { |
264 |
|
rpl->next = pqueue[i]; |
265 |
|
nr = 0; |
269 |
|
if (rpl->nr < RPACKSIZ) |
270 |
|
nr++; /* add flush block */ |
271 |
|
} |
272 |
< |
n = readbuf(rtpd[i][0], (char *)rtbuf, |
272 |
> |
n = readbuf(rtpd[i].r, (char *)rtbuf, |
273 |
|
4*sizeof(float)*nr); |
274 |
|
if (n < 0) |
275 |
|
error(SYSTEM, "read failure in flush_queue"); |
297 |
|
FILE *fp; |
298 |
|
int pid; |
299 |
|
|
300 |
< |
if ((fp = fopen(PFILE, "r")) == NULL) |
300 |
> |
if ((fp = fopen(pfile, "r")) == NULL) |
301 |
|
return; |
302 |
|
if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0) |
303 |
< |
unlink(PFILE); |
303 |
> |
unlink(pfile); |
304 |
|
fclose(fp); |
305 |
|
} |
306 |
|
|
313 |
|
if (nprocs > 1) |
314 |
|
killpersist(); |
315 |
|
while (nprocs > 0) { |
316 |
< |
rv = close_process(rtpd[--nprocs]); |
316 |
> |
rv = close_process(&rtpd[--nprocs]); |
317 |
|
if (rv > 0) |
318 |
|
status = rv; |
319 |
|
} |
320 |
< |
free((char *)rtbuf); |
320 |
> |
free((void *)rtbuf); |
321 |
|
rtbuf = NULL; |
322 |
|
maxqlen = 0; |
323 |
|
return(status); |