Power airtime monotonic windows due to light sleep. #10582
Open
h3lix1 wants to merge 2 commits into
Open
Conversation
8 tasks
Contributor
|
need to review your code more carefully, but isn't that duplicate of 9778, which looks like has been closed as I didn't receive feedback / review from maintainers? |
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.
Power Airtime Monotonic Windows
Summary
This change updates airtime accounting to advance from monotonic uptime instead of the
AirTimethread's once-per-second scheduler tick.Before this change,
AirTime::runOnce()incremented an internalsecSinceBootcounter by one each time the thread ran. On devices using light sleep, the scheduler can be paused while real time continues. That means the channel-utilization and TX-utilization windows could decay according to awake scheduler time, not elapsed wall time.After this change, airtime windows are synchronized from
millis()before airtime is logged or read. Packets observed after wake are counted in the current elapsed-time bucket, and buckets crossed during sleep are cleared or rotated immediately.Motivation
The power-saving work makes ESP32 nodes enter light sleep quickly after packet processing. That exposed a mismatch in airtime accounting:
AirTimethread ran.When a node slept frequently, old airtime could remain in the active channel-utilization window for longer than 60 real seconds. This could make the channel appear busy after the channel had actually been quiet from the node's point of view.
Code Changes
The change is isolated to:
src/airtime.cppsrc/airtime.hThe new private helper is:
syncNow()usesmillis()as the time source. It intentionally does not use RTC, GPS, NTP, or mesh time, because wall-clock time can move backward or forward. Airtime windows should be based on monotonic uptime.The helper is called from:
logAirtime()airtimeReport()getSecondsSinceBoot()channelUtilizationPercent()utilizationTXPercent()runOnce()airtimeRotatePeriod()Calling it from both readers and writers matters because a node may wake, receive a packet, or make a send-gating decision before the periodic
AirTimethread runs again.Window Behavior
Channel utilization keeps the existing six 10-second buckets:
If one or more 10-second boundaries were crossed while the scheduler was paused,
syncNow()clears each crossed bucket. If the elapsed time is large enough to cover the full 60-second window, it clears the whole channel-utilization window.TX utilization keeps the existing 60 one-minute buckets:
If one or more minute boundaries were crossed,
syncNow()clears those buckets. If the elapsed time covers the full hour, it clears the full TX-utilization window.Historical airtime reports keep the existing hour-sized periods:
If one or more hour boundaries were crossed,
syncNow()rotates the report periods. If the elapsed time covers all retained periods, it clears the full report window.Expected Runtime Impact
The main behavioral change is that channel utilization and TX utilization decay according to elapsed monotonic uptime, including time spent in light sleep.
This can affect send-gating decisions that use:
airTime->isTxAllowedChannelUtil(...) airTime->isTxAllowedAirUtil()🤝 Attestations
Heltec v4.3