7 |
|
|
8 |
|
#include <signal.h> |
9 |
|
#include <sys/time.h> |
10 |
+ |
#include <string.h> |
11 |
|
|
12 |
|
#include "rholo.h" |
13 |
|
#include "random.h" |
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 |
+ |
|
40 |
|
int |
41 |
< |
start_rtrace() /* start rtrace process */ |
41 |
> |
start_rtrace(void) /* start rtrace process */ |
42 |
|
{ |
43 |
|
static char buf1[8]; |
44 |
|
int rmaxpack = 0; |
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; |
102 |
> |
int pn, i; |
103 |
|
|
104 |
|
pn = 0; /* find shortest queue */ |
105 |
|
for (i = 1; i < nprocs; i++) |
113 |
|
if (pqlen[i] == pqlen[pn]) |
114 |
|
cnt++; |
115 |
|
/* break ties fairly */ |
116 |
< |
if ((cnt = random() % cnt)) |
116 |
> |
if ((cnt = irandom(cnt))) |
117 |
|
for (i = pn; i < nprocs; i++) |
118 |
|
if (pqlen[i] == pqlen[pn] && !cnt--) |
119 |
|
return(i); |
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; |
127 |
> |
int nslots = 0; |
128 |
> |
int i; |
129 |
|
|
130 |
|
for (i = nprocs; i--; ) |
131 |
|
nslots += maxqlen - pqlen[i]; |
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 |
> |
PACKET *p |
139 |
> |
) |
140 |
|
{ |
141 |
|
int pn, n; |
142 |
|
/* determine process to write to */ |
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)); |
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 */ |
153 |
|
pqueue[pn] = p; |
154 |
|
else { |
155 |
< |
register PACKET *rpl = pqueue[pn]; |
155 |
> |
PACKET *rpl = pqueue[pn]; |
156 |
|
while (rpl->next != NULL) |
157 |
|
rpl = rpl->next; |
158 |
|
rpl->next = 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; |
170 |
|
PACKET *pldone = NULL, *plend; |
171 |
< |
register PACKET *p; |
171 |
> |
PACKET *p; |
172 |
|
int n, nr; |
173 |
< |
register int pn; |
173 |
> |
int pn; |
174 |
|
float *bp; |
175 |
|
/* prepare select call */ |
176 |
|
FD_ZERO(&readset); FD_ZERO(&errset); n = 0; |
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 |
|
} |
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; |
244 |
> |
do_packets( /* queue a packet list, return finished */ |
245 |
> |
PACKET *pl |
246 |
> |
) |
247 |
|
{ |
248 |
< |
register PACKET *p; |
248 |
> |
PACKET *p; |
249 |
|
/* consistency check */ |
250 |
|
if (nprocs < 1) |
251 |
|
error(CONSISTENCY, "do_packets called with no active process"); |
259 |
|
|
260 |
|
|
261 |
|
PACKET * |
262 |
< |
flush_queue() /* empty all rtrace queues */ |
262 |
> |
flush_queue(void) /* empty all rtrace queues */ |
263 |
|
{ |
264 |
|
PACKET *rpdone = NULL; |
265 |
< |
register PACKET *rpl; |
265 |
> |
PACKET *rpl = NULL; |
266 |
|
float *bp; |
267 |
< |
register PACKET *p; |
267 |
> |
PACKET *p; |
268 |
|
int i, n, nr; |
269 |
|
|
270 |
|
for (i = 0; i < nprocs; i++) |
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; |
318 |
|
|
319 |
|
|
320 |
|
int |
321 |
< |
end_rtrace() /* close rtrace process(es) */ |
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]); |
317 |
< |
if (rv > 0) |
318 |
< |
status = rv; |
319 |
< |
} |
327 |
> |
status = close_processes(rtpd, nprocs); |
328 |
> |
nprocs = 0; |
329 |
|
free((void *)rtbuf); |
330 |
|
rtbuf = NULL; |
331 |
|
maxqlen = 0; |