benchmarks: add a hardware abstraction layer#239
Conversation
There was a problem hiding this comment.
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, andbench_plat_triggerIRQare now defined in a newbench_plat.hheader 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 therhealstonesuite) 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_latencybenchmark. - Build System Updates: The
Makefilehas been updated to conditionally include platform-specific HAL implementations, ensuring proper compilation for different targets based on theTARGET_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
-
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. ↩
There was a problem hiding this comment.
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.
| 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); | ||
| } |
There was a problem hiding this comment.
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);.
There was a problem hiding this comment.
Everything gets cleaned up anyway when the program exits, so I don't think it's worth the effort.
|
|
||
| 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++) { |
There was a problem hiding this comment.
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++) {There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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.
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
29f39a2 to
b00b13b
Compare
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
How Has This Been Tested?
Checklist:
Special treatment