Skip to content

Conversation

@nordic-krch
Copy link
Contributor

Logger must support the case when API is used before logger is explicitly
initialized. When logger API is called and logger is not yet initialized,
it is initialized implicitly with dummy timestamp function (timestamp
source may not be yet available).

Signed-off-by: Krzysztof Chruscinski [email protected]

@codecov-io
Copy link

codecov-io commented Jul 5, 2018

Codecov Report

Merging #8742 into master will decrease coverage by 0.02%.
The diff coverage is 53.12%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8742      +/-   ##
==========================================
- Coverage   52.34%   52.31%   -0.03%     
==========================================
  Files         195      195              
  Lines       24723    24741      +18     
  Branches     5139     5146       +7     
==========================================
+ Hits        12941    12944       +3     
- Misses       9708     9717       +9     
- Partials     2074     2080       +6
Impacted Files Coverage Δ
subsys/logging/log_core.c 66.23% <53.12%> (-6.57%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0aedf8d...cff2617. Read the comment docs.

Copy link
Member

Choose a reason for hiding this comment

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

As the logging could be called from multiple threads that could be preempted, shouldn't the interface variable be atomic so that we would not be able call log_init() twice. By looking the code, it seems possible that log_init() could be initialized more than once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jukkar good point, I've added following mechanism: logger can have 3 internal states: uninit'ed, init in progress, init'ed. each log API is atomic_inc state and only if previous state was uninit'ed it will perform initialization, if state is init in progress then log is dropped because we cannot do much since we interrupt log initialization.

I've added kindof state initial precheck before doing atomic incrementation for performance reasons.

@pizi-nordic pizi-nordic self-requested a review July 6, 2018 14:40
Logger must support the case when API is used before logger is
explicitly initialized. When logger API is called and logger is
not yet initialized, it is initialized implicitly with dummy
timestamp function (timestamp source may not be yet available).

Signed-off-by: Krzysztof Chruscinski <[email protected]>
Copy link
Contributor

@pizi-nordic pizi-nordic left a comment

Choose a reason for hiding this comment

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

How this PR will cooperate with this one: #8704 ?

@nordic-krch
Copy link
Contributor Author

@pizi-nordic after recent updates in #8704 it will.

Copy link
Contributor

@pizi-nordic pizi-nordic left a comment

Choose a reason for hiding this comment

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

In my opinion we should just initialize the logger during system start-up. Then this change (which slightly degrades performance) will be not needed.

} while (0)

#define LOG_COND_INIT() _COND_INIT(return)
#define LOG_COND_INIT_PRINTK() _COND_INIT(return 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hiding return statement in macro is not a good idea. Please consider using anonymous functions to check the state and initialize logger.

@nordic-krch
Copy link
Contributor Author

@nashif regarding:

In my opinion we should just initialize the logger during system start-up. Then this change (which slightly degrades performance) will be not needed.

Do you know (or know who knows) where would be the best place to add that. In that case we could just add assert to log API checking if it is initialized to detect if somehow log is used before being initialized.

@jukkar
Copy link
Member

jukkar commented Jul 11, 2018

Do you know (or know who knows) where would be the best place to add that. In that case we could just add assert to log API checking if it is initialized to detect if somehow log is used before being initialized.

The kernel/init.c looks like a good candidate to place such early init calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants