diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b30f2d881a..38f0363914c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -582,9 +582,6 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_c combiner_test) endif() - if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) - add_dependencies(buildtests_c competition) - endif() add_dependencies(buildtests_c completion_queue_threading_test) add_dependencies(buildtests_c compression_test) add_dependencies(buildtests_c concurrent_connectivity_test) @@ -4943,106 +4940,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) ) -endif() -endif() -if(gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) - - add_executable(competition - src/core/ext/upb-generated/google/api/annotations.upb.c - src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c - src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c - src/core/ext/upb-generated/google/api/http.upb.c - src/core/ext/upb-generated/google/protobuf/any.upb.c - src/core/ext/upb-generated/google/protobuf/duration.upb.c - src/core/ext/upb-generated/google/protobuf/empty.upb.c - src/core/ext/upb-generated/google/protobuf/struct.upb.c - src/core/ext/upb-generated/google/protobuf/timestamp.upb.c - src/core/ext/upb-generated/google/protobuf/wrappers.upb.c - src/core/ext/upb-generated/google/rpc/status.upb.c - src/core/lib/gpr/alloc.cc - src/core/lib/gpr/atm.cc - src/core/lib/gpr/cpu_iphone.cc - src/core/lib/gpr/cpu_linux.cc - src/core/lib/gpr/cpu_posix.cc - src/core/lib/gpr/cpu_windows.cc - src/core/lib/gpr/env_linux.cc - src/core/lib/gpr/env_posix.cc - src/core/lib/gpr/env_windows.cc - src/core/lib/gpr/log.cc - src/core/lib/gpr/log_android.cc - src/core/lib/gpr/log_linux.cc - src/core/lib/gpr/log_posix.cc - src/core/lib/gpr/log_windows.cc - src/core/lib/gpr/murmur_hash.cc - src/core/lib/gpr/string.cc - src/core/lib/gpr/string_posix.cc - src/core/lib/gpr/string_util_windows.cc - src/core/lib/gpr/string_windows.cc - src/core/lib/gpr/sync.cc - src/core/lib/gpr/sync_abseil.cc - src/core/lib/gpr/sync_posix.cc - src/core/lib/gpr/sync_windows.cc - src/core/lib/gpr/time.cc - src/core/lib/gpr/time_posix.cc - src/core/lib/gpr/time_precise.cc - src/core/lib/gpr/time_windows.cc - src/core/lib/gpr/tmpfile_msys.cc - src/core/lib/gpr/tmpfile_posix.cc - src/core/lib/gpr/tmpfile_windows.cc - src/core/lib/gpr/wrap_memcpy.cc - src/core/lib/gprpp/arena.cc - src/core/lib/gprpp/examine_stack.cc - src/core/lib/gprpp/fork.cc - src/core/lib/gprpp/global_config_env.cc - src/core/lib/gprpp/host_port.cc - src/core/lib/gprpp/mpscq.cc - src/core/lib/gprpp/stat_posix.cc - src/core/lib/gprpp/stat_windows.cc - src/core/lib/gprpp/status_helper.cc - src/core/lib/gprpp/thd_posix.cc - src/core/lib/gprpp/thd_windows.cc - src/core/lib/gprpp/time_util.cc - src/core/lib/profiling/basic_timers.cc - src/core/lib/profiling/stap_timers.cc - src/core/lib/promise/activity.cc - test/core/promise/benchmark/competition.cc - test/core/promise/benchmark/filter_stack.cc - ) - - target_include_directories(competition - 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} - ) - - target_link_libraries(competition - ${_gRPC_ALLTARGETS_LIBRARIES} - absl::base - absl::core_headers - absl::memory - absl::status - absl::statusor - absl::cord - absl::str_format - absl::strings - absl::synchronization - absl::time - absl::optional - absl::variant - ${_gRPC_BENCHMARK_LIBRARIES} - upb - ) - - endif() endif() if(gRPC_BUILD_TESTS) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index b62853e5ce6..e39714a47d7 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -3218,150 +3218,6 @@ targets: - linux - posix - mac -- name: competition - build: test - language: c - headers: - - src/core/ext/upb-generated/google/api/annotations.upb.h - - src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h - - src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h - - src/core/ext/upb-generated/google/api/http.upb.h - - src/core/ext/upb-generated/google/protobuf/any.upb.h - - src/core/ext/upb-generated/google/protobuf/duration.upb.h - - src/core/ext/upb-generated/google/protobuf/empty.upb.h - - src/core/ext/upb-generated/google/protobuf/struct.upb.h - - src/core/ext/upb-generated/google/protobuf/timestamp.upb.h - - src/core/ext/upb-generated/google/protobuf/wrappers.upb.h - - src/core/ext/upb-generated/google/rpc/status.upb.h - - src/core/lib/gpr/alloc.h - - src/core/lib/gpr/env.h - - src/core/lib/gpr/murmur_hash.h - - src/core/lib/gpr/spinlock.h - - src/core/lib/gpr/string.h - - src/core/lib/gpr/string_windows.h - - src/core/lib/gpr/time_precise.h - - src/core/lib/gpr/tls.h - - src/core/lib/gpr/tmpfile.h - - src/core/lib/gpr/useful.h - - src/core/lib/gprpp/arena.h - - src/core/lib/gprpp/atomic_utils.h - - src/core/lib/gprpp/bitset.h - - src/core/lib/gprpp/construct_destruct.h - - src/core/lib/gprpp/debug_location.h - - src/core/lib/gprpp/examine_stack.h - - src/core/lib/gprpp/fork.h - - src/core/lib/gprpp/global_config.h - - src/core/lib/gprpp/global_config_custom.h - - src/core/lib/gprpp/global_config_env.h - - src/core/lib/gprpp/global_config_generic.h - - src/core/lib/gprpp/host_port.h - - src/core/lib/gprpp/manual_constructor.h - - src/core/lib/gprpp/memory.h - - src/core/lib/gprpp/mpscq.h - - src/core/lib/gprpp/stat.h - - src/core/lib/gprpp/status_helper.h - - src/core/lib/gprpp/sync.h - - src/core/lib/gprpp/thd.h - - src/core/lib/gprpp/time_util.h - - src/core/lib/profiling/timers.h - - src/core/lib/promise/activity.h - - src/core/lib/promise/context.h - - src/core/lib/promise/detail/basic_join.h - - src/core/lib/promise/detail/basic_seq.h - - src/core/lib/promise/detail/promise_factory.h - - src/core/lib/promise/detail/promise_like.h - - src/core/lib/promise/detail/status.h - - src/core/lib/promise/detail/switch.h - - src/core/lib/promise/for_each.h - - src/core/lib/promise/intra_activity_waiter.h - - src/core/lib/promise/join.h - - src/core/lib/promise/latch.h - - src/core/lib/promise/pipe.h - - src/core/lib/promise/poll.h - - src/core/lib/promise/seq.h - - src/core/lib/promise/try_join.h - - src/core/lib/promise/try_seq.h - src: - - src/core/ext/upb-generated/google/api/annotations.upb.c - - src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c - - src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c - - src/core/ext/upb-generated/google/api/http.upb.c - - src/core/ext/upb-generated/google/protobuf/any.upb.c - - src/core/ext/upb-generated/google/protobuf/duration.upb.c - - src/core/ext/upb-generated/google/protobuf/empty.upb.c - - src/core/ext/upb-generated/google/protobuf/struct.upb.c - - src/core/ext/upb-generated/google/protobuf/timestamp.upb.c - - src/core/ext/upb-generated/google/protobuf/wrappers.upb.c - - src/core/ext/upb-generated/google/rpc/status.upb.c - - src/core/lib/gpr/alloc.cc - - src/core/lib/gpr/atm.cc - - src/core/lib/gpr/cpu_iphone.cc - - src/core/lib/gpr/cpu_linux.cc - - src/core/lib/gpr/cpu_posix.cc - - src/core/lib/gpr/cpu_windows.cc - - src/core/lib/gpr/env_linux.cc - - src/core/lib/gpr/env_posix.cc - - src/core/lib/gpr/env_windows.cc - - src/core/lib/gpr/log.cc - - src/core/lib/gpr/log_android.cc - - src/core/lib/gpr/log_linux.cc - - src/core/lib/gpr/log_posix.cc - - src/core/lib/gpr/log_windows.cc - - src/core/lib/gpr/murmur_hash.cc - - src/core/lib/gpr/string.cc - - src/core/lib/gpr/string_posix.cc - - src/core/lib/gpr/string_util_windows.cc - - src/core/lib/gpr/string_windows.cc - - src/core/lib/gpr/sync.cc - - src/core/lib/gpr/sync_abseil.cc - - src/core/lib/gpr/sync_posix.cc - - src/core/lib/gpr/sync_windows.cc - - src/core/lib/gpr/time.cc - - src/core/lib/gpr/time_posix.cc - - src/core/lib/gpr/time_precise.cc - - src/core/lib/gpr/time_windows.cc - - src/core/lib/gpr/tmpfile_msys.cc - - src/core/lib/gpr/tmpfile_posix.cc - - src/core/lib/gpr/tmpfile_windows.cc - - src/core/lib/gpr/wrap_memcpy.cc - - src/core/lib/gprpp/arena.cc - - src/core/lib/gprpp/examine_stack.cc - - src/core/lib/gprpp/fork.cc - - src/core/lib/gprpp/global_config_env.cc - - src/core/lib/gprpp/host_port.cc - - src/core/lib/gprpp/mpscq.cc - - src/core/lib/gprpp/stat_posix.cc - - src/core/lib/gprpp/stat_windows.cc - - src/core/lib/gprpp/status_helper.cc - - src/core/lib/gprpp/thd_posix.cc - - src/core/lib/gprpp/thd_windows.cc - - src/core/lib/gprpp/time_util.cc - - src/core/lib/profiling/basic_timers.cc - - src/core/lib/profiling/stap_timers.cc - - src/core/lib/promise/activity.cc - - test/core/promise/benchmark/competition.cc - - test/core/promise/benchmark/filter_stack.cc - deps: - - absl/base:base - - absl/base:core_headers - - absl/memory:memory - - absl/status:status - - absl/status:statusor - - absl/strings:cord - - absl/strings:str_format - - absl/strings:strings - - absl/synchronization:synchronization - - absl/time:time - - absl/types:optional - - absl/types:variant - - benchmark - - upb - benchmark: true - defaults: benchmark - platforms: - - linux - - posix - uses_polling: false - name: completion_queue_threading_test build: test run: false diff --git a/test/core/promise/benchmark/BUILD b/test/core/promise/benchmark/BUILD deleted file mode 100644 index 63178eee09a..00000000000 --- a/test/core/promise/benchmark/BUILD +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2021 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. - -licenses(["notice"]) - -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") - -grpc_cc_test( - name = "competition", - srcs = [ - "competition.cc", - "filter_stack.cc", - "filter_stack.h", - ], - external_deps = [ - "benchmark", - "absl/synchronization", - ], - tags = [ - "no_mac", - "no_windows", - ], - uses_polling = False, - deps = [ - "//:activity", - "//:for_each", - "//:join", - "//:latch", - "//:pipe", - "//:seq", - "//:try_join", - "//:try_seq", - "//test/core/util:grpc_suppressions", - ], -) diff --git a/test/core/promise/benchmark/competition.cc b/test/core/promise/benchmark/competition.cc deleted file mode 100644 index f0d1592cfca..00000000000 --- a/test/core/promise/benchmark/competition.cc +++ /dev/null @@ -1,491 +0,0 @@ -// Copyright 2021 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. - -/* This benchmark exists to ensure that immediately-firing alarms are fast */ - -#include - -#include "absl/synchronization/mutex.h" - -#include "src/core/lib/promise/activity.h" -#include "src/core/lib/promise/context.h" -#include "src/core/lib/promise/for_each.h" -#include "src/core/lib/promise/join.h" -#include "src/core/lib/promise/latch.h" -#include "src/core/lib/promise/pipe.h" -#include "src/core/lib/promise/seq.h" -#include "src/core/lib/promise/try_join.h" -#include "src/core/lib/promise/try_seq.h" -#include "test/core/promise/benchmark/filter_stack.h" - -namespace filter_stack { - -Filter passthrough_filter = { - CallNextOp, NoCallData, NoCallData, NoChannelData, NoChannelData, 0, 0, -}; - -struct Interject { - Closure c; - Closure* next; - - static void Callback(void* p, absl::Status status) { - auto* i = static_cast(p); - i->next->Run(std::move(status)); - } - - static void Init(CallElem* elem) { - auto* i = static_cast(elem->call_data); - i->c.f = Callback; - i->c.p = i; - } - - static void Destroy(CallElem*) {} - - static void StartOp(CallElem* elem, Op* op) { - auto* i = static_cast(elem->call_data); - if (op->recv_initial_metadata) { - i->next = op->on_complete; - op->on_complete = &i->c; - } - CallNextOp(elem, op); - } -}; - -Filter interject_filter = { - Interject::StartOp, - Interject::Init, - Interject::Destroy, - NoChannelData, - NoChannelData, - sizeof(Interject), - 0, -}; - -struct InterjectPipe { - Closure c_init_metadata; - Closure* next_init_metadata; - Closure c_payload; - Closure* next_payload; - Closure c_trailing_metadata; - Closure* next_trailing_metadata; - - static void CallbackInitMetadata(void* p, absl::Status status) { - auto* i = static_cast(p); - i->next_init_metadata->Run(std::move(status)); - } - - static void CallbackPayload(void* p, absl::Status status) { - auto* i = static_cast(p); - i->next_payload->Run(std::move(status)); - } - - static void CallbackTrailingMetadata(void* p, absl::Status status) { - auto* i = static_cast(p); - i->next_trailing_metadata->Run(std::move(status)); - } - - static void Init(CallElem* elem) { - auto* i = static_cast(elem->call_data); - i->c_init_metadata.f = CallbackInitMetadata; - i->c_init_metadata.p = i; - i->c_payload.f = CallbackPayload; - i->c_payload.p = i; - i->c_trailing_metadata.f = CallbackTrailingMetadata; - i->c_trailing_metadata.p = i; - } - - static void Destroy(CallElem*) {} - - static void StartOp(CallElem* elem, Op* op) { - auto* i = static_cast(elem->call_data); - if (op->recv_trailing_metadata) { - i->next_trailing_metadata = op->on_complete; - op->on_complete = &i->c_trailing_metadata; - } - if (op->recv_message) { - i->next_payload = op->on_complete; - op->on_complete = &i->c_payload; - } - if (op->recv_initial_metadata) { - i->next_init_metadata = op->on_complete; - op->on_complete = &i->c_init_metadata; - } - CallNextOp(elem, op); - } -}; - -Filter interject_pipe = { - InterjectPipe::StartOp, - InterjectPipe::Init, - InterjectPipe::Destroy, - NoChannelData, - NoChannelData, - sizeof(InterjectPipe), - 0, -}; - -void EndOp(CallElem*, Op* op) { op->on_complete->Run(absl::OkStatus()); } - -Filter end_filter = {EndOp, NoCallData, NoCallData, NoChannelData, - NoChannelData, 0, 0}; - -static void unary(benchmark::State& state, - std::initializer_list filters) { - auto* channel = - MakeChannel(const_cast(&*filters.begin()), filters.size()); - for (auto _ : state) { - auto* call = MakeCall(channel); - Op op; - Op::Payload payload; - op.recv_initial_metadata = true; - op.recv_message = true; - op.recv_trailing_metadata = true; - op.payload = &payload; - Closure done = {call, +[](void* p, absl::Status status) { - if (!status.ok()) abort(); - FreeCall(static_cast(p)); - }}; - op.on_complete = &done; - RunOp(call, &op); - } - FreeChannel(channel); -} - -static void BM_FilterStack_Passthrough3_Unary(benchmark::State& state) { - unary(state, {&passthrough_filter, &passthrough_filter, &passthrough_filter, - &end_filter}); -} -BENCHMARK(BM_FilterStack_Passthrough3_Unary); - -static void BM_FilterStack_Passthrough10_Unary(benchmark::State& state) { - unary(state, {&passthrough_filter, &passthrough_filter, &passthrough_filter, - &passthrough_filter, &passthrough_filter, &passthrough_filter, - &passthrough_filter, &passthrough_filter, &passthrough_filter, - &passthrough_filter, &end_filter}); -} -BENCHMARK(BM_FilterStack_Passthrough10_Unary); - -static void BM_FilterStack_Interject3_Unary(benchmark::State& state) { - unary(state, - {&interject_filter, &interject_filter, &interject_filter, &end_filter}); -} -BENCHMARK(BM_FilterStack_Interject3_Unary); - -static void BM_FilterStack_Interject10_Unary(benchmark::State& state) { - unary(state, {&interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &end_filter}); -} -BENCHMARK(BM_FilterStack_Interject10_Unary); - -static void BM_FilterStack_Interject30_Unary(benchmark::State& state) { - unary(state, {&interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &interject_filter, &interject_filter, &interject_filter, - &end_filter}); -} -BENCHMARK(BM_FilterStack_Interject30_Unary); - -static void BM_FilterStack_Interject3Pipe_Unary(benchmark::State& state) { - unary(state, - {&interject_pipe, &interject_pipe, &interject_pipe, &end_filter}); -} -BENCHMARK(BM_FilterStack_Interject3Pipe_Unary); - -static void BM_FilterStack_Interject10Pipe_Unary(benchmark::State& state) { - unary(state, - {&interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &end_filter}); -} -BENCHMARK(BM_FilterStack_Interject10Pipe_Unary); - -static void BM_FilterStack_Interject30Pipe_Unary(benchmark::State& state) { - unary(state, - {&interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &interject_pipe, &interject_pipe, - &interject_pipe, &interject_pipe, &end_filter}); -} -BENCHMARK(BM_FilterStack_Interject30Pipe_Unary); - -} // namespace filter_stack - -namespace grpc_core { - -namespace activity_stack { -struct RPCIO { - Latch recv_initial_metadata; -}; - -struct RPCP { - Pipe pipe; -}; -} // namespace activity_stack - -template <> -struct ContextType {}; - -template <> -struct ContextType {}; - -namespace activity_stack { - -template -static void unary(benchmark::State& state, MakeCall make_call) { - printf("activity stack size: %d\n", static_cast(make_call()->Size())); - for (auto _ : state) { - make_call(); - } -} - -static void BM_ActivityStack_Passthrough3_Unary(benchmark::State& state) { - unary(state, []() { - return MakeActivity( - []() { - auto one = []() { return absl::OkStatus(); }; - return TrySeq(one, one, one); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }); - }); -} -BENCHMARK(BM_ActivityStack_Passthrough3_Unary); - -static void BM_ActivityStack_Passthrough10_Unary(benchmark::State& state) { - unary(state, []() { - return MakeActivity( - []() { - auto one = []() { return absl::OkStatus(); }; - return TrySeq(one, one, one, one, one, one, one, one, one, one); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }); - }); -} -BENCHMARK(BM_ActivityStack_Passthrough10_Unary); - -static void BM_ActivityStack_Interject3Latches_Unary(benchmark::State& state) { - unary(state, []() { - RPCIO rpcio; - return MakeActivity( - []() { - auto one = []() { - return GetContext()->recv_initial_metadata.Wait(); - }; - return Seq(Join(one(), one(), one(), - []() { - GetContext()->recv_initial_metadata.Set(42); - return true; - }), - []() { return absl::OkStatus(); }); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }, - std::move(rpcio)); - }); -} -BENCHMARK(BM_ActivityStack_Interject3Latches_Unary); - -static void BM_ActivityStack_Interject10Latches_Unary(benchmark::State& state) { - unary(state, []() { - RPCIO rpcio; - return MakeActivity( - []() { - auto one = []() { - return GetContext()->recv_initial_metadata.Wait(); - }; - return Seq(Join(one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), - []() { - GetContext()->recv_initial_metadata.Set(42); - return true; - }), - []() { return absl::OkStatus(); }); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }, - std::move(rpcio)); - }); -} -BENCHMARK(BM_ActivityStack_Interject10Latches_Unary); - -static void BM_ActivityStack_Interject30Latches_Unary(benchmark::State& state) { - unary(state, []() { - RPCIO rpcio; - return MakeActivity( - []() { - auto one = []() { - return GetContext()->recv_initial_metadata.Wait(); - }; - return Seq( - Join(one(), one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), one(), one(), one(), - []() { - GetContext()->recv_initial_metadata.Set(42); - return true; - }), - []() { return absl::OkStatus(); }); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }, - std::move(rpcio)); - }); -} -BENCHMARK(BM_ActivityStack_Interject30Latches_Unary); - -static void BM_ActivityStack_Interject3Filters_Unary(benchmark::State& state) { - unary(state, []() { - RPCP rpcio; - return MakeActivity( - []() { - auto one = []() { - return GetContext()->pipe.sender.Filter( - [](int i) { return absl::StatusOr(i); }); - }; - return TryJoin( - one(), one(), one(), - Seq( - GetContext()->pipe.sender.Push(42), - []() { return GetContext()->pipe.sender.Push(43); }, - []() { return GetContext()->pipe.sender.Push(44); }, - []() { - auto x = std::move(GetContext()->pipe.sender); - return absl::OkStatus(); - }), - Seq( - GetContext()->pipe.receiver.Next(), - []() { return GetContext()->pipe.receiver.Next(); }, - []() { return GetContext()->pipe.receiver.Next(); }, - []() { return absl::OkStatus(); })); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }, - std::move(rpcio)); - }); -} -BENCHMARK(BM_ActivityStack_Interject3Filters_Unary); - -static void BM_ActivityStack_Interject10Filters_Unary(benchmark::State& state) { - unary(state, []() { - RPCP rpcio; - return MakeActivity( - []() { - auto one = []() { - return GetContext()->pipe.sender.Filter( - [](int i) { return absl::StatusOr(i); }); - }; - return TryJoin( - one(), one(), one(), one(), one(), one(), one(), one(), one(), - one(), - Seq( - GetContext()->pipe.sender.Push(42), - []() { return GetContext()->pipe.sender.Push(43); }, - []() { return GetContext()->pipe.sender.Push(44); }, - []() { - auto x = std::move(GetContext()->pipe.sender); - return absl::OkStatus(); - }), - Seq( - GetContext()->pipe.receiver.Next(), - []() { return GetContext()->pipe.receiver.Next(); }, - []() { return GetContext()->pipe.receiver.Next(); }, - []() { return absl::OkStatus(); })); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }, - std::move(rpcio)); - }); -} -BENCHMARK(BM_ActivityStack_Interject10Filters_Unary); - -static void BM_ActivityStack_Interject30Filters_Unary(benchmark::State& state) { - unary(state, []() { - RPCP rpcio; - return MakeActivity( - []() { - auto one = []() { - return GetContext()->pipe.sender.Filter( - [](int i) { return absl::StatusOr(i); }); - }; - return TryJoin( - one(), one(), one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), one(), one(), one(), one(), one(), one(), - one(), one(), one(), - Seq( - GetContext()->pipe.sender.Push(42), - []() { return GetContext()->pipe.sender.Push(43); }, - []() { return GetContext()->pipe.sender.Push(44); }, - []() { - auto x = std::move(GetContext()->pipe.sender); - return absl::OkStatus(); - }), - Seq( - GetContext()->pipe.receiver.Next(), - []() { return GetContext()->pipe.receiver.Next(); }, - []() { return GetContext()->pipe.receiver.Next(); }, - []() { return absl::OkStatus(); })); - }, - NoCallbackScheduler(), - [](absl::Status status) { - if (!status.ok()) abort(); - }, - std::move(rpcio)); - }); -} -BENCHMARK(BM_ActivityStack_Interject30Filters_Unary); - -} // namespace activity_stack -} // namespace grpc_core - -// Some distros have RunSpecifiedBenchmarks under the benchmark namespace, -// and others do not. This allows us to support both modes. -namespace benchmark { -void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); } -} // namespace benchmark - -int main(int argc, char** argv) { - ::benchmark::Initialize(&argc, argv); - benchmark::RunTheBenchmarksNamespaced(); - return 0; -} diff --git a/test/core/promise/benchmark/filter_stack.cc b/test/core/promise/benchmark/filter_stack.cc deleted file mode 100644 index fe438e40461..00000000000 --- a/test/core/promise/benchmark/filter_stack.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2021 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 "test/core/promise/benchmark/filter_stack.h" - -namespace filter_stack { - -ChannelStack* MakeChannel(Filter** filters, size_t num_filters) { - size_t size = sizeof(ChannelStack) + num_filters * sizeof(ChannelElem); - size_t call_size = sizeof(CallStack) + num_filters * sizeof(CallElem); - for (size_t i = 0; i < num_filters; i++) { - size += filters[i]->sizeof_channel_data; - call_size += filters[i]->sizeof_call_data; - } - char* data = new char[size]; - ChannelStack* stk = reinterpret_cast(data); - new (data) ChannelStack{0, num_filters, call_size}; - data += sizeof(ChannelStack); - char* user_data = data + num_filters * sizeof(ChannelElem); - for (size_t i = 0; i < num_filters; i++) { - new (data) ChannelElem{filters[i], user_data}; - filters[i]->init_channel_data(reinterpret_cast(data)); - data += sizeof(ChannelElem); - user_data += filters[i]->sizeof_channel_data; - } - printf("CALL STACK SIZE: %d\n", static_cast(call_size)); - return stk; -} - -void FreeChannel(ChannelStack* stk) { - ChannelElem* elems = reinterpret_cast(stk + 1); - for (size_t i = 0; i < stk->num_elems; i++) { - elems[i].filter->destroy_channel_data(&elems[i]); - } - stk->~ChannelStack(); - delete[] reinterpret_cast(stk); -} - -CallStack* MakeCall(ChannelStack* stk) { - char* data = new char[stk->call_stack_size]; - CallStack* call = reinterpret_cast(data); - new (data) CallStack{{1}, stk->num_elems, {}}; - data += sizeof(CallStack); - ChannelElem* channel_elems = reinterpret_cast(stk + 1); - char* user_data = data + stk->num_elems * sizeof(CallElem); - for (size_t i = 0; i < stk->num_elems; i++) { - new (data) CallElem{channel_elems[i].filter, channel_elems[i].channel_data, - user_data}; - channel_elems[i].filter->init_call_data(reinterpret_cast(data)); - data += sizeof(CallElem); - user_data += channel_elems[i].filter->sizeof_call_data; - } - return call; -} - -static void RefCall(CallStack* stk) { - stk->refcount.fetch_add(1, std::memory_order_relaxed); -} - -static void UnrefCall(CallStack* stk) { - if (stk->refcount.fetch_sub(1, std::memory_order_acq_rel) == 1) { - CallElem* elems = reinterpret_cast(stk + 1); - for (size_t i = 0; i < stk->num_elems; i++) { - elems[i].filter->destroy_call_data(&elems[i]); - } - stk->~CallStack(); - delete[] reinterpret_cast(stk); - } -} - -void FreeCall(CallStack* stk) { UnrefCall(stk); } - -void NoChannelData(ChannelElem*) {} -void NoCallData(CallElem*) {} - -static void StartOp(CallElem* elem, Op* op) { - elem->filter->start_transport_stream_op_batch(elem, op); -} - -void CallNextOp(CallElem* elem, Op* op) { StartOp(elem + 1, op); } - -void RunOp(CallStack* stk, Op* op) { - RefCall(stk); - { - absl::MutexLock lock(&stk->mutex); - StartOp(reinterpret_cast(stk + 1), op); - } - UnrefCall(stk); -} - -} // namespace filter_stack diff --git a/test/core/promise/benchmark/filter_stack.h b/test/core/promise/benchmark/filter_stack.h deleted file mode 100644 index 52a7d68dbb9..00000000000 --- a/test/core/promise/benchmark/filter_stack.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2021 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 FILTER_STACK_H -#define FILTER_STACK_H - -#include "absl/status/status.h" -#include "absl/synchronization/mutex.h" - -namespace filter_stack { - -struct Filter; - -struct ChannelStack { - uint64_t refcount; - size_t num_elems; - size_t call_stack_size; -}; - -struct CallStack { - std::atomic refcount; - size_t num_elems; - absl::Mutex mutex; -}; - -struct ChannelElem { - Filter* filter; - void* channel_data; -}; - -struct CallElem { - Filter* filter; - void* channel_data; - void* call_data; -}; - -struct Closure { - void* p; - void (*f)(void* p, absl::Status); - void Run(absl::Status status) { f(p, std::move(status)); } -}; - -struct Op { - struct Payload {}; - - Op() - : send_initial_metadata(false), - send_trailing_metadata(false), - send_message(false), - recv_initial_metadata(false), - recv_message(false), - recv_trailing_metadata(false), - cancel_stream(false), - is_traced(false) {} - - Op(const Op&) = delete; - Op& operator=(const Op&) = delete; - - Payload* payload = nullptr; - - Closure* on_complete = nullptr; - - bool send_initial_metadata : 1; - bool send_trailing_metadata : 1; - bool send_message : 1; - bool recv_initial_metadata : 1; - bool recv_message : 1; - bool recv_trailing_metadata : 1; - bool cancel_stream : 1; - bool is_traced : 1; -}; - -struct Filter { - void (*start_transport_stream_op_batch)(CallElem* elem, Op* op); - void (*init_call_data)(CallElem* elem); - void (*destroy_call_data)(CallElem* elem); - void (*init_channel_data)(ChannelElem* elem); - void (*destroy_channel_data)(ChannelElem* elem); - size_t sizeof_call_data; - size_t sizeof_channel_data; -}; - -ChannelStack* MakeChannel(Filter** filters, size_t num_filters); -void FreeChannel(ChannelStack* stk); -CallStack* MakeCall(ChannelStack* stk); -void FreeCall(CallStack* stk); - -void NoChannelData(ChannelElem*); -void NoCallData(CallElem*); - -void CallNextOp(CallElem* elem, Op* op); - -void RunOp(CallStack* stk, Op* op); - -} // namespace filter_stack - -#endif diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index badadbfddee..d50029cde79 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -785,26 +785,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": true, - "ci_platforms": [ - "linux", - "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "competition", - "platforms": [ - "linux", - "posix" - ], - "uses_polling": false - }, { "args": [], "benchmark": false,