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

logging: add minimal implementation #19322

Merged
merged 6 commits into from
Oct 1, 2019

Conversation

andrewboie
Copy link
Contributor

@andrewboie andrewboie commented Sep 22, 2019

The log mechanism, even in immediate mode, adds somewhere
between 1K-2K of footprint to applications that use it.

We want to standardize the logging APIs for all logging
within the kernel, but need to not let platforms with
very constrained RAM/ROM in the dust.

This patch introduces CONFIG_LOG_MINIMAL, which is a very
thin wrapper to printk(). It supports the APIs expressed
in logging/log.h.

This will be the new default for test cases.

log_printk()'s return value was removed to make it more like Zephyr printk().

Some code in shell and bluetooth monitor which assumed that the backend code existed has been adjusted.

Fixes: #19317

@zephyrbot zephyrbot added area: Logging area: Test Framework Issues related not to a particular test, but to the framework instead area: API Changes to public APIs area: Kernel labels Sep 23, 2019
@zephyrbot
Copy link
Collaborator

zephyrbot commented Sep 23, 2019

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@ulfalizer
Copy link
Collaborator

Would be nice to refactor the console stuff to do less selecting at some point. Those dependency loops get pretty hairy.

Also saw a bunch of select-with-unsatisfied-deps. issues there earlier, but maybe most of them have gotten fixed.

@andrewboie
Copy link
Contributor Author

andrewboie commented Sep 23, 2019

Would be nice to refactor the console stuff to do less selecting at some point. Those dependency loops get pretty hairy.

@ulfalizer I ran into this. If I change the "imply PRINTK" to "depends-on PRINTK" for CONFIG_LOG_MINIMAL, it all goes up in flames with a circular dependency.

Also saw a bunch of select-with-unsatisfied-deps. issues there earlier, but maybe most of them have gotten fixed.

Think I've seen these at times, but might because I modfied some Kconfig and needed to do a clean build.

@ulfalizer
Copy link
Collaborator

ulfalizer commented Sep 23, 2019

@ulfalizer I ran into this. If I change the "imply PRINTK" to "depends-on PRINTK" for CONFIG_LOG_MINIMAL, it all goes up in flames with a circular dependency.

Yeah, honestly those errors are a pain to figure out for me too. Usually, it helps to try to stick to depends on everywhere you can, so that all dependencies go in the same direction, and only select/imply very "locally" if you must (except for simple helper symbols).

Unrelated to this PR though.

@joerchan
Copy link
Contributor

Could this minimal implementation be used instead of LOG_IMMEDIATE?
It seems to be a lot of problems with LOG_IMMEDIATE, and it would be nice to reduce the amount of functionality that we have to maintain.

@nordic-krch
Copy link
Contributor

It seems to be a lot of problems with LOG_IMMEDIATE

The main issue (once #19339 gets in) is the fact that when log immediate is enabled then thread stack usage increases and that will lead to mpu faults since stacks are tuned for deferred logging. Minimal logging won't help with that since main stack contributor is string formatting.

By switching to log minimal we safe ~2k of ROM compared to log_immediate but we lose things like pretty output (timestamp, module name/log level/function name prefix), support for multiple backends, integration with shell. Imo, the difference is significant enough to have both options.


#define Z_LOG(_level, fmt, ...) do { \
if (Z_LOG_CONST_LEVEL_CHECK(_level)) { \
printk(fmt "\n", ##__VA_ARGS__); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no locking here. Won't it crash if one log interrupts another? I guess that simple console like uart may survive but what about console over cdc acm?

Copy link
Contributor Author

@andrewboie andrewboie Sep 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't. these emit to the console drivers one character at a time.

Copy link
Collaborator

@LeiW000 LeiW000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the code itself, I don't see anything wrong.

Copy link
Contributor

@joerchan joerchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_strdup has an issue if it is called twice in the same call to LOG_INFO. I would really like to see this fixed, as there are instances where this happens in the stack at the moment. And using minimal logging would yield very confusing logging info when this happens. (see my earlier comment https://github.com/zephyrproject-rtos/zephyr/pull/19322/files#r327967725)

@andrewboie
Copy link
Contributor Author

andrewboie commented Sep 27, 2019

log_strdup has an issue if it is called twice in the same call to LOG_INFO.

I'm not seeing how this is related to my patch?
Seems a problem with the log system in general.
[edit] I see it now. Can we just document in log_strdup() that they shouldn't use it in this way? The problem here is that with minimal logging we can't start bringing in heap allocations as required. It will be extra code, and FuSa/MISRA-C both discourage runtime heap allocations in functionally safe applications -- and at the same time these log_strdup() calls are required for the standard frontend.

@joerchan
Copy link
Contributor

@andrewboie We have discussed this offline and reached the conclusion that we can leave log_strdup like this. (although for the record the name is misleading and could possible lead to the same confusion for others).

@andrewboie
Copy link
Contributor Author

andrewboie commented Sep 30, 2019

Updated PR:

  • LOG_MINIMAL logic folded into __LOG and __LOG_HEXDUMP instead of Z_LOG/Z_LOG_HEXDUMP per @nordic-krch suggestion
  • Error type codes now printed for minimal logging
  • log_strdup() doc string updated to not rely on duplication behavior

@andrewboie andrewboie force-pushed the minimal-logging branch 3 times, most recently from 443c97c to d25ac9c Compare September 30, 2019 23:43
Andrew Boie added 6 commits September 30, 2019 16:51
Similar to how LOG_INIT(), LOG_PANIC(), etc are
wrapped.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
The same function should not be defined in two different
headers.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
printk() doesn't return a value, this doesn't need to
either.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
These checks should be against CONFIG_SHELL_LOG_BACKEND,
and not against CONFIG_LOG, since it's possible to enable
logging without building this particular backend.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Log backends don't exist with minimal logging enabled,
don't compile this code.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
The log mechanism, even in immediate mode, adds somewhere
between 1K-2K of footprint to applications that use it.

We want to standardize the logging APIs for all logging
within the kernel, but need to not let platforms with
very constrained RAM/ROM in the dust.

This patch introduces CONFIG_LOG_MINIMAL, which is a very
thin wrapper to printk(). It supports the APIs expressed
in logging/log.h.

This will be the new default for test cases.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@nashif nashif closed this Oct 1, 2019
@nashif nashif reopened this Oct 1, 2019
@joerchan
Copy link
Contributor

joerchan commented Oct 1, 2019

  • log_strdup() doc string updated to not rely on duplication behavior

Thank you.

@andrewboie andrewboie requested a review from nordic-krch October 1, 2019 06:58
@nashif nashif merged commit 7e29c9d into zephyrproject-rtos:master Oct 1, 2019
@andrewboie andrewboie deleted the minimal-logging branch October 2, 2019 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Bluetooth area: Kernel area: Logging area: Shell Shell subsystem area: Test Framework Issues related not to a particular test, but to the framework instead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

need a minimal log implementation that maps to printk()
7 participants