cpu/esp32/gpio_ll: fix & cleanup#20635
Merged
maribu merged 1 commit intoRIOT-OS:masterfrom Apr 30, 2024
Merged
Conversation
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
Member
Author
|
OK, it compiles now for both ESP32 with one and two GPIO ports. Tests are still passing: The benchmark for |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 return0even ifportis 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) withmasterConclusion
.text, -64 B.data, +/-0 B.bssintests/benchmark/gpio_llgpio_ll_toggle()got a lot more expensive (but now lives out to the thread-safety guarantees of the API)Issues/PRs references
None