Skip to content

Commit

Permalink
Revert "Remove unused eventmanager_libuv code (grpc#25796)" (grpc#25807)
Browse files Browse the repository at this point in the history
This caused problems internally. The interface deletion needs a cherrypick, but I will do an overnight test first, before I reintroduce. CC @nicolasnoble
  • Loading branch information
drfloob authored Mar 25, 2021
1 parent 801c2fd commit 1694984
Show file tree
Hide file tree
Showing 21 changed files with 466 additions and 0 deletions.
23 changes: 23 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ grpc_cc_library(
public_hdrs = GRPC_PUBLIC_HDRS,
deps = [
"dual_ref_counted",
"eventmanager_libuv",
"gpr_base",
"grpc_codegen",
"grpc_trace",
Expand Down Expand Up @@ -3604,3 +3605,25 @@ filegroup(
],
visibility = ["//visibility:public"],
)

# Base classes of EventManagerInterface
grpc_cc_library(
name = "eventmanager_interface",
hdrs = [
"src/core/lib/iomgr/poller/eventmanager_interface.h",
],
)

# Libuv-based EventManager implementation
grpc_cc_library(
name = "eventmanager_libuv",
srcs = [
"src/core/lib/iomgr/poller/eventmanager_libuv.cc",
],
hdrs = [
"src/core/lib/iomgr/poller/eventmanager_libuv.h",
],
deps = [
"gpr_base",
],
)
2 changes: 2 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ config("grpc_config") {
"src/core/lib/iomgr/nameser.h",
"src/core/lib/iomgr/parse_address.cc",
"src/core/lib/iomgr/parse_address.h",
"src/core/lib/iomgr/poller/eventmanager_libuv.cc",
"src/core/lib/iomgr/poller/eventmanager_libuv.h",
"src/core/lib/iomgr/polling_entity.cc",
"src/core/lib/iomgr/polling_entity.h",
"src/core/lib/iomgr/pollset.cc",
Expand Down
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx end2end_test)
add_dependencies(buildtests_cxx error_details_test)
add_dependencies(buildtests_cxx evaluate_args_test)
add_dependencies(buildtests_cxx eventmanager_libuv_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx examine_stack_test)
endif()
Expand Down Expand Up @@ -1836,6 +1837,7 @@ add_library(grpc
src/core/lib/iomgr/load_file.cc
src/core/lib/iomgr/lockfree_event.cc
src/core/lib/iomgr/parse_address.cc
src/core/lib/iomgr/poller/eventmanager_libuv.cc
src/core/lib/iomgr/polling_entity.cc
src/core/lib/iomgr/pollset.cc
src/core/lib/iomgr/pollset_custom.cc
Expand Down Expand Up @@ -2462,6 +2464,7 @@ add_library(grpc_unsecure
src/core/lib/iomgr/load_file.cc
src/core/lib/iomgr/lockfree_event.cc
src/core/lib/iomgr/parse_address.cc
src/core/lib/iomgr/poller/eventmanager_libuv.cc
src/core/lib/iomgr/polling_entity.cc
src/core/lib/iomgr/pollset.cc
src/core/lib/iomgr/pollset_custom.cc
Expand Down Expand Up @@ -10280,6 +10283,41 @@ target_link_libraries(evaluate_args_test
)


endif()
if(gRPC_BUILD_TESTS)

add_executable(eventmanager_libuv_test
test/core/iomgr/poller/eventmanager_libuv_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)

target_include_directories(eventmanager_libuv_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)

target_link_libraries(eventmanager_libuv_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)


endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ LIBGRPC_SRC = \
src/core/lib/iomgr/load_file.cc \
src/core/lib/iomgr/lockfree_event.cc \
src/core/lib/iomgr/parse_address.cc \
src/core/lib/iomgr/poller/eventmanager_libuv.cc \
src/core/lib/iomgr/polling_entity.cc \
src/core/lib/iomgr/pollset.cc \
src/core/lib/iomgr/pollset_custom.cc \
Expand Down Expand Up @@ -1882,6 +1883,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/iomgr/load_file.cc \
src/core/lib/iomgr/lockfree_event.cc \
src/core/lib/iomgr/parse_address.cc \
src/core/lib/iomgr/poller/eventmanager_libuv.cc \
src/core/lib/iomgr/polling_entity.cc \
src/core/lib/iomgr/pollset.cc \
src/core/lib/iomgr/pollset_custom.cc \
Expand Down
14 changes: 14 additions & 0 deletions build_autogenerated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ libs:
- src/core/lib/iomgr/lockfree_event.h
- src/core/lib/iomgr/nameser.h
- src/core/lib/iomgr/parse_address.h
- src/core/lib/iomgr/poller/eventmanager_libuv.h
- src/core/lib/iomgr/polling_entity.h
- src/core/lib/iomgr/pollset.h
- src/core/lib/iomgr/pollset_custom.h
Expand Down Expand Up @@ -1249,6 +1250,7 @@ libs:
- src/core/lib/iomgr/load_file.cc
- src/core/lib/iomgr/lockfree_event.cc
- src/core/lib/iomgr/parse_address.cc
- src/core/lib/iomgr/poller/eventmanager_libuv.cc
- src/core/lib/iomgr/polling_entity.cc
- src/core/lib/iomgr/pollset.cc
- src/core/lib/iomgr/pollset_custom.cc
Expand Down Expand Up @@ -1736,6 +1738,7 @@ libs:
- src/core/lib/iomgr/lockfree_event.h
- src/core/lib/iomgr/nameser.h
- src/core/lib/iomgr/parse_address.h
- src/core/lib/iomgr/poller/eventmanager_libuv.h
- src/core/lib/iomgr/polling_entity.h
- src/core/lib/iomgr/pollset.h
- src/core/lib/iomgr/pollset_custom.h
Expand Down Expand Up @@ -1996,6 +1999,7 @@ libs:
- src/core/lib/iomgr/load_file.cc
- src/core/lib/iomgr/lockfree_event.cc
- src/core/lib/iomgr/parse_address.cc
- src/core/lib/iomgr/poller/eventmanager_libuv.cc
- src/core/lib/iomgr/polling_entity.cc
- src/core/lib/iomgr/pollset.cc
- src/core/lib/iomgr/pollset_custom.cc
Expand Down Expand Up @@ -5033,6 +5037,16 @@ targets:
- test/core/security/evaluate_args_test.cc
deps:
- grpc_test_util
- name: eventmanager_libuv_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/iomgr/poller/eventmanager_libuv_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: examine_stack_test
gtest: true
build: test
Expand Down
2 changes: 2 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/iomgr/load_file.cc \
src/core/lib/iomgr/lockfree_event.cc \
src/core/lib/iomgr/parse_address.cc \
src/core/lib/iomgr/poller/eventmanager_libuv.cc \
src/core/lib/iomgr/polling_entity.cc \
src/core/lib/iomgr/pollset.cc \
src/core/lib/iomgr/pollset_custom.cc \
Expand Down Expand Up @@ -1157,6 +1158,7 @@ if test "$PHP_GRPC" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/http)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr/executor)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr/poller)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/json)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/matchers)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/profiling)
Expand Down
2 changes: 2 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\iomgr\\load_file.cc " +
"src\\core\\lib\\iomgr\\lockfree_event.cc " +
"src\\core\\lib\\iomgr\\parse_address.cc " +
"src\\core\\lib\\iomgr\\poller\\eventmanager_libuv.cc " +
"src\\core\\lib\\iomgr\\polling_entity.cc " +
"src\\core\\lib\\iomgr\\pollset.cc " +
"src\\core\\lib\\iomgr\\pollset_custom.cc " +
Expand Down Expand Up @@ -1257,6 +1258,7 @@ if (PHP_GRPC != "no") {
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\http");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr\\executor");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr\\poller");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\json");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\matchers");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\profiling");
Expand Down
2 changes: 2 additions & 0 deletions gRPC-C++.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/lockfree_event.h',
'src/core/lib/iomgr/nameser.h',
'src/core/lib/iomgr/parse_address.h',
'src/core/lib/iomgr/poller/eventmanager_libuv.h',
'src/core/lib/iomgr/polling_entity.h',
'src/core/lib/iomgr/pollset.h',
'src/core/lib/iomgr/pollset_custom.h',
Expand Down Expand Up @@ -1221,6 +1222,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/lockfree_event.h',
'src/core/lib/iomgr/nameser.h',
'src/core/lib/iomgr/parse_address.h',
'src/core/lib/iomgr/poller/eventmanager_libuv.h',
'src/core/lib/iomgr/polling_entity.h',
'src/core/lib/iomgr/pollset.h',
'src/core/lib/iomgr/pollset_custom.h',
Expand Down
3 changes: 3 additions & 0 deletions gRPC-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,8 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/nameser.h',
'src/core/lib/iomgr/parse_address.cc',
'src/core/lib/iomgr/parse_address.h',
'src/core/lib/iomgr/poller/eventmanager_libuv.cc',
'src/core/lib/iomgr/poller/eventmanager_libuv.h',
'src/core/lib/iomgr/polling_entity.cc',
'src/core/lib/iomgr/polling_entity.h',
'src/core/lib/iomgr/pollset.cc',
Expand Down Expand Up @@ -1778,6 +1780,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/lockfree_event.h',
'src/core/lib/iomgr/nameser.h',
'src/core/lib/iomgr/parse_address.h',
'src/core/lib/iomgr/poller/eventmanager_libuv.h',
'src/core/lib/iomgr/polling_entity.h',
'src/core/lib/iomgr/pollset.h',
'src/core/lib/iomgr/pollset_custom.h',
Expand Down
2 changes: 2 additions & 0 deletions grpc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/iomgr/nameser.h )
s.files += %w( src/core/lib/iomgr/parse_address.cc )
s.files += %w( src/core/lib/iomgr/parse_address.h )
s.files += %w( src/core/lib/iomgr/poller/eventmanager_libuv.cc )
s.files += %w( src/core/lib/iomgr/poller/eventmanager_libuv.h )
s.files += %w( src/core/lib/iomgr/polling_entity.cc )
s.files += %w( src/core/lib/iomgr/polling_entity.h )
s.files += %w( src/core/lib/iomgr/pollset.cc )
Expand Down
2 changes: 2 additions & 0 deletions grpc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@
'src/core/lib/iomgr/load_file.cc',
'src/core/lib/iomgr/lockfree_event.cc',
'src/core/lib/iomgr/parse_address.cc',
'src/core/lib/iomgr/poller/eventmanager_libuv.cc',
'src/core/lib/iomgr/polling_entity.cc',
'src/core/lib/iomgr/pollset.cc',
'src/core/lib/iomgr/pollset_custom.cc',
Expand Down Expand Up @@ -1270,6 +1271,7 @@
'src/core/lib/iomgr/load_file.cc',
'src/core/lib/iomgr/lockfree_event.cc',
'src/core/lib/iomgr/parse_address.cc',
'src/core/lib/iomgr/poller/eventmanager_libuv.cc',
'src/core/lib/iomgr/polling_entity.cc',
'src/core/lib/iomgr/pollset.cc',
'src/core/lib/iomgr/pollset_custom.cc',
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@
<file baseinstalldir="/" name="src/core/lib/iomgr/nameser.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/parse_address.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/parse_address.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/poller/eventmanager_libuv.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/poller/eventmanager_libuv.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/polling_entity.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/polling_entity.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/pollset.cc" role="src" />
Expand Down
35 changes: 35 additions & 0 deletions src/core/lib/iomgr/poller/eventmanager_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_INTERFACE_H
#define GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_INTERFACE_H

