-
Notifications
You must be signed in to change notification settings - Fork 6
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
[RFC] Add logging support #28
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
- Feature Name: `Logger support` | ||
- Start Date: 2019-12-28 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Summary | ||
[summary]: #summary | ||
|
||
Add support for interrupt priority based logging in RTFM (ala [`cortex-m-funnel`]). | ||
|
||
# Motivation | ||
[motivation]: #motivation | ||
|
||
One of the most time consuming issues of embedded programming is debugging. And especially when it comes to event based systems where debugging can get in the way of timing requirements. Debugging is often done through logging with `printf`-like methods, and the logger implementation will often impede real-time requirements, causing the system to behave differently with and without logging enabled. | ||
This often comes from logger implementations having global critical sections for accessing the log buffers, but with RTFM we can have seamless support for logging without critical sections by leveraging the design and ideas behind [`cortex-m-funnel`]. | ||
|
||
The idea behind it is that there exists one logging queue per interrupt priority, and a logging function always writes to the currently running priority which in turn means that no critical sections are needed (see [`cortex-m-funnel`] for implementation details). | ||
|
||
Adding this feature will help users immensely, as figuring out logging is not a trivial task. This will also help adoption of RTFM as **we made logging easy**. | ||
|
||
# Detailed design | ||
[design]: #detailed-design | ||
|
||
The important thing is to define how large the buffers should be. Either we can go with the simplest case (and have all buffers the same size): | ||
|
||
```rust | ||
#[app(logger = 256)] | ||
// ... | ||
``` | ||
|
||
Or we can have a base size, together with possible specialization (bikeshed of API needed): | ||
|
||
```rust | ||
// Base size of 256 bytes, but the queue for priority 7 is of 1024 bytes | ||
#[app(logger = [base = 256, 7 = 1024])] | ||
// ... | ||
``` | ||
|
||
The final implementation of the logging is very simple. Simply, based on the analysis, fill out the [`cortex-m-funnel`] macro. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cortex-m-funnel only supports |
||
|
||
One thing we should be careful with is that the logger should be **external** to RTFM so it is easy to include in libraries. Just as the [`log`] crate is today. | ||
|
||
## Should the log be part of task definition? | ||
|
||
It is my view that it should not. We should follow the common design of [`log`] and [`cortex-m-funnel`], where the log macros can be added anywhere without propagating it down through the call tree. This is the key feature that makes it easy to use, just have RTFM provide the information to properly initialize the queues for the logger. | ||
|
||
# How We Teach This | ||
[how-we-teach-this]: #how-we-teach-this | ||
|
||
This should be added to the book as its own `Safe logging` chapter. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would name the chapter 'non-blocking logging', 'real-time logging' or something like that. |
||
|
||
# Drawbacks | ||
[drawbacks]: #drawbacks | ||
|
||
* Increase of complexity of RTFM, but I would argue that this is of much greater help than not to have it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it also ties RTFM semver to cortex-m-funnel version so if we release a RTFM that uses cortex-m-funnel v0.1 it probably won't work with the |
||
|
||
# Alternatives | ||
[alternatives]: #alternatives | ||
|
||
* Use `cortex-m-funnel` manually, however this would be easy to get wrong | ||
|
||
# Unresolved questions | ||
[unresolved]: #unresolved-questions | ||
|
||
* API design | ||
|
||
[`cortex-m-funnel`]: https://github.com/japaric/cortex-m-funnel | ||
[`log`]: https://github.com/rust-lang/log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax of the
#[app]
arguments can be anything; the downside is that it never gets formatted byrustfmt
. I personally would prefer not to enter so much data as an attribute arguments but can't think of a better syntax right now.