Run "accounting_run_housekeeping" with a periodic event.
Here's an implementation sketch:
- Make accounting_add_bytes() check whether limits are exceeded. Refactor the code as needed to make this check fast.
- If a limit is exceeded, schedule consider_hibernation().
- Also schedule consider_hibernation() again based on "shutdown_time", "hibernate_end_time", and "interval_wakeup_time".
- Pull "accounting_run_housekeeping" apart:
- Other logic to set interval_end_time if it isn't set but accounting is enabled.
- A periodic event, only scheduled when network is on and accounting is enabled, to record bandwidth usage. Tie this into the or_state_save event.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information