Enable errqueue support for linux kernel versions 4.0.0 and above

pull/17310/head
Yash Tibrewal 6 years ago
parent a93b6012cc
commit 66b2005cbb
  1. 10
      src/core/lib/iomgr/ev_posix.cc
  2. 39
      src/core/lib/iomgr/internal_errqueue.cc
  3. 8
      src/core/lib/iomgr/internal_errqueue.h
  4. 2
      src/core/lib/iomgr/iomgr.cc
  5. 3
      src/core/lib/iomgr/port.h

@ -36,6 +36,7 @@
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
#include "src/core/lib/iomgr/ev_epollex_linux.h"
#include "src/core/lib/iomgr/ev_poll_posix.h"
#include "src/core/lib/iomgr/internal_errqueue.h"
grpc_core::TraceFlag grpc_polling_trace(false,
"polling"); /* Disabled by default */
@ -236,12 +237,11 @@ void grpc_event_engine_shutdown(void) {
}
bool grpc_event_engine_can_track_errors(void) {
/* Only track errors if platform supports errqueue. */
#ifdef GRPC_LINUX_ERRQUEUE
return g_event_engine->can_track_err;
#else
/* Only track errors if platform supports errqueue. */
if (grpc_core::kernel_supports_errqueue()) {
return g_event_engine->can_track_err;
}
return false;
#endif /* GRPC_LINUX_ERRQUEUE */
}
grpc_fd* grpc_fd_create(int fd, const char* name, bool track_err) {

@ -20,17 +20,50 @@
#include "src/core/lib/iomgr/port.h"
#include <grpc/impl/codegen/log.h>
#include "src/core/lib/iomgr/internal_errqueue.h"
#ifdef GRPC_POSIX_SOCKET_TCP
bool kernel_supports_errqueue() {
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
namespace grpc_core {
static bool errqueue_supported = false;
bool kernel_supports_errqueue() { return errqueue_supported; }
void grpc_errqueue_init() {
/* Both-compile time and run-time linux kernel versions should be atleast 4.0.0
*/
#ifdef LINUX_VERSION_CODE
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
return true;
struct utsname buffer;
if (uname(&buffer) != 0) {
gpr_log(GPR_ERROR, "uname: %s", strerror(errno));
return;
}
char* release = buffer.release;
if (release == nullptr) {
return;
}
if (strtol(release, nullptr, 10) >= 4) {
errqueue_supported = true;
} else {
gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled");
}
#endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(4, 0, 0) */
#endif /* LINUX_VERSION_CODE */
return false;
}
} /* namespace grpc_core */
#else
namespace grpc_core {
void grpc_errqueue_init() {}
} /* namespace grpc_core */
#endif /* GRPC_POSIX_SOCKET_TCP */

@ -76,8 +76,14 @@ constexpr uint32_t kTimestampingRecordingOptions =
* Currently allowing only linux kernels above 4.0.0
*/
bool kernel_supports_errqueue();
} // namespace grpc_core
} /* namespace grpc_core */
#endif /* GRPC_POSIX_SOCKET_TCP */
namespace grpc_core {
/* Initializes errqueue support */
void grpc_errqueue_init();
} /* namespace grpc_core */
#endif /* GRPC_CORE_LIB_IOMGR_INTERNAL_ERRQUEUE_H */

@ -36,6 +36,7 @@
#include "src/core/lib/iomgr/buffer_list.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/internal_errqueue.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/network_status_tracker.h"
#include "src/core/lib/iomgr/timer.h"
@ -58,6 +59,7 @@ void grpc_iomgr_init() {
g_root_object.name = (char*)"root";
grpc_network_status_init();
grpc_iomgr_platform_init();
grpc_core::grpc_errqueue_init();
}
void grpc_iomgr_start() { grpc_timer_manager_init(); }

@ -62,8 +62,7 @@
#define GRPC_HAVE_UNIX_SOCKET 1
#ifdef LINUX_VERSION_CODE
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
/* TODO(yashykt): Re-enable once Fathom changes are commited.
#define GRPC_LINUX_ERRQUEUE 1 */
#define GRPC_LINUX_ERRQUEUE 1
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) */
#endif /* LINUX_VERSION_CODE */
#define GRPC_LINUX_MULTIPOLL_WITH_EPOLL 1

Loading…
Cancel
Save