-
Notifications
You must be signed in to change notification settings - Fork 55
Add BenchmarkSystem that implements benchmarking #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
marcmo
wants to merge
1
commit into
eclipse-openbsw:main
Choose a base branch
from
esrlabs:cr-124398
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| .. _learning_benchmark: | ||
|
|
||
| Benchmark mode | ||
| ============== | ||
|
|
||
| Previous: :ref:`learning_tracing` | ||
|
|
||
| The reference app can be built to run benchmark tests. There is a BenchmarkSystem class that | ||
| implements the following tests: | ||
|
|
||
| * interrupt latency test - to measure the time between raising the interrupt line and entering the ISR | ||
| * task switch latency test - to measure the time between an async runnable setting an event | ||
| and another (woken up) runnable starting execution | ||
| * task switch after timeout latency test - to measure the time between scheduling an async runnable | ||
| and its start of execution (woken up by a timer) | ||
| * load test - record CPU idle time during cyclic artificial load across various tasks | ||
|
|
||
| Use the following command to build the reference app in benchmark mode for the S32K148EVB: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| cmake -B cmake-build-s32k148-benchmark -S executables/referenceApp -DBUILD_TARGET_PLATFORM="S32K148EVB" \ | ||
| -DBUILD_BENCHMARK=ON --toolchain ../../admin/cmake/ArmNoneEabi-gcc.cmake | ||
| cmake --build cmake-build-s32k148-benchmark --target app.referenceApp -j | ||
|
|
||
| When started, the application runs benchmark tests and prints out measurement results on the console. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,4 @@ Some simple lessons to get new users up and running. | |
| uds/index | ||
| hwio/index | ||
| tracing/index | ||
| benchmark/index | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
executables/referenceApp/application/include/app/BenchmarkLogger.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright 2024 Accenture. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "util/logger/Logger.h" | ||
|
|
||
| DECLARE_LOGGER_COMPONENT(BENCH) |
149 changes: 149 additions & 0 deletions
149
executables/referenceApp/application/include/systems/BenchmarkSystem.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright 2024 Accenture. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "app/BenchmarkLogger.h" | ||
|
|
||
| #include <async/AsyncBinding.h> | ||
| #include <async/FutureSupport.h> | ||
| #include <console/AsyncCommandWrapper.h> | ||
| #include <lifecycle/AsyncLifecycleComponent.h> | ||
| #include <lifecycle/console/LifecycleControlCommand.h> | ||
| #include <mcu/mcu.h> | ||
| #include <runtime/StatisticsContainer.h> | ||
|
|
||
| using ::util::logger::BENCH; | ||
| using ::util::logger::Logger; | ||
|
|
||
| namespace systems | ||
| { | ||
| class BenchmarkSystem | ||
| : public ::lifecycle::AsyncLifecycleComponent | ||
| , private ::async::IRunnable | ||
| { | ||
| public: | ||
| explicit BenchmarkSystem( | ||
| ::async::ContextType context, ::async::AsyncBinding::RuntimeMonitorType& runtimeMonitor); | ||
|
|
||
| BenchmarkSystem(BenchmarkSystem const&) = delete; | ||
| BenchmarkSystem& operator=(BenchmarkSystem const&) = delete; | ||
|
|
||
| void init() override; | ||
| void run() override; | ||
| void shutdown() override; | ||
|
|
||
| void cyclic(); | ||
|
|
||
| private: | ||
| void execute() override; | ||
|
|
||
| uint32_t getPercentage(uint64_t value, uint64_t total); | ||
| void startTaskSwitchLatencyTest(); | ||
| void handleTaskSwitchLatencyTest(); | ||
| void startTaskSwitchAfterTimeoutLatencyTest(); | ||
| void handleTaskSwitchAfterTimeoutLatencyTest(); | ||
| void startInterruptLatencyTest(); | ||
| void handleInterruptLatencyTest(); | ||
| void startLoadTest(); | ||
| void handleLoadTest(); | ||
| uint32_t calculateTimeDifference(uint32_t start, uint32_t end); | ||
|
|
||
| private: | ||
| using TaskStatistics = ::runtime::declare::StatisticsContainer< | ||
| ::runtime::RuntimeStatistics, | ||
| ::async::AsyncBindingType::AdapterType::FREERTOS_TASK_COUNT>; | ||
|
|
||
| class EventWaiterRunnable : public ::async::IRunnable | ||
| { | ||
| public: | ||
| explicit EventWaiterRunnable(::async::FutureSupport& future, uint32_t& latencyEnd) | ||
| : _future(future), _timestamp(latencyEnd) | ||
| {} | ||
|
|
||
| void execute() override | ||
| { | ||
| _future.wait(); | ||
| _timestamp = DWT->CYCCNT; /* HW cycle counter */ | ||
| } | ||
|
|
||
| private: | ||
| ::async::FutureSupport& _future; | ||
| uint32_t& _timestamp; | ||
| }; | ||
|
|
||
| class EventSetterRunnable : public ::async::IRunnable | ||
| { | ||
| public: | ||
| explicit EventSetterRunnable(::async::FutureSupport& future, uint32_t& latencyStart) | ||
| : _future(future), _timestamp(latencyStart) | ||
| {} | ||
|
|
||
| void execute() override | ||
| { | ||
| _timestamp = DWT->CYCCNT; | ||
| _future.notify(); | ||
| } | ||
|
|
||
| private: | ||
| ::async::FutureSupport& _future; | ||
| uint32_t& _timestamp; | ||
| }; | ||
|
|
||
| class TimoutWaiterRunnable : public ::async::IRunnable | ||
| { | ||
| public: | ||
| explicit TimoutWaiterRunnable(uint32_t& latencyEnd) : _timestamp(latencyEnd) {} | ||
|
|
||
| void execute() override { _timestamp = DWT->CYCCNT; } | ||
|
|
||
| private: | ||
| uint32_t& _timestamp; | ||
| }; | ||
|
|
||
| class LoadRunnable : public ::async::IRunnable | ||
| { | ||
| public: | ||
| explicit LoadRunnable(uint32_t limit) : _limit(limit) {} | ||
|
|
||
| void execute() override | ||
| { | ||
| uint32_t volatile counter = 0; | ||
| while (counter++ < _limit) {} | ||
| } | ||
|
|
||
| private: | ||
| uint32_t _limit; | ||
| }; | ||
| friend class EventWaiterRunnable; | ||
| friend class EventSetterRunnable; | ||
| friend class TimoutWaiterRunnable; | ||
| ::async::ContextType const _context; | ||
| uint32_t _taskSwitchLatencyStart; | ||
| uint32_t _taskSwitchLatencyEnd; | ||
| uint32_t _taskSwitchAfterTimeoutLatencyStart; | ||
| uint32_t _taskSwitchAfterTimeoutLatencyEnd; | ||
| ::async::TimeoutType _timeout; | ||
| ::async::TimeoutType _taskSwitchTimeout; | ||
| ::async::TimeoutType _sysadminTimeout; | ||
| ::async::TimeoutType _canTimeout; | ||
| ::async::TimeoutType _demoTimeout; | ||
| ::async::TimeoutType _udsTimeout; | ||
| ::async::TimeoutType _bgTimeout; | ||
| ::async::FutureSupport _future; | ||
| EventWaiterRunnable _eventWaiterRunnable; | ||
| EventSetterRunnable _eventSetterRunnable; | ||
| TimoutWaiterRunnable _timeoutWaiterRunnable; | ||
| LoadRunnable _sysadminLoadRunnable; | ||
| LoadRunnable _canLoadRunnable; | ||
| LoadRunnable _demoLoadRunnable; | ||
| LoadRunnable _udsLoadRunnable; | ||
| LoadRunnable _bgLoadRunnable; | ||
| bool _taskSwitchLatencyTestRunning; | ||
| bool _taskSwitchAfterTimeoutLatencyTestRunning; | ||
| bool _interruptLatencyTestRunning; | ||
| bool _loadTestRunning; | ||
| bool _runtimeMonitorRunning; | ||
| ::async::AsyncBinding::RuntimeMonitorType& _runtimeMonitor; | ||
| }; | ||
|
|
||
| } // namespace systems |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe add a check here that prevents the benchmarking build on Posix? This might be slightly out of place, but currently it will fail due to a compiler error which is also not good. So you could just add:
if (BUILD_TARGET_PLATFORM STREQUAL "POSIX") message(FATAL_ERROR "Benchmarking not supported on POSIX") endif ()