Skip to content

Commit

Permalink
set ASYNC_LOW_LATENCY flag on serial device just like setserial does …
Browse files Browse the repository at this point in the history
…to fix huge latency found on recent kernel versions
  • Loading branch information
john30 committed Jun 3, 2017
1 parent 9a1a274 commit 343a443
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
11 changes: 11 additions & 0 deletions src/lib/ebus/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#ifdef HAVE_LINUX_SERIAL
# include <linux/serial.h>
#endif
#include <errno.h>
#ifdef HAVE_PPOLL
# include <poll.h>
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 343a443

Please sign in to comment.