-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/esp32/gpio_ll: fix & cleanup #20635
Merged
Merged
+78
−75
Conversation
This file contains 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
1 task
benpicco
reviewed
Apr 30, 2024
06edfa8
to
ae1deb2
Compare
benpicco
approved these changes
Apr 30, 2024
ae1deb2
to
f36695e
Compare
- `gpio_ll_toggle()` now is race-free - avoid using a look up table but branch to the two different registers in the `gpio_ll*()` functions - in most cases the GPIO port is a compile time constant and the dead branch is eliminated by the optimizer, making this vastly more efficient - some MCUs do only have a single port, in which case `GPIO_PORT_NUM(port)` is known to return `0` even if `port` is not known, resulting in one of the branch being eliminated as dead branch no matter what - in case it really is unknown at compile time which port to work on, the branch can still be implemented efficiently by the compiler e.g. using a conditional move; likely more efficient than fetching a value from the look up table.
f36695e
to
dd585f9
Compare
OK, it compiles now for both ESP32 with one and two GPIO ports. Tests are still passing:
The benchmark for
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area: cpu
Area: CPU/MCU ports
CI: ready for build
If set, CI server will compile all applications for all available boards for the labeled PR
Platform: ESP
Platform: This PR/issue effects ESP-based platforms
Type: bug
The issue reports a bug / The PR fixes a bug (including spelling errors)
Type: cleanup
The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
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.
Contribution description
gpio_ll_toggle()
now is race-freein the
gpio_ll*()
functionsGPIO_PORT_NUM(port)
is known to return0
even ifport
is not known, resulting in one of the branch being eliminated as dead branch no matter whatTesting procedure
Selftest with the PR
Benchmark (
tests/bench/gpio_ll
) with PRBenchmark (
tests/bench/gpio_ll
) withmaster
Conclusion
.text
, -64 B.data
, +/-0 B.bss
intests/benchmark/gpio_ll
gpio_ll_toggle()
got a lot more expensive (but now lives out to the thread-safety guarantees of the API)Issues/PRs references
None