From 343a443e98a19924fa4dc082b384d106d7369dbe Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 3 Jun 2017 08:27:55 +0200 Subject: [PATCH] set ASYNC_LOW_LATENCY flag on serial device just like setserial does to fix huge latency found on recent kernel versions --- CMakeLists.txt | 1 + config.h.cmake | 3 +++ configure.ac | 1 + src/lib/ebus/device.cpp | 11 +++++++++++ 4 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79b6417b..5a6ffe31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ set(CMAKE_REQUIRED_LIBRARIES pthread rt) check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP) check_function_exists(pselect HAVE_PSELECT) check_function_exists(ppoll HAVE_PPOLL) +check_include_file(linux/serial.h HAVE_LINUX_SERIAL -DHAVE_LINUX_SERIAL=1) check_function_exists(argp_parse HAVE_ARGP) if(NOT HAVE_ARGP) find_library(LIB_ARGP argp) diff --git a/config.h.cmake b/config.h.cmake index 2dc71e19..e24ef367 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -13,6 +13,9 @@ /* Defined if pselect() is available. */ #cmakedefine HAVE_PSELECT +/* Defined if linux/serial.h is available. */ +#cmakedefine HAVE_LINUX_SERIAL + /* Defined if pthread_setname_np is available. */ #cmakedefine HAVE_PTHREAD_SETNAME_NP diff --git a/configure.ac b/configure.ac index 1f377051..0e78d23f 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,7 @@ AC_SUBST(EXTRA_LIBS) AC_CHECK_FUNC([pselect], [AC_DEFINE(HAVE_PSELECT, [1], [Defined if pselect() is available.])]) AC_CHECK_FUNC([ppoll], [AC_DEFINE(HAVE_PPOLL, [1], [Defined if ppoll() is available.])]) +AC_CHECK_HEADER([linux/serial.h], [AC_DEFINE(HAVE_LINUX_SERIAL, [1], [Defined if linux/serial.h is available.])]) AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [enable code coverage tracking]), [CXXFLAGS+=" -coverage -O0"], []) AC_ARG_WITH(contrib, AS_HELP_STRING([--without-contrib], [disable inclusion of contributed sources]), [], [with_contrib=yes]) diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index 8d78cfe9..c7a892c5 100644 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -27,6 +27,9 @@ #include #include #include +#ifdef HAVE_LINUX_SERIAL +# include +#endif #include #ifdef HAVE_PPOLL # include @@ -190,6 +193,14 @@ result_t SerialDevice::open() { return RESULT_ERR_DEVICE; } +#ifdef HAVE_LINUX_SERIAL + struct serial_struct serial; + if (ioctl(m_fd, TIOCGSERIAL, &serial) == 0) { + serial.flags |= ASYNC_LOW_LATENCY; + ioctl(m_fd, TIOCSSERIAL, &serial); + } +#endif + // save current settings tcgetattr(m_fd, &m_oldSettings);