1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
From 81833a1cf6288fee93a9157c0f60cafb5ec340b9 Mon Sep 17 00:00:00 2001
From: Steve Markgraf <steve@steve-m.de>
Date: Tue, 16 Jul 2019 23:45:57 +0200
Subject: [PATCH 05/33] lib: disable usbfs zero-copy support by default
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.
---
CMakeLists.txt | 8 ++++++++
configure.ac | 6 ++++++
src/librtlsdr.c | 2 +-
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index abc8f9b..57a1c2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
########################################################################
diff --git a/configure.ac b/configure.ac
index 5b94828..1afbfbd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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)
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index d72a0f5..213e96c 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -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;
--
2.30.2
|