From 6a1b0c8df33212dfeea63525d5a24fe762549ddc Mon Sep 17 00:00:00 2001 From: Piotr Chodorowski Date: Tue, 22 Jul 2025 12:57:34 +0200 Subject: [PATCH 1/2] Implement LoLa benchmark --- MODULE.bazel.lock | 12 +- score/mw/com/benchmark/BUILD | 30 +++ score/mw/com/benchmark/benchmark.cpp | 246 ++++++++++++++++++ score/mw/com/benchmark/benchmark.h | 56 ++++ score/mw/com/benchmark/etc/logging.json | 8 + score/mw/com/benchmark/etc/mw_com_config.json | 75 ++++++ 6 files changed, 421 insertions(+), 6 deletions(-) create mode 100644 score/mw/com/benchmark/BUILD create mode 100644 score/mw/com/benchmark/benchmark.cpp create mode 100644 score/mw/com/benchmark/benchmark.h create mode 100644 score/mw/com/benchmark/etc/logging.json create mode 100644 score/mw/com/benchmark/etc/mw_com_config.json diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 1cb4cb0b..762fcf8d 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -259,11 +259,11 @@ "https://bcr.bazel.build/modules/xz/5.4.5.bcr.5/source.json": "30c4e5c856087a60d92e2522eafd316c0661671f4478ca94c6b7bd877010210a", "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca", - "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.6/MODULE.bazel": "e937cf0a3772f93ad91f3c7af4f330b76a878bbfee06527ca1a9673b790eb896", - "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.6/source.json": "5f397158198f338129c865a4c3ae21bc5626a9664b3c3b40fa3b3c2ec1ff83bf", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.7/MODULE.bazel": "26a6764cda2bfa720e5ea6bea9e6aa4282b69f96d3b9cfcfbce1ef596ce30e43", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.7/source.json": "086122bc43f9108094fed21aaace4c0affd5abd8364af0520dbacdb76cc0546d", "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198", - "https://bcr.bazel.build/modules/zstd/1.5.6/MODULE.bazel": "471ebe7d3cdd8c6469390fcf623eb4779ff55fbee0a87f1dc57a1def468b96d4", - "https://bcr.bazel.build/modules/zstd/1.5.6/source.json": "02010c3333fc89b44fe861db049968decb6e688411f7f9d4f6791d74f9adfb51", + "https://bcr.bazel.build/modules/zstd/1.5.7/MODULE.bazel": "f5780cdbd6f4c5bb985a20f839844316fe48fb5e463056f372dbc37cfabdf450", + "https://bcr.bazel.build/modules/zstd/1.5.7/source.json": "f72c48184b6528ffc908a5a2bcbf3070c6684f3db03da2182c8ca999ae5f5cfd", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/abseil-cpp/20210324.2/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/abseil-cpp/20211102.0/MODULE.bazel": "not found", @@ -449,9 +449,9 @@ "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/xz/5.4.5.bcr.5/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zlib/1.2.11/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "not found", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zlib/1.3.1.bcr.6/MODULE.bazel": "not found", + "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zlib/1.3.1.bcr.7/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zlib/1.3.1/MODULE.bazel": "not found", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zstd/1.5.6/MODULE.bazel": "not found" + "https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/modules/zstd/1.5.7/MODULE.bazel": "not found" }, "selectedYankedVersions": {}, "moduleExtensions": { diff --git a/score/mw/com/benchmark/BUILD b/score/mw/com/benchmark/BUILD new file mode 100644 index 00000000..0d88a8ee --- /dev/null +++ b/score/mw/com/benchmark/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +load("@score-baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES") + +cc_binary( + name = "benchmark", + srcs = [ + "benchmark.cpp", + "benchmark.h", + ], + data = ["etc/mw_com_config.json"], + features = COMPILER_WARNING_FEATURES + [ + "aborts_upon_exception", + ], + deps = [ + "//score/mw/com", + "@score-baselibs//score/mw/log", + "@score-baselibs//score/language/futurecpp", + ], +) diff --git a/score/mw/com/benchmark/benchmark.cpp b/score/mw/com/benchmark/benchmark.cpp new file mode 100644 index 00000000..bdccc6de --- /dev/null +++ b/score/mw/com/benchmark/benchmark.cpp @@ -0,0 +1,246 @@ +/******************************************************************************** + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#include "score/mw/com/impl/instance_specifier.h" +#include "benchmark.h" + +#include "score/concurrency/notification.h" + +#include +#include +#include +#include +#include + +#include "score/mw/com/runtime.h" + +using namespace std::chrono_literals; +using namespace score::mw::com; +using namespace std::chrono; + +std::mutex cout_mutex{}; +score::cpp::latch benchmark_ab_start_point{3}, benchmark_ab_finish_point{3}, init_ab_sync_point{3}, deinit_ab_sync_point{2}; +score::cpp::latch benchmark_multi_start_point{1 + kThreadsMultiTotal}, benchmark_multi_finish_point{1 + kThreadsMultiTotal}, init_multi_sync_point{kThreadsMultiTotal}, deinit_multi_sync_point{kThreadsMultiTotal}; +const auto instance_specifier_skeleton_a_optional = InstanceSpecifier::Create("benchmark/SkeletonA"); +const auto instance_specifier_skeleton_b_optional = InstanceSpecifier::Create("benchmark/SkeletonB"); + +score::cpp::optional>> GetBenchmarkDataProxyEvent( + BenchmarkProxy& proxy) +{ + return proxy.dummy_benchmark_data_; +} + +void SetupThread(int cpu) +{ + auto id = std::this_thread::get_id(); + auto native_handle = *reinterpret_cast(&id); + + int max_priority = sched_get_priority_max(SCHED_RR); + struct sched_param params; + params.sched_priority = max_priority; + if (pthread_setschedparam(native_handle, SCHED_RR, ¶ms)) + { + std::cout << "Failed to setschedparam: " << std::strerror(errno) << std::endl; + std::cout << "App needs to be run as root" << std::endl; + return; + } + + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(cpu, &cpuset); + if (pthread_setaffinity_np(native_handle, sizeof(cpu_set_t), &cpuset)) + { + std::cout << "Failed to setaffinity_np: " << std::strerror(errno) << std::endl; + std::cout << "App needs to be run as root" << std::endl; + } +} + +void Transmitter(int cpu, bool starter, impl::InstanceSpecifier skeleton_instance_specifier, impl::InstanceSpecifier proxy_instance_specifier) +{ + SetupThread(cpu); + + auto create_result = BenchmarkSkeleton::Create(skeleton_instance_specifier); + if (!create_result.has_value()) + { + std::cerr << "Unable to construct skeleton: " << create_result.error() << "!" << std::endl; + return; + } + auto& skeleton = create_result.value(); + const auto offer_result = skeleton.OfferService(); + if (!offer_result.has_value()) + { + std::cerr << "Unable to offer service for skeleton: " << offer_result.error() << "!" << std::endl; + return; + } + + ServiceHandleContainer handle{}; + do + { + auto handles_result = BenchmarkProxy::FindService(proxy_instance_specifier); + if (!handles_result.has_value()) + { + std::cerr << "Unable to find service: " << handles_result.error() << "!" << std::endl; + return; + } + handle = std::move(handles_result).value(); + if (handle.size() == 0) + { + std::this_thread::sleep_for(500ms); + } + } while (handle.size() == 0); + + auto proxy_result = BenchmarkProxy::Create(std::move(handle.front())); + if (!proxy_result.has_value()) + { + std::cerr << "Unable to construct proxy: " << proxy_result.error() << "!" << std::endl; + return; + } + auto& proxy = proxy_result.value(); + + auto dummy_data_event_optional = GetBenchmarkDataProxyEvent(proxy); + if (!dummy_data_event_optional.has_value()) + { + std::cerr << "Could not get dummy_data proxy event" << std::endl; + return; + } + impl::ProxyEvent& dummy_data_event = dummy_data_event_optional.value().get(); + score::Result> sample_result; + + dummy_data_event.Subscribe(1); + + init_ab_sync_point.arrive_and_wait(); + benchmark_ab_start_point.arrive_and_wait(); + if (starter) + { + do { + sample_result = skeleton.dummy_benchmark_data_.Allocate(); + } while (!sample_result.has_value()); + skeleton.dummy_benchmark_data_.Send(std::move(sample_result).value()); + } + for (std::size_t cycle = 0U; cycle < kIterations; cycle++) + { + while (!dummy_data_event.GetNewSamples(( + [](SamplePtr sample) noexcept { + std::ignore = sample; + }), + 1).has_value()) {}; + do { + sample_result = skeleton.dummy_benchmark_data_.Allocate(); + } while (!sample_result.has_value()); + skeleton.dummy_benchmark_data_.Send(std::move(sample_result).value()); + + } + benchmark_ab_finish_point.arrive_and_wait(); + dummy_data_event.Unsubscribe(); + deinit_ab_sync_point.arrive_and_wait(); + skeleton.StopOfferService(); +} + +void Subscriber(int cpu, impl::InstanceSpecifier proxy_instance_specifier) +{ + SetupThread(cpu); + + ServiceHandleContainer handle{}; + do + { + auto handles_result = BenchmarkProxy::FindService(proxy_instance_specifier); + if (!handles_result.has_value()) + { + std::cerr << "Unable to find service: " << handles_result.error() << "!" << std::endl; + return; + } + handle = std::move(handles_result).value(); + if (handle.size() == 0) + { + std::this_thread::sleep_for(500ms); + } + } while (handle.size() == 0); + + auto proxy_result = BenchmarkProxy::Create(std::move(handle.front())); + if (!proxy_result.has_value()) + { + std::cerr << "Unable to construct proxy: " << proxy_result.error() << "!" << std::endl; + return; + } + auto& proxy = proxy_result.value(); + + auto dummy_data_event_optional = GetBenchmarkDataProxyEvent(proxy); + if (!dummy_data_event_optional.has_value()) + { + std::cerr << "Could not get dummy_data proxy event" << std::endl; + return; + } + impl::ProxyEvent& dummy_data_event = dummy_data_event_optional.value().get(); + + dummy_data_event.Subscribe(1); + init_multi_sync_point.arrive_and_wait(); + benchmark_multi_start_point.arrive_and_wait(); + for (std::size_t cycle = 0U; cycle < kIterations; cycle++) + { + while (!dummy_data_event.GetNewSamples(( + [](SamplePtr sample) noexcept { + std::ignore = sample; + }), + 1).has_value()) {}; + + } + benchmark_multi_finish_point.arrive_and_wait(); + dummy_data_event.Unsubscribe(); + deinit_multi_sync_point.arrive_and_wait(); +} + +int main() +{ + int cpu = 0; + + if (!instance_specifier_skeleton_a_optional.has_value() || !instance_specifier_skeleton_b_optional.has_value()) + { + std::cerr << "Invalid instance specifier, terminating." << std::endl; + return EXIT_FAILURE; + } + const auto& instance_specifier_skeleton_a = instance_specifier_skeleton_a_optional.value(); + const auto& instance_specifier_skeleton_b = instance_specifier_skeleton_b_optional.value(); + + std::cout << "Starting benchmark" << std::endl; + + std::thread transmitterA(Transmitter, cpu++, true, std::ref(instance_specifier_skeleton_a), std::ref(instance_specifier_skeleton_b)); + std::thread transmitterB(Transmitter, cpu++, false, std::ref(instance_specifier_skeleton_b), std::ref(instance_specifier_skeleton_a)); +#if kSubscribers > 0 + std::thread subscribers[kSubscribers]; + if (kSubscribers > 0) + { + subscribers[i] = std::thread(Subscriber, cpu++, std::ref(instance_specifier_skeleton_a)); + subscribers[i] = std::thread(Subscriber, cpu++, std::ref(instance_specifier_skeleton_b)); + } +#endif + init_ab_sync_point.arrive_and_wait(); + const auto benchmark_ab_start_time = std::chrono::steady_clock::now(); + benchmark_ab_start_point.arrive_and_wait(); + benchmark_ab_finish_point.arrive_and_wait(); + const auto benchmark_ab_stop_time = std::chrono::steady_clock::now(); + const auto benchmark_ab_time = benchmark_ab_stop_time - benchmark_ab_start_time; + + transmitterA.join(); + transmitterB.join(); +#if kSubscribers > 0 + for (std::size_t i = 0; i < kSubscribers; i++) + { + subscribers[i].join(); + } +#endif + std::cout << "Results:" << "\t" << + "Iterations: " << kIterations << ", " << "\t" << + "Time: " << duration(benchmark_ab_time).count() << "s, " << "\t" << + "Latency: " << duration_cast(benchmark_ab_time).count() / (kIterations * 2) << "ns, " << "\t" << + "Sample Size: " << kSampleSize << + "Additional subscribers: " << kSubscribers << std::endl; +} diff --git a/score/mw/com/benchmark/benchmark.h b/score/mw/com/benchmark/benchmark.h new file mode 100644 index 00000000..98be467d --- /dev/null +++ b/score/mw/com/benchmark/benchmark.h @@ -0,0 +1,56 @@ +/******************************************************************************** + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#ifndef SCORE_IPC_BRIDGE_BENCHMARK_H +#define SCORE_IPC_BRIDGE_BENCHMARK_H + +#include "score/mw/com/types.h" + +namespace score::mw::com +{ + +constexpr std::size_t kSampleSize = 8192; +constexpr std::uint32_t kIterations = 1000000; +constexpr std::size_t kSubscribers = 2; +constexpr std::size_t kThreadsMultiTotal = kSubscribers + 2; + +struct DummyBenchmarkData +{ + DummyBenchmarkData() = default; + + DummyBenchmarkData(DummyBenchmarkData&&) = default; + + DummyBenchmarkData(const DummyBenchmarkData&) = default; + + DummyBenchmarkData& operator=(DummyBenchmarkData&&) = default; + + DummyBenchmarkData& operator=(const DummyBenchmarkData&) = default; + + std::array dummy_data; + +}; + +template +class IpcBridgeInterface : public Trait::Base +{ + public: + using Trait::Base::Base; + + typename Trait::template Event dummy_benchmark_data_{*this, "dummy_data_arrived"}; +}; + +using BenchmarkProxy = AsProxy; +using BenchmarkSkeleton = AsSkeleton; + +} // namespace score::mw::com + +#endif // SCORE_IPC_BRIDGE_BENCHMARK_H diff --git a/score/mw/com/benchmark/etc/logging.json b/score/mw/com/benchmark/etc/logging.json new file mode 100644 index 00000000..751801fd --- /dev/null +++ b/score/mw/com/benchmark/etc/logging.json @@ -0,0 +1,8 @@ +{ + "appId": "IPBR", + "appDesc": "ipc_bridge", + "logLevel": "kOff", + "logLevelThresholdConsole": "kOff", + "logMode": "kConsole", + "dynamicDatarouterIdentifiers" : true +} diff --git a/score/mw/com/benchmark/etc/mw_com_config.json b/score/mw/com/benchmark/etc/mw_com_config.json new file mode 100644 index 00000000..a3fa02e3 --- /dev/null +++ b/score/mw/com/benchmark/etc/mw_com_config.json @@ -0,0 +1,75 @@ +{ + "serviceTypes": [ + { + "serviceTypeName": "/lola/benchmark", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 1234, + "events": [ + { + "eventName": "dummy_data_arrived", + "eventId": 1 + } + ] + } + ] + } + ], + "serviceInstances": [ + { + "instanceSpecifier": "benchmark/SkeletonA", + "serviceTypeName": "/lola/benchmark", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 1, + "allowedConsumer": {}, + "allowedProvider": {}, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "dummy_data_arrived", + "numberOfSampleSlots": 100, + "maxSubscribers": 3 + } + ], + "permission-checks": "file-permissions-on-empty" + } + ] + }, + { + "instanceSpecifier": "benchmark/SkeletonB", + "serviceTypeName": "/lola/benchmark", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 2, + "allowedConsumer": {}, + "allowedProvider": {}, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "dummy_data_arrived", + "numberOfSampleSlots": 100, + "maxSubscribers": 3 + } + ], + "permission-checks": "file-permissions-on-empty" + } + ] + } + ] +} From fdef7b0601595eb0cec795c4dafe517994ee536c Mon Sep 17 00:00:00 2001 From: Piotr Chodorowski Date: Thu, 11 Sep 2025 12:27:10 +0200 Subject: [PATCH 2/2] Review fix --- score/mw/com/benchmark/benchmark.cpp | 87 +++++++++---------- score/mw/com/benchmark/etc/mw_com_config.json | 8 +- 2 files changed, 45 insertions(+), 50 deletions(-) diff --git a/score/mw/com/benchmark/benchmark.cpp b/score/mw/com/benchmark/benchmark.cpp index bdccc6de..71aea682 100644 --- a/score/mw/com/benchmark/benchmark.cpp +++ b/score/mw/com/benchmark/benchmark.cpp @@ -27,17 +27,7 @@ using namespace std::chrono_literals; using namespace score::mw::com; using namespace std::chrono; -std::mutex cout_mutex{}; score::cpp::latch benchmark_ab_start_point{3}, benchmark_ab_finish_point{3}, init_ab_sync_point{3}, deinit_ab_sync_point{2}; -score::cpp::latch benchmark_multi_start_point{1 + kThreadsMultiTotal}, benchmark_multi_finish_point{1 + kThreadsMultiTotal}, init_multi_sync_point{kThreadsMultiTotal}, deinit_multi_sync_point{kThreadsMultiTotal}; -const auto instance_specifier_skeleton_a_optional = InstanceSpecifier::Create("benchmark/SkeletonA"); -const auto instance_specifier_skeleton_b_optional = InstanceSpecifier::Create("benchmark/SkeletonB"); - -score::cpp::optional>> GetBenchmarkDataProxyEvent( - BenchmarkProxy& proxy) -{ - return proxy.dummy_benchmark_data_; -} void SetupThread(int cpu) { @@ -64,7 +54,7 @@ void SetupThread(int cpu) } } -void Transmitter(int cpu, bool starter, impl::InstanceSpecifier skeleton_instance_specifier, impl::InstanceSpecifier proxy_instance_specifier) +void Transceiver(int cpu, bool starter, impl::InstanceSpecifier skeleton_instance_specifier, impl::InstanceSpecifier proxy_instance_specifier) { SetupThread(cpu); @@ -106,13 +96,7 @@ void Transmitter(int cpu, bool starter, impl::InstanceSpecifier skeleton_instanc } auto& proxy = proxy_result.value(); - auto dummy_data_event_optional = GetBenchmarkDataProxyEvent(proxy); - if (!dummy_data_event_optional.has_value()) - { - std::cerr << "Could not get dummy_data proxy event" << std::endl; - return; - } - impl::ProxyEvent& dummy_data_event = dummy_data_event_optional.value().get(); + impl::ProxyEvent& dummy_data_event = proxy.dummy_benchmark_data_; score::Result> sample_result; dummy_data_event.Subscribe(1); @@ -128,11 +112,21 @@ void Transmitter(int cpu, bool starter, impl::InstanceSpecifier skeleton_instanc } for (std::size_t cycle = 0U; cycle < kIterations; cycle++) { - while (!dummy_data_event.GetNewSamples(( + while (true) { + auto result = dummy_data_event.GetNewSamples(( [](SamplePtr sample) noexcept { std::ignore = sample; - }), - 1).has_value()) {}; + }),1); + if (result.has_value()) + { + if (result.value() == 0) + { + continue; + } else { + break; + } + } + }; do { sample_result = skeleton.dummy_benchmark_data_.Allocate(); } while (!sample_result.has_value()); @@ -173,64 +167,65 @@ void Subscriber(int cpu, impl::InstanceSpecifier proxy_instance_specifier) } auto& proxy = proxy_result.value(); - auto dummy_data_event_optional = GetBenchmarkDataProxyEvent(proxy); - if (!dummy_data_event_optional.has_value()) - { - std::cerr << "Could not get dummy_data proxy event" << std::endl; - return; - } - impl::ProxyEvent& dummy_data_event = dummy_data_event_optional.value().get(); + impl::ProxyEvent& dummy_data_event = proxy.dummy_benchmark_data_; dummy_data_event.Subscribe(1); - init_multi_sync_point.arrive_and_wait(); - benchmark_multi_start_point.arrive_and_wait(); for (std::size_t cycle = 0U; cycle < kIterations; cycle++) { - while (!dummy_data_event.GetNewSamples(( + while (true) { + auto result = dummy_data_event.GetNewSamples(( [](SamplePtr sample) noexcept { std::ignore = sample; - }), - 1).has_value()) {}; - + }),1); + if (result.has_value()) + { + if (result.value() == 0) + { + continue; + } else { + break; + } + } + }; } - benchmark_multi_finish_point.arrive_and_wait(); dummy_data_event.Unsubscribe(); - deinit_multi_sync_point.arrive_and_wait(); } int main() { int cpu = 0; + const auto instance_specifier_instance_a_result = InstanceSpecifier::Create("benchmark/InstanceA"); + const auto instance_specifier_instance_b_result = InstanceSpecifier::Create("benchmark/InstanceB"); - if (!instance_specifier_skeleton_a_optional.has_value() || !instance_specifier_skeleton_b_optional.has_value()) + if (!instance_specifier_instance_a_result.has_value() || !instance_specifier_instance_b_result.has_value()) { std::cerr << "Invalid instance specifier, terminating." << std::endl; return EXIT_FAILURE; } - const auto& instance_specifier_skeleton_a = instance_specifier_skeleton_a_optional.value(); - const auto& instance_specifier_skeleton_b = instance_specifier_skeleton_b_optional.value(); + const auto& instance_specifier_instance_a = instance_specifier_instance_a_result.value(); + const auto& instance_specifier_instance_b = instance_specifier_instance_b_result.value(); std::cout << "Starting benchmark" << std::endl; - std::thread transmitterA(Transmitter, cpu++, true, std::ref(instance_specifier_skeleton_a), std::ref(instance_specifier_skeleton_b)); - std::thread transmitterB(Transmitter, cpu++, false, std::ref(instance_specifier_skeleton_b), std::ref(instance_specifier_skeleton_a)); + std::thread transceiverA(Transceiver, cpu++, true, std::ref(instance_specifier_instance_a), std::ref(instance_specifier_instance_b)); + std::thread transceiverB(Transceiver, cpu++, false, std::ref(instance_specifier_instance_b), std::ref(instance_specifier_instance_a)); #if kSubscribers > 0 std::thread subscribers[kSubscribers]; if (kSubscribers > 0) { - subscribers[i] = std::thread(Subscriber, cpu++, std::ref(instance_specifier_skeleton_a)); - subscribers[i] = std::thread(Subscriber, cpu++, std::ref(instance_specifier_skeleton_b)); + subscribers[i] = std::thread(Subscriber, cpu++, std::ref(instance_specifier_instance_a)); + subscribers[i] = std::thread(Subscriber, cpu++, std::ref(instance_specifier_instance_b)); } #endif init_ab_sync_point.arrive_and_wait(); - const auto benchmark_ab_start_time = std::chrono::steady_clock::now(); benchmark_ab_start_point.arrive_and_wait(); + const auto benchmark_ab_start_time = std::chrono::steady_clock::now(); benchmark_ab_finish_point.arrive_and_wait(); const auto benchmark_ab_stop_time = std::chrono::steady_clock::now(); const auto benchmark_ab_time = benchmark_ab_stop_time - benchmark_ab_start_time; - transmitterA.join(); - transmitterB.join(); + transceiverA.join(); + transceiverB.join(); #if kSubscribers > 0 for (std::size_t i = 0; i < kSubscribers; i++) { diff --git a/score/mw/com/benchmark/etc/mw_com_config.json b/score/mw/com/benchmark/etc/mw_com_config.json index a3fa02e3..43228757 100644 --- a/score/mw/com/benchmark/etc/mw_com_config.json +++ b/score/mw/com/benchmark/etc/mw_com_config.json @@ -22,7 +22,7 @@ ], "serviceInstances": [ { - "instanceSpecifier": "benchmark/SkeletonA", + "instanceSpecifier": "benchmark/InstanceA", "serviceTypeName": "/lola/benchmark", "version": { "major": 1, @@ -38,7 +38,7 @@ "events": [ { "eventName": "dummy_data_arrived", - "numberOfSampleSlots": 100, + "numberOfSampleSlots": 1, "maxSubscribers": 3 } ], @@ -47,7 +47,7 @@ ] }, { - "instanceSpecifier": "benchmark/SkeletonB", + "instanceSpecifier": "benchmark/InstanceB", "serviceTypeName": "/lola/benchmark", "version": { "major": 1, @@ -63,7 +63,7 @@ "events": [ { "eventName": "dummy_data_arrived", - "numberOfSampleSlots": 100, + "numberOfSampleSlots": 1, "maxSubscribers": 3 } ],