Allow to sleep instead of busy waiting when limiting refresh rate #1563
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.
On single core boards, busy waiting renders the system unresponsive. We add the --led-no-busy-waiting flag, to allow the process to sleep instead of busy waiting, thereby freeing up CPU cycles for other processes at the cost of slightly less accurate frame timing.
On a Raspberry Pi 3B on two 32x32 panels, busy waiting keeps a core 98% busy. Sleeping reduces it to 14%.
On a Raspberry Zero on two 32x32 panels, busy waiting keeps the single core 95% busy and gives an unresponsive system. Sleeping reduces it to 32% and keeps the system responsive.
Sleeping degrades the timing accuracy a bit, but is still good enough by a far margin for many uses. The following numbers are for driving two 32x32 panels and averaging the refresh rate across a minute (the 1kHz refresh rate limit is of course not reached, and is only there to make sure that the relevant code path is taken):
+--------------------------------------------------+--------------+-----------+
| Raspberry Pi 3B, limit 70Hz, hardw. pulsing | 70.000Hz | 69.977Hz |
| Raspberry Pi 3B, limit 70Hz, no hardw. pulsing | 70.000Hz | 69.977Hz |
| Raspberry Pi 3B, limit 1kHz, hardw. pulsing | 430.824Hz | 430.855Hz |
| Raspberry Pi 3B, limit 1kHz, no hardw. pulsing | 365.498Hz | 365.456Hz |
| Raspberry Pi Zero, limit 70Hz, hardw. pulsing | 69.986Hz | 69.643Hz |
| Raspberry Pi Zero, limit 70Hz, no hardw. pulsing | 69.986Hz | 69.638Hz |
| Raspberry Pi Zero, limit 1kHz, hardw. pulsing | 263.877Hz | 264.538Hz |
| Raspberry Pi Zero, limit 1kHz, no hardw. pulsing | 233.166Hz | 231.650Hz |
+--------------------------------------------------+--------------+-----------+