namespace grpc {
namespace experimental {

class BaseEventManagerInterface {
public:
virtual ~BaseEventManagerInterface() {}
};

class EpollEventManagerInterface : public BaseEventManagerInterface {};

} // namespace experimental
} // namespace grpc

#endif /* GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_INTERFACE_H */
88 changes: 88 additions & 0 deletions src/core/lib/iomgr/poller/eventmanager_libuv.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <grpc/support/port_platform.h>

#include "src/core/lib/iomgr/poller/eventmanager_libuv.h"

#include <grpc/support/time.h>

grpc::experimental::LibuvEventManager::Options::Options() : num_workers_(-1) {}
grpc::experimental::LibuvEventManager::Options::Options(int num_workers)
: num_workers_(num_workers) {}

grpc::experimental::LibuvEventManager::LibuvEventManager(const Options& options)
: options_(options) {
int num_workers = options_.num_workers();
// Number of workers can't be 0 if we do not accept thread donation.
// TODO(guantaol): replaces the hard-coded number with a flag.
if (num_workers <= 0) num_workers = 32;

for (int i = 0; i < num_workers; i++) {
workers_.emplace_back(
options_.thread_name_prefix().c_str(),
[](void* em) { static_cast<LibuvEventManager*>(em)->RunWorkerLoop(); },
this);
workers_.back().Start();
}
}

