-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Logger process trigger #8704
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
Logger process trigger #8704
Conversation
|
cc: @jukkar |
Codecov Report
@@ Coverage Diff @@
## master #8704 +/- ##
==========================================
- Coverage 52.3% 52.28% -0.02%
==========================================
Files 196 196
Lines 24778 24788 +10
Branches 5152 5152
==========================================
+ Hits 12959 12961 +2
- Misses 9740 9748 +8
Partials 2079 2079
Continue to review full report at Codecov.
|
subsys/logging/log_core.c
Outdated
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.
I think sleeping here is not good. We should have a way to be notified here that there are messages waiting to be processed, k_poll() could be used here for example.
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.
There is notifying option: number of buffered messages are tracked and when exceeds the threshold task is waken up. Sleeping is added for case when logs are not arriving continuously and some could stuck for long period. I added threshold to avoid calling k_wakeup() on every log entry because that degrades performance of the logger.
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.
Do you mean that this thread is put to sleep and then waken up by some other thread?
Having a k_sleep() here means that basically you are polling the logger. I think this is not really good to do it like this. Better would be that when things exceed some threshold, the logging APIs will trigger a pollable event, which causes this reading thread to be waken up and process the data. After processing this data, the thread starts to wait another events. This is a bit more code than plain sleep, but is better architecturally.
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.
yes, PR contains 2 commits, first commit (9495059) adds ability to wake up a thread when threshold is exceeded. Second commit (adding internal thread) is using this feature but additionally adds sleep period in the thread. Sleeping is added to ensure that buffered logs are processed (and presented to the developer) even when logs stopped arriving. Let say that threshold is set to 20 and you have 19 logs in a buffer and next log will not come for dozens of seconds. You may get confused in that situation if you except to see given log (e.g. you got connected, but log does not print "connected").
Sleep period is configurable (maybe i should add option where sleep period 0 sets forever sleeping).
dddcec8 to
bb47d7f
Compare
|
BTW, do we really need to have "subsys:" in the commit subject? I think this is redundant as "logging" is your subsystem so there is no need to add 8 characters more to commit subject, that give no real information. |
bb47d7f to
e5a51c7
Compare
|
@jukkar removed subsys: part from commit messages. |
subsys/logging/Kconfig
Outdated
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 name of the option does not match the help or the prompt, i.e. this is for number of buffered logs, but no mention of that in the name of the config. Also, what is THR? if thread, please spell it out.
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.
THR was supposed to mean threshold. I've extended it to threshold to avoid confusion and modified prompt to "Amount of buffered logs which triggers processing thread."
subsys/logging/log_core.c
Outdated
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.
call this 'log_process_thread', then it appears as such when we list threads by name (using stringify)
fbd2c05 to
2cd625f
Compare
subsys/logging/log_core.c
Outdated
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.
We definitely have to separate logger initialization from thread-based processing initialization.
The logger must be be able to log data very early (ideally just after entering C code), while threads could start after system is fully initialized.
Ideally we should end with a call to log_init() in Zephyr startup code and (much) later application might decide how it is going to process gathered data (in the idle, dedicated thread or somewhere else).
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.
good point, I've extracted setting thread to external function. log_init() is without parameters and initializes fifo and does not touch thread part. I checked that it will play nicely with #8742
2cd625f to
5301b80
Compare
doc/subsystems/logging/logger.rst
Outdated
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.
Could we add an option which will set priority of internal thread?
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.
added configurable priority and stack size.
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.
Could we have a log_flush() or something else which will block current thread until log queue is empty?
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.
I've added log_buffered_cnt() to log_ctrl.h api which returns number of currently pending log messages. It is later on used in the example to pend on log flush
subsys/logging/Kconfig
Outdated
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.
I suggest 2 different options:
LOG_PROCESS_THREAD: Allow for log processing thread, enables other LOG_PROCESS_THREAD_* options.
LOG_PROCESS_THREAD_INTERNAL: Enables internal thread for log processing.
subsys/logging/log_core.c
Outdated
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.
Is that empty line needed?
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.
no
subsys/logging/Kconfig
Outdated
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.
There sould be a note, that this option affects only internal thread.
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.
yep
dbkinder
left a comment
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.
+1 for doc changes as written.
8fb4b54 to
ed54a35
Compare
doc/subsystems/logging/logger.rst
Outdated
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.
IMHO it might be worth to mention, that this also affects internal thread if it is enabled.
"... threshold dedicated thread (see :cpp:func:log_thread_set) or the internal one"
doc/subsystems/logging/logger.rst
Outdated
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.
Last sentence is unclear to me.
What about something like this: "In that case logger thread is initialized and log messages are processed implicitly."?
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.
Why this k_sleep() is needed?
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.
it can be removed once #8842 goes in. It's about allowing log to initialize since log thread is on low priority and initialization is there.
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.
@nashif: Could you please merge #8842?
@nordic-krch: Could you please rebase this after #8842 will be merged?
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.
done
subsys/logging/log_core.c
Outdated
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.
Should we allow to replace logger internal thread?
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.
It is exposed in case user does not use internal thread. I can add assert there to check if proc_tid before setting is null.
ed54a35 to
49633b8
Compare
Added configurable threshold of number of buffered log messages on which log wakes up thread which processes buffered logs. Thread ID is provided during logger initialization. Feature is optional and can be disabled by setting CONFIG_LOG_PROCESS_TRIGGER_THR to 0. Signed-off-by: Krzysztof Chruscinski <[email protected]>
When enabled, logger is creating own thread which processes buffered logs. When no logs to process, thread sleeps for configurable period. Thread can be waken up if number of buffered log messages exceeds configured threshold. Logging sample aligned to use new feature. Signed-off-by: Krzysztof Chruscinski <[email protected]>
Documenting new logger features: waking up processing thread and internal logger processing thread. Signed-off-by: Krzysztof Chruscinski <[email protected]>
49633b8 to
cb8c89b
Compare
Two features are introduced:
Logger sample updated to showcase new features.