Skip to content

Commit

Permalink
lib: disable usbfs zero-copy support by default
Browse files Browse the repository at this point in the history
Although we added a detection mechanism for the presence of the Kernel
bug earlier, reading from the incorrectly mapped memory might cause a
bus error on some ARM systems.

With the overall performance benefit being rather minimal for the
data rates of rtl-sdr, disable zero-copy by default.
  • Loading branch information
steve-m committed Jul 16, 2019
1 parent be1d120 commit 81833a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ else (DETACH_KERNEL_DRIVER)
message (STATUS "Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable")
endif (DETACH_KERNEL_DRIVER)

option(ENABLE_ZEROCOPY "Enable usbfs zero-copy support" OFF)
if (ENABLE_ZEROCOPY)
message (STATUS "Building with usbfs zero-copy support enabled")
add_definitions(-DENABLE_ZEROCOPY=1)
else (ENABLE_ZEROCOPY)
message (STATUS "Building with usbfs zero-copy support disabled, use -DENABLE_ZEROCOPY=ON to enable")
endif (ENABLE_ZEROCOPY)

########################################################################
# Add subdirectories
########################################################################
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ AC_ARG_ENABLE(driver-detach,
CFLAGS="$CFLAGS -DDETACH_KERNEL_DRIVER"
fi])

AC_ARG_ENABLE(zerocopy,
[ --enable-zerocopy Enable usbfs zero-copy support (disabled by default)],
[if test x$enableval = xyes; then
CFLAGS="$CFLAGS -DENABLE_ZEROCOPY"
fi])

dnl Generate the output
AC_CONFIG_HEADER(config.h)

Expand Down
2 changes: 1 addition & 1 deletion src/librtlsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev)
dev->xfer_buf = malloc(dev->xfer_buf_num * sizeof(unsigned char *));
memset(dev->xfer_buf, 0, dev->xfer_buf_num * sizeof(unsigned char *));

#if defined (__linux__) && LIBUSB_API_VERSION >= 0x01000105
#if defined(ENABLE_ZEROCOPY) && defined (__linux__) && LIBUSB_API_VERSION >= 0x01000105
fprintf(stderr, "Allocating %d zero-copy buffers\n", dev->xfer_buf_num);

dev->use_zerocopy = 1;
Expand Down

0 comments on commit 81833a1

Please sign in to comment.