Skip to content

benchmarks: add a hardware abstraction layer#239

Open
jmaksymowicz wants to merge 2 commits into
masterfrom
jmaksymowicz/benchmarks-platform
Open

benchmarks: add a hardware abstraction layer#239
jmaksymowicz wants to merge 2 commits into
masterfrom
jmaksymowicz/benchmarks-platform

Conversation

@jmaksymowicz
Copy link
Copy Markdown
Contributor

Abstract platform-dependent functions, such as timers or interrupt triggering, into separate functions that can be defined per-platform.

Additionally, fix a bug that caused one test to give incorrect results on one of the tested platforms.

Motivation and Context

Now benchmarks can be more easily ported to different hardware platforms.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: armv7r5f-tda4vm-som

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @jmaksymowicz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a hardware abstraction layer (HAL) for benchmark-related platform-dependent functions, such as timers and interrupt triggering. This refactoring significantly improves the portability of benchmarks across different hardware platforms by centralizing and abstracting low-level hardware interactions. Additionally, it includes a bug fix addressing an issue where one of the tests produced incorrect results on a specific platform due to previous platform-specific implementation details.

Highlights

  • Hardware Abstraction Layer (HAL) Introduction: A new HAL is introduced to abstract platform-specific functionalities, making benchmarks more portable. This includes dedicated interfaces for timer access and interrupt management.
  • Centralized Platform-Dependent Functions: Functions like bench_plat_getTime, bench_plat_initIRQ, and bench_plat_triggerIRQ are now defined in a new bench_plat.h header and implemented per-platform (e.g., bench_plat_gr740.c), replacing previous scattered or hardcoded implementations.
  • Enhanced Benchmark Portability: All existing benchmark tests (dup_close, high_load, jitter, and the rhealstone suite) have been updated to utilize the new HAL, replacing direct platform-specific calls with abstracted ones and incorporating necessary timer initialization.
  • Bug Fix for Test Accuracy: A bug causing incorrect results in one of the tests on a specific platform has been resolved by correctly abstracting and centralizing the platform's interrupt handling within the new HAL, specifically impacting the irq_latency benchmark.
  • Build System Updates: The Makefile has been updated to conditionally include platform-specific HAL implementations, ensuring proper compilation for different targets based on the TARGET_SUBFAMILY.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a well-designed hardware abstraction layer (HAL) for platform-dependent functions, significantly improving the portability and maintainability of the benchmarks. The changes are consistently applied across the test suite. I've identified a few areas for improvement, including a potential resource leak and an issue that could affect benchmark accuracy. Addressing these points will further strengthen this already solid contribution.

Comment on lines +52 to +61
int bench_plat_initIRQ(int (*irqHandler)(unsigned int, void *))
{
void *mmapResult = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE | MAP_PHYSMEM | MAP_ANONYMOUS, -1, (uintptr_t)INT_CTRL_BASE);
if (mmapResult == MAP_FAILED) {
return -ENOMEM;
}

irqCtrl = mmapResult;
return interrupt(IRQ_UNUSED, irqHandler, NULL, 0, NULL);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The memory mapped via mmap in bench_plat_initIRQ is never unmapped with munmap. This results in a resource leak. While the OS will likely clean this up when the benchmark program exits, it's good practice to explicitly release resources. Consider adding a bench_plat_deinitIRQ function to the platform abstraction layer to handle this cleanup, which would call munmap(irqCtrl, _PAGE_SIZE);.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything gets cleaned up anyway when the program exits, so I don't think it's worth the effort.

Comment thread benchmarks/rhealstone/preemption.c Outdated

for (volatile int cnt1 = 0; cnt1 < MAX_LOOPS; cnt1++) {
for (volatile int i = 0; i < ONE_TICK_AVG; i++) {
for (atomic_int i = 0; i < ONE_TICK_AVG; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loop counter i is declared as atomic_int. Since i is a local variable and not shared across threads, using atomic_int is unnecessary and may introduce performance overhead, which is undesirable in a benchmark's overhead calculation. volatile int should be sufficient to prevent the compiler from optimizing the loop away, especially with the nop inside.

		for (volatile int i = 0; i < ONE_TICK_AVG; i++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional performance overhead of atomic_int is exactly the reason why this change was made - previously it was not included in the overhead measurement causing incorrect results.


void bench_plat_triggerIRQ(void)
{
*(irqCtrl + 2) = (1 << IRQ_UNUSED);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pointer arithmetic *(irqCtrl + 2) uses a magic number 2 for the register offset. To improve code readability and maintainability, please define this offset as a named constant (e.g., #define IRQ_CTRL_FORCE_REG 2) at the top of the file and use it here.

#define IRQ_CTRL_FORCE_REG 2
*(irqCtrl + IRQ_CTRL_FORCE_REG) = (1 << IRQ_UNUSED);

Copy link
Copy Markdown
Contributor Author

@jmaksymowicz jmaksymowicz Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the registers on that IRQ controller are, I just moved existing code into a new file. Considering it's an AI answer, take that #define name with a grain of salt.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 3, 2025

Unit Test Results

8 039 tests  +9   7 515 ✅ +9   43m 4s ⏱️ + 2m 26s
  479 suites ±0     524 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 29f39a2. ± Comparison against base commit 2df76e2.

Comment thread benchmarks/common/bench_plat.h Outdated
Previously overhead was counted by incrementing a value of type `int`,
while in the task a value of type `atomic_int` was incremented.
Depending on the platform this could result in overhead value being
under-counted and the results would be higher (worse) than expected.

JIRA: RTOS-1045
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/benchmarks-platform branch from 29f39a2 to b00b13b Compare August 12, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants