Skip to content
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

sys/busy_wait: add busy wait helper #20241

Merged
merged 6 commits into from Jan 11, 2024
Merged

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented Jan 9, 2024

Contribution description

We often need to wait for a short period of time before timers are initialized, e.g. in board_init().

Instead of ad-hoc busy wait implementations, provide a common busy_wait() helper function (taken from msp430) and add a busy_wait_us() for a rough time approximation based on the CPU frequency.

Testing procedure

A new test application is provided in tests/sys/busy_wait that will measure the diversion from the usec timer:

samd20-xpro (Cortex M0+)

2024-01-09 18:34:38,799 # waiting for 10 µs…
2024-01-09 18:34:38,801 # took 29 µs (diff: 19 µs)
2024-01-09 18:34:38,803 # waiting for 100 µs…
2024-01-09 18:34:38,806 # took 119 µs (diff: 19 µs)
2024-01-09 18:34:38,808 # waiting for 1000 µs…
2024-01-09 18:34:38,812 # took 1012 µs (diff: 12 µs)
2024-01-09 18:34:38,814 # waiting for 10000 µs…
2024-01-09 18:34:38,827 # took 9942 µs (diff: -58 µs)

saml10-xpro (Cortex M23)

2024-01-09 19:06:53,208 # waiting for 10 µs…
2024-01-09 19:06:53,211 # took 38 µs (diff: 28 µs)
2024-01-09 19:06:53,213 # waiting for 100 µs…
2024-01-09 19:06:53,216 # took 128 µs (diff: 28 µs)
2024-01-09 19:06:53,218 # waiting for 1000 µs…
2024-01-09 19:06:53,222 # took 1029 µs (diff: 29 µs)
2024-01-09 19:06:53,224 # waiting for 10000 µs…
2024-01-09 19:06:53,237 # took 10028 µs (diff: 28 µs)

same54-xpro (Cortex M4F)

2024-01-09 19:07:30,669 # waiting for 10 µs…
2024-01-09 19:07:30,671 # took 14 µs (diff: 4 µs)
2024-01-09 19:07:30,673 # waiting for 100 µs…
2024-01-09 19:07:30,676 # took 103 µs (diff: 3 µs)
2024-01-09 19:07:30,678 # waiting for 1000 µs…
2024-01-09 19:07:30,681 # took 1003 µs (diff: 3 µs)
2024-01-09 19:07:30,683 # waiting for 10000 µs…
2024-01-09 19:07:30,696 # took 10003 µs (diff: 3 µs)

avr-rss2 (AVR8)

2024-01-09 23:07:08,152 # waiting for 10 µs…
2024-01-09 23:07:08,153 # took 96 µs (diff: 86 µs)
2024-01-09 23:07:08,153 # waiting for 100 µs…
2024-01-09 23:07:08,153 # took 208 µs (diff: 108 µs)
2024-01-09 23:07:08,154 # waiting for 1000 µs…
2024-01-09 23:07:08,154 # took 1104 µs (diff: 104 µs)
2024-01-09 23:07:08,155 # waiting for 10000 µs…
2024-01-09 23:07:08,155 # took 10112 µs (diff: 112 µs)

esp8266-esp-12x (ESP8266)

2024-01-09 23:19:50,829 # waiting for 10 µs…
2024-01-09 23:19:50,829 # took 20 µs (diff: 10 µs)
2024-01-09 23:19:50,830 # waiting for 100 µs…
2024-01-09 23:19:50,830 # took 106 µs (diff: 6 µs)
2024-01-09 23:19:50,830 # waiting for 1000 µs…
2024-01-09 23:19:50,831 # took 1007 µs (diff: 7 µs)
2024-01-09 23:19:50,831 # waiting for 10000 µs…
2024-01-09 23:19:50,832 # took 10007 µs (diff: 7 µs)

esp32-wroom-32 (ESP32)

2024-01-09 23:11:12,958 # waiting for 10 µs…
2024-01-09 23:11:12,959 # took 12 µs (diff: 2 µs)
2024-01-09 23:11:12,959 # waiting for 100 µs…
2024-01-09 23:11:12,960 # took 102 µs (diff: 2 µs)
2024-01-09 23:11:12,960 # waiting for 1000 µs…
2024-01-09 23:11:12,960 # took 1002 µs (diff: 2 µs)
2024-01-09 23:11:12,961 # waiting for 10000 µs…
2024-01-09 23:11:12,961 # took 10002 µs (diff: 2 µs)

esp32s2-wemos-mini (ESP32S2)

2024-01-09 23:30:08,115 # waiting for 10 µs…
2024-01-09 23:30:08,117 # took 20 µs (diff: 10 µs)
2024-01-09 23:30:08,119 # waiting for 100 µs…
2024-01-09 23:30:08,121 # took 151 µs (diff: 51 µs)
2024-01-09 23:30:08,123 # waiting for 1000 µs…
2024-01-09 23:30:08,127 # took 1010 µs (diff: 10 µs)
2024-01-09 23:30:08,129 # waiting for 10000 µs…
2024-01-09 23:30:08,142 # took 10010 µs (diff: 10 µs)

esp32s3-devkit (ESP32S3)

2024-01-09 23:23:44,314 # waiting for 10 µs…
2024-01-09 23:23:44,314 # took 13 µs (diff: 3 µs)
2024-01-09 23:23:44,315 # waiting for 100 µs…
2024-01-09 23:23:44,315 # took 103 µs (diff: 3 µs)
2024-01-09 23:23:44,315 # waiting for 1000 µs…
2024-01-09 23:23:44,316 # took 1002 µs (diff: 2 µs)
2024-01-09 23:23:44,316 # waiting for 10000 µs…
2024-01-09 23:23:44,317 # took 10003 µs (diff: 3 µs)

esp32c3-devkit (RISC-V)

2024-01-09 23:33:23,096 # waiting for 10 µs…
2024-01-09 23:33:23,097 # took 14 µs (diff: 4 µs)
2024-01-09 23:33:23,100 # waiting for 100 µs…
2024-01-09 23:33:23,102 # took 103 µs (diff: 3 µs)
2024-01-09 23:33:23,105 # waiting for 1000 µs…
2024-01-09 23:33:23,107 # took 1002 µs (diff: 2 µs)
2024-01-09 23:33:23,108 # waiting for 10000 µs…
2024-01-09 23:33:23,112 # took 10003 µs (diff: 3 µs)

sipeed-longan-nano (RISC-V)

2024-01-09 23:37:05,709 # waiting for 10 µs…
2024-01-09 23:37:05,709 # took 13 µs (diff: 3 µs)
2024-01-09 23:37:05,709 # waiting for 100 µs…
2024-01-09 23:37:05,710 # took 113 µs (diff: 13 µs)
2024-01-09 23:37:05,711 # waiting for 1000 µs…
2024-01-09 23:37:05,711 # took 1013 µs (diff: 13 µs)
2024-01-09 23:37:05,712 # waiting for 10000 µs…
2024-01-09 23:37:05,718 # took 10014 µs (diff: 14 µs)

Issues/PRs references

@github-actions github-actions bot added Platform: MSP Platform: This PR/issue effects MSP-based platforms Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: tests Area: tests and testing framework Area: cpu Area: CPU/MCU ports Area: sys Area: System labels Jan 9, 2024
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 9, 2024
@riot-ci
Copy link

riot-ci commented Jan 9, 2024

Murdock results

✔️ PASSED

9cf1c47 tests/sys/busy_wait: add test for busy wait

Success Failures Total Runtime
8101 0 8101 11m:37s

Artifacts

Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

Nice one. The blinky example could also make use of this :-)

@github-actions github-actions bot added Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Jan 9, 2024
sys/include/busy_wait.h Show resolved Hide resolved
cpu/avr8_common/include/cpu.h Show resolved Hide resolved
tests/sys/busy_wait/main.c Show resolved Hide resolved
@benpicco benpicco added the CI: no fast fail don't abort PR build after first error label Jan 11, 2024
@benpicco benpicco added this pull request to the merge queue Jan 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 11, 2024
@benpicco
Copy link
Contributor Author

@maribu if you run the test on MSP430 you can also provide CPU_CYCLES_PER_LOOP for it.

Merged via the queue into RIOT-OS:master with commit 714958a Jan 11, 2024
25 checks passed
@benpicco benpicco deleted the busy_wait branch January 11, 2024 15:26
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.01 milestone Feb 7, 2024
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 Area: sys Area: System Area: tests Area: tests and testing framework CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms Platform: MSP Platform: This PR/issue effects MSP-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants