Commit 3c0d2649 authored by Federico Vaga's avatar Federico Vaga

*: use vmalloc to store data in the driver

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 174062cc
......@@ -491,6 +491,7 @@ static struct zio_cset ft_cset[] = {
static struct zio_device ft_tmpl = {
.owner = THIS_MODULE,
.preferred_trigger = FT_ZIO_TRIG_TYPE_NAME,
.preferred_buffer = "vmalloc",
.s_op = &ft_zio_sysfs_ops,
.cset = ft_cset,
.n_cset = ARRAY_SIZE(ft_cset),
......
......@@ -38,13 +38,20 @@ static int ft_nboards; /**< number of available boards */
static char *names[] = { "seconds", "coarse" }; /**< names used to retrive
time-stamps from sysfs */
static const char *fmctdc_error_string[] = {
[FMCTDC_ERR_VMALLOC - __FMCTDC_ERR_MIN] =
"Missing ZIO vmalloc support",
};
/**
* It returns the error message associated to the given error code
* @param[in] err error code
*/
char *fmctdc_strerror(int err)
const char *fmctdc_strerror(int err)
{
return strerror(err);
if (err < __FMCTDC_ERR_MIN || err > __FMCTDC_ERR_MAX)
return strerror(err);
return fmctdc_error_string[err - __FMCTDC_ERR_MIN];
}
......@@ -227,6 +234,14 @@ found:
b->fdcc[i] = open(path, O_RDONLY);
if (b->fdcc[i] < 0)
goto error;
snprintf(path, sizeof(path), "%s/ft-ch%d/chan0/buffer/max-buffer-kb",
b->sysbase, i + 1);
if (access(path, R_OK | W_OK)) {
errno = FMCTDC_ERR_VMALLOC;
goto error;
}
}
return (void *)b;
......@@ -526,12 +541,15 @@ int fmctdc_get_buffer_len(struct fmctdc_board *userb, unsigned int channel)
return -1;
}
snprintf(attr, sizeof(attr), "ft-ch%d/chan0/buffer/max-buffer-len",
snprintf(attr, sizeof(attr), "ft-ch%d/chan0/buffer/max-buffer-kb",
channel + 1);
ret = fmctdc_sysfs_get(b, attr, &val);
if (ret)
return ret;
val = (val * 1024) / sizeof(struct ft_hw_timestamp);
return val;
}
......@@ -539,9 +557,14 @@ int fmctdc_get_buffer_len(struct fmctdc_board *userb, unsigned int channel)
* The function set the buffer length
* @param[in] userb TDC board instance token
* @param[in] channel to use
* @param[in] length maximum number of timestamps to store
* @param[in] length maximum number of timestamps to store (min: 64)
* @return 0 on success, otherwise a negative errno code is set
* appropriately
*
* Internally, the buffer allocates memory in chunks of minimun 1KiB. This
* means, for example, that if you ask for 65 timestamp the buffer will
* allocate space for 128. This because 64 timestamps fit in 1KiB, to store
* 65 we need 2KiB (128 timestamps)
*/
int fmctdc_set_buffer_len(struct fmctdc_board *userb, unsigned int channel,
unsigned int length)
......@@ -554,10 +577,15 @@ int fmctdc_set_buffer_len(struct fmctdc_board *userb, unsigned int channel,
errno = EINVAL;
return -1;
}
if (length < 64) {
errno = EINVAL;
return -1;
}
snprintf(attr, sizeof(attr), "ft-ch%d/chan0/buffer/max-buffer-len", channel + 1);
snprintf(attr, sizeof(attr), "ft-ch%d/chan0/buffer/max-buffer-kb",
channel + 1);
val = length;
val = ((length * sizeof(struct ft_hw_timestamp)) / 1024) + 1;
return fmctdc_sysfs_set(b, attr, &val);
}
......
......@@ -17,6 +17,12 @@ extern "C" {
#include <stdint.h>
#define __FMCTDC_ERR_MIN 4096
enum fmctdc_error_numbers {
FMCTDC_ERR_VMALLOC = __FMCTDC_ERR_MIN,
__FMCTDC_ERR_MAX,
};
/**
* Enumeration for all TDC channels
*/
......@@ -99,7 +105,7 @@ struct fmctdc_time {
* Set of library utilities
* @{
*/
extern char *fmctdc_strerror(int err);
extern const char *fmctdc_strerror(int err);
extern int fmctdc_init(void);
extern void fmctdc_exit(void);
/**@}*/
......
......@@ -251,7 +251,7 @@ int main(int argc, char **argv)
struct fmctdc_time *ts;
int channels[FMCTDC_NUM_CHANNELS];
int chan_count = 0, i, n, ch, fd, n_ts, ret, n_boards;
int nblock = 0, buflen = 16;
int nblock = 0, buflen = 5000000;
enum fmctdc_buffer_mode bufmode = FMCTDC_BUFFER_FIFO;
int n_samples = -1;
unsigned int n_show = 1;
......
......@@ -199,10 +199,16 @@ static void fmctdc_param_test6(struct m_test *m_test)
for (i = 0; i < FMCTDC_NUM_CHANNELS; ++i) {
for (len = 1; len < 64; len <<= 1) {
err = fmctdc_set_buffer_len(tdc, i, len);
m_assert_int_eq(-1, err);
}
for (len = 64; len < (64 << 20); len <<= 1) {
err = fmctdc_set_buffer_len(tdc, i, len);
m_assert_int_eq(0, err);
ret = fmctdc_get_buffer_len(tdc, i);
m_assert_int_eq(len, ret);
m_assert_int_le(len, ret);
}
}
}
......@@ -247,7 +253,7 @@ static void fmctdc_op_test_setup(struct m_test *m_test)
ret = fmctdc_channel_status_get(tdc, i);
m_assert_int_eq(FMCTDC_STATUS_DISABLE, ret);
err = fmctdc_set_buffer_len(tdc, i, 16);
err = fmctdc_set_buffer_len(tdc, i, 1000000);
m_assert_int_eq(0, err);
err = fmctdc_ts_mode_set(tdc, i, FMCTDC_TS_MODE_POST);
m_assert_int_eq(0, err);
......
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