grpc::experimental::LibuvEventManager::~LibuvEventManager() {
Shutdown();
for (auto& th : workers_) {
th.Join();
}
}

void grpc::experimental::LibuvEventManager::RunWorkerLoop() {
while (true) {
// TODO(guantaol): extend the worker loop with real work.
if (ShouldStop()) return;
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_micros(10, GPR_TIMESPAN)));
}
}

bool grpc::experimental::LibuvEventManager::ShouldStop() {
return should_stop_.Load(grpc_core::MemoryOrder::ACQUIRE) != 0;
}

void grpc::experimental::LibuvEventManager::Shutdown() {
if (should_stop_.Load(grpc_core::MemoryOrder::ACQUIRE)) {
return; // Already shut down.
}

{
grpc_core::MutexLock lock(&shutdown_mu_);
while (shutdown_refcount_.Load(grpc_core::MemoryOrder::ACQUIRE) > 0) {
shutdown_cv_.Wait(&shutdown_mu_);
}
}
should_stop_.Store(true, grpc_core::MemoryOrder::RELEASE);
}

void grpc::experimental::LibuvEventManager::ShutdownRef() {
shutdown_refcount_.FetchAdd(1, grpc_core::MemoryOrder::RELAXED);
}

void grpc::experimental::LibuvEventManager::ShutdownUnref() {
if (shutdown_refcount_.FetchSub(1, grpc_core::MemoryOrder::ACQ_REL) == 1) {
grpc_core::MutexLock lock(&shutdown_mu_);
shutdown_cv_.Signal();
}
}
Loading

0 comments on commit 1694984

Please sign in to comment.