Commit 113ff999 authored by Federico Vaga's avatar Federico Vaga

drv: do a pre-allocation to store all timestamps

This allows bigger read from the driver, which reduces the number of syscall
and make the system faster
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent fe5b9727
...@@ -640,41 +640,61 @@ int fmctdc_read(struct fmctdc_board *userb, unsigned int channel, ...@@ -640,41 +640,61 @@ int fmctdc_read(struct fmctdc_board *userb, unsigned int channel,
struct fmctdc_time *t, int n, int flags) struct fmctdc_time *t, int n, int flags)
{ {
__define_board(b, userb); __define_board(b, userb);
int i, j; int i;
int n_ts;
fd_set set; fd_set set;
struct ft_hw_timestamp data; struct ft_hw_timestamp *data;
if (channel >= FMCTDC_NUM_CHANNELS) { if (channel >= FMCTDC_NUM_CHANNELS) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
for (i = 0; i < n;) { data = calloc(n, sizeof(*data));
j = read(b->fdd[channel], &data, sizeof(data)); if (!data) {
if (j == sizeof(data)) { errno = ENOMEM;
fmctdc_ts_convert(&t[i], &data); return -1;
++i; }
continue;
i = 0;
while (i < n) {
n_ts = read(b->fdd[channel], &data[i], sizeof(*data) * (n - i));
if (n_ts < 0 && errno != EAGAIN) {
if (i == 0)
goto err;
else
goto out;
} }
if (j < 0 && errno != EAGAIN) if (n_ts % sizeof(*data) == 0) { /* Good samples here */
return -1; n_ts /= sizeof(*data);
n_ts += i;
for (; i < n_ts && i < n; i++)
fmctdc_ts_convert(&t[i], &data[i]);
continue; /* the while loop */
}
if (i) /* error but before we got something */
goto out;
/* so, it's EAGAIN: if we already got something, we are done */
if (i)
return i;
/* EAGAIN at first sample */ /* EAGAIN at first sample */
if (j < 0 && flags == O_NONBLOCK) if (n_ts < 0 && flags == O_NONBLOCK)
return -1; return -1;
/* So, first sample and blocking read. Wait.. */ /* So, first sample and blocking read. Wait.. */
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(b->fdc[channel], &set); FD_SET(b->fdc[channel], &set);
if (select(b->fdc[channel] + 1, &set, NULL, NULL, NULL) < 0) if (select(b->fdc[channel] + 1, &set, NULL, NULL, NULL) < 0)
return -1; goto err;
continue;
} }
out:
free(data);
return i; return i;
err:
free(data);
return -1;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment