libsigrok/hardware
Lars-Peter Clausen 5af666a94e sr: fx2lafw: Calculate buffer size and timeout based on sample rate
Currently timeout and buffer size are hard-coded in the fx2lafw driver which is
non-optimal if we want to get good results at both high and low sample rates.

The timeout is hard-coded to 40ms, which doesn't work well when sampling at
a low sample rate. E.g. at 20kHz filling all available buffer space alone takes
6 seconds. So naturally we'll see a lot of transfers timeout in this case.

The buffer size is hard-coded to 4096 bytes, which does not work well with high
sample rates. E.g. at 24MHz these 4096 bytes are enough space for 0.17ms of
data. The total buffer size is enough for about 5ms of data. Sooner or later the
application won't be able to resubmit a transfer within this time span and the
device will abort data acquisition. Usually this happens within the first few
seconds of sampling.

This patch adds a few new helper functions which calculate the buffer size and
timeout based on the current sample rate.

The buffer size is chosen to be large enough to hold about 10ms of data and it
also must be a multiple of 512 bytes since the firmware will send us the data
in 512 byte chunks.

The timeout is set to the time it would take to fill the whole available buffer
space plus a 25% headroom to accommodate for jitter. This is more than enough,
but there is no need to make the timeout a tight deadline, since it is only
meant as a last resort in case the device stops submitting data. And in this
case data acquisition will be aborted anyway.

The patch also limits the the number of transfers so that the total buffer
space is not much more of 500ms. This will ensure that we do not have to
wait too long when aborting data acquisition.

This patch also significantly reduces the number of context switches when
sampling at a higher sample rate. On my system for example the CPU load of
sigrok-cli when sampling at 24MHz goes down from ~25% to 3-4%.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2012-06-28 00:40:52 +02:00
..
alsa sr: Made the dev_config_set parameter a const pointer 2012-05-31 19:51:11 +01:00
asix-sigma sr: Made sample rate lists const 2012-05-31 19:51:11 +01:00
chronovu-la8 sr: chronovu-la8: Split code into api.c and driver.c. 2012-06-21 23:34:38 +02:00
common sr: Deleted the saleae-logic driver, fx2lafw has superceded it. 2012-04-19 00:12:22 +02:00
demo sr: Made sample rate lists const 2012-05-31 19:51:11 +01:00
fx2lafw sr: fx2lafw: Calculate buffer size and timeout based on sample rate 2012-06-28 00:40:52 +02:00
hantek-dso hantek-dso: add profiles for all five models in the series 2012-06-27 19:36:30 +02:00
link-mso19 sr: Made sample rate lists const 2012-05-31 19:51:11 +01:00
mastech-va18b sr: Unfinished Mastech VA18B (DMM) support. 2012-06-21 23:56:24 +02:00
openbench-logic-sniffer sr: ols: Fix incorrect comment. 2012-06-21 23:59:27 +02:00
zeroplus-logic-cube sr: backend/zeroplus: Improve debug output. 2012-06-19 23:33:50 +02:00
Makefile.am sr: Unfinished Mastech VA18B (DMM) support. 2012-06-21 23:56:24 +02:00