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

Allow wrapping storage (circular storage) #13

Open
MathiasKoch opened this issue Jun 18, 2021 · 2 comments · May be fixed by #16
Open

Allow wrapping storage (circular storage) #13

MathiasKoch opened this issue Jun 18, 2021 · 2 comments · May be fixed by #16
Labels
enhancement 👍 New feature or request

Comments

@MathiasKoch
Copy link
Member

It would be nice to be able to configure defmt-persist to be either the n first log frames, or the n latest log frames, where n depends on the storage available.

@MathiasKoch MathiasKoch added the enhancement 👍 New feature or request label Jun 18, 2021
@eupn
Copy link
Contributor

eupn commented Jun 18, 2021

We should also take into account that NVRAMs are typically erased on a page basis and that a page is of a huge size relative to the log frames. The page size varies between MCU vendors and families, but typically it's 1024 or 4096 bytes.

This leads to the question of choosing the rotation strategy (or rather granularity): on a per-page or per-frame basis.

How I image log rotation on a per-page basis:

  • When reached the end of the last NVRAM page (or rather when we realize that the current slice can't fit w/o wrapping),
    • Erase the very first page of the storage
    • Put a magic number there to identify that the storage is alive
    • Set "write" & "read" heads there right after the magic number
  • (edge-case) If a user has provided us with only a single page, so per-page granularity will lead to an immediate loss of previous log frames when wrapping occurs. This is sad, but still better than not wrapping because the device will still be able to function and log properly
  • After a first wrap, we'll have a bubble of "free" space moving through pages with data
    • If we realize that the current data slice can't fit into this bubble, then erase the next NVRAM page and then fill the bubble, and put the rest of the slice at the beginning of the next page.

Per-page basis has the advantage that it's straightforward to implement and also won't require an auxiliary SRAM buffer to salvage log frames from the page that's being erased.

Per-frame log rotation seems to me as more complicated and full of edge cases, as well as more SRAM-consuming.

@MathiasKoch
Copy link
Member Author

I would definitely vote for a per-page basis no matter what, even though i know i wrote n frames i did not mean it to be on a per-frame basis.

I think your suggestion here is spot on with how i imagined it to work 👍

@eupn eupn linked a pull request Jun 20, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 👍 New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants