Merge pull request #17310 from yashykt/enableerrqueue

Enable errqueue support for linux kernel versions 4.0.0 and above
pull/17326/head
Yash Tibrewal 6 years ago committed by GitHub
commit 5749f80830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      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
  6. 14
      src/core/lib/iomgr/tcp_posix.cc

@ -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,19 +237,18 @@ 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) {
GRPC_POLLING_API_TRACE("fd_create(%d, %s, %d)", fd, name, track_err);
GRPC_FD_TRACE("fd_create(%d, %s, %d)", fd, name, track_err);
return g_event_engine->fd_create(fd, name,
track_err && g_event_engine->can_track_err);
return g_event_engine->fd_create(
fd, name, track_err && grpc_event_engine_can_track_errors());
}
int grpc_fd_wrapped_fd(grpc_fd* fd) {

@ -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

@ -740,7 +740,7 @@ static bool process_errors(grpc_tcp* tcp) {
}
return false;
}
process_timestamp(tcp, &msg, cmsg);
cmsg = process_timestamp(tcp, &msg, cmsg);
}
}
}
@ -761,13 +761,11 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
/* We are still interested in collecting timestamps, so let's try reading
* them. */
if (!process_errors(tcp)) {
/* This was not a timestamps error. This was an actual error. Set the
* read and write closures to be ready.
*/
grpc_fd_set_readable(tcp->em_fd);
grpc_fd_set_writable(tcp->em_fd);
}
process_errors(tcp);
/* This might not a timestamps error. Set the read and write closures to be
* ready. */
grpc_fd_set_readable(tcp->em_fd);
grpc_fd_set_writable(tcp->em_fd);
GRPC_CLOSURE_INIT(&tcp->error_closure, tcp_handle_error, tcp,
grpc_schedule_on_exec_ctx);
grpc_fd_notify_on_error(tcp->em_fd, &tcp->error_closure);

Loading…
Cancel
Save