]> sigrok.org Git - libsigrok.git/commit - hardware/fx2lafw/fx2lafw.c
sr: fx2lafw: Calculate buffer size and timeout based on sample rate
authorLars-Peter Clausen <redacted>
Mon, 25 Jun 2012 20:15:59 +0000 (22:15 +0200)
committerUwe Hermann <redacted>
Wed, 27 Jun 2012 22:40:52 +0000 (00:40 +0200)
commit5af666a94e67e8a18c0dfa1f4314e1c3e93aa993
tree0317d351e9840a94e94844d80c7b338a764a1904
parent7ce737a77c0d29276cdda4f3670c1ef41173bb9c
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 <redacted>
hardware/fx2lafw/fx2lafw.c