airspy: Option pack={0,1} to enable USB bit packing

Patch provided by Martin Smith.

Last July there were several changes made to the Airspy firmware and
libairspy that added support for a new bit packing mode where 4 sets of
12 bit samples are packed into 3 sets of 16 bits for the transfer across
the USB bus ( ). 25% less data is
transferred across the bus and this is good for some computers with
cheap USB chipsets. There is an overhead of extra memory bandwidth
required on the host side to unpack the data into a useful format, so
for optimal performance bit packing is disabled by default.

The data is automatically unpacked within libairspy before being passed
along, so no changes are required anywhere else if packing is enabled
(or not enabled). Airspy firmware older than v1.0.0-rc6 does not have
the function, but that is detected and handled by libairspy.

I wrote the attached patch to enable packing in gr-osmosdr, which I
tested and it works. It is basically a clone of the bias=0|1 lines as
pack=0|1 and calls the needed libairspy function.


Do some Baseline test with Airspy command line tools to have something
to compare USB throughput results
$ sudo mount -t debugfs none /sys/kernel/debug
$ sudo modprobe usbmon
$ wireshark -i usbmod3 &
$ airspy_info ; sleep 120 ; \
airspy_rx -t 4 -r /dev/null -n 2400000000 ; sleep 120 ; \
airspy_rx -t 4 -r /dev/null -p 1 -n 2400000000 ; sleep 120 ; \
Wireshark->Statistics->IO Graph
The Bytes/Tick are double the actual data rate because of way wireshark
collects the USB packets, I could have added a filter to fix this. But
the relationship is valid 25% less with packing enabled. The data rate
in the IO Grahp drops from 80MB/sec (in+out) [really 40MB/sec] to
60MB/second (in+out) [really 30MB/sec] from unpacked to packed.
10MSPS no packing, packing
2.5MSPS no packing, packing

Verification test with my patched gr-osmosdr
$ sudo mount -t debugfs none /sys/kernel/debug
$ sudo modprobe usbmon
$ wireshark -i usbmod3 &
$ osmocom_fft -a "airspy=0" -s 10000000 --fft-rate=1
$ osmocom_fft -a "airspy=0,pack=1" -s 10000000 --fft-rate=1
$ osmocom_fft -a "airspy=0" -s 2500000 --fft-rate=1
$ osmocom_fft -a "airspy=0,pack=1" -s 2500000 --fft-rate=1
$ osmocom_fft -a "airspy=0" -s 2500000 --fft-rate=1
$ osmocom_fft -a "airspy=0,pack=0" -s 2500000 --fft-rate=1

I ran all of the above tests and the wireshark USB throughput graphs
showed exactly what was expected.

25% less when packing was enabled and if you did not specify the
"pack=1", then no bit packing is performed by libairspy. All the
magnitudes within the FFT windows looked exactly the same as they do
without bit packing.
This commit is contained in:
Dimitri Stolnikov 2016-02-28 17:52:01 +01:00
parent b206a90f49
commit 164a09fc11
1 changed files with 10 additions and 0 deletions

View File

@ -153,6 +153,16 @@ airspy_source_c::airspy_source_c (const std::string &args)
AIRSPY_THROW_ON_ERROR(ret, "Failed to enable DC bias")
/* pack 4 sets of 12 bits into 3 sets 16 bits for the data transfer across the
* USB bus. The default is is unpacked, to transfer 12 bits across the USB bus
* in 16 bit words. libairspy transparently unpacks if packing is enabled */
if ( dict.count( "pack" ) )
bool pack = boost::lexical_cast<bool>( dict["pack"] );
int ret = airspy_set_packing(_dev, (uint8_t)pack);
AIRSPY_THROW_ON_ERROR(ret, "Failed to set USB bit packing")
_fifo = new boost::circular_buffer<gr_complex>(5000000);
if (!_fifo) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +