[Plat-8106] Remove calls to libc printf #1397
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
Libc printf acquires locks, and so it not safe for use in async-safe code.
This PR replaces these calls with async-safe alternatives, and also disables low level logging by default so that it doesn't run in production (it doesn't hurt anything, but bloats the binary size, and is of no use in the field).
Design
Low level number-to-string functions from the JSON encoder have now been exposed so that they can be used from elsewhere.
Added stb_sprintf to replace the few sprintf calls in the logger and other places in the codebase that can't be easily replaced with simpler alternatives.
All low level logging is now dependent upon the define
BSG_KSLOG_ENABLE_LOW_LEVEL_LOGGING
. When 0, no low level logging code is compiled.Testing
Added tests for the low level number-to-string functions.
Tested manually with
BSG_KSLOG_ENABLE_LOW_LEVEL_LOGGING
= 1 and = 0.