- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.2k
 
lib: os: cbprintf: Add static packaging #31102
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
          
     Closed
      
      
            nordic-krch
  wants to merge
  20
  commits into
  zephyrproject-rtos:master
from
nordic-krch:cbprintf_static_package
  
      
      
   
      
    
                
     Closed
            
            lib: os: cbprintf: Add static packaging #31102
                    nordic-krch
  wants to merge
  20
  commits into
  zephyrproject-rtos:master
from
nordic-krch:cbprintf_static_package
  
      
      
   
              
            Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    If a precision flag is included for s formatting that bounds the maximum output length, so we need to use strnlen rather than strlen to get the amount of data to emit. With that flag we can't expect there to be a terminating NUL following the text to print. Also fix handling of an empty precision, which should behave as if a precision of zero was provided. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Replace SANITYCHECK flag with TWISTER. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
TC_PRINTF doesn't append a newline, so the skip messages sometimes ran into the test result message. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Providing a literal width or precision that exceeds the non-negative range of int does not appear to be rejected by the standard, but it does produce a build diagnostic so we can't test it. Switch to an equivalent form that doesn't affect line coverage. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This function was designed to support the logging infrastructure's need to copy values from va_list structures. It did not meet that need, since some values need to be changed based on additional data that is only available when the complete format specification is examined. Remove the function as unnecessary. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
It may not be clear that the length modifiers reference native C types with specific ranks. Document the core type for each modifier. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The extraction of values from varargs was inlined in cbvprintf() because va_list arguments cannot be passed into subroutines by reference, and there was only one place that needed this functionality. An upcoming enhancement requires extracting the arguments but processing them later, so outline the extraction code. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Format width and precision can be extracted from arguments. A negative value is interpreted by changing flag state and using the non-negative value. Refactor pull_va_args() so the raw value from the stack is preserved in the state so it can be packed, deferring the interpretation to point-of-use. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
An upcoming enhancement supports conversion with information provided from sources other than a va_list. Add a level of indirection so the core conversion operation isn't tied to the stdarg API. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Several tests require additional stack space to accommodate a deeper call stack due to inability to inline functions in an upcoming enhancement. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
In applications like logging the call site where arguments to formatting are available may not be suitable for performing the formatting, e.g. when the output operation can sleep. Add API that supports capturing data that may be transient into a buffer that can be saved, and API that then produces the output later using the packaged arguments. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Double vs long double handling was swapped in packaging. It was wrong in encoder and decoder so error gone unnoticed. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Use int for H and HH values. This allows to statically package all arguments of size int and smaller. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Using wint_t instead of unsigned long to package %lc. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Fixed compilation issues with wint_t by replacing it with wchar_t. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  This was referenced Jan 5, 2021 
      
      
     Merged
  
2de98cf    to
    f867185      
    Compare
  
    Added version which compiles much faster and provide similar functionality (with few limitations). If macros are widely used then compile time is significantly shorter (order of magnitude). Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added tests for FAST_FOR_EACH_x, FAST_GET_ARG_N and FAST_GET_ARGS_LESS_N. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added macro for determining if string can be statically packaged. Added macro for static packaging of a string. Added cbprintf_internal.h with internal macros to avoid spoiling API file. Additionally, added option for packaging to store first char pointer (fmt) as a standard pointer witouth 1 byte header which distinguish between storing by pointer and storing by value. This can significantly reduce storage, e.g. string without any arguments uses one word vs two word (byte header + alignment). Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
f867185    to
    c2393cc      
    Compare
  
    Added new tests and modified existing tests to validate static packaging. If static packaging is enabled then it is performed whenever possible. Dedicated test is used for validating static packaging for cases where runtime package may differ due to padding. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
c2393cc    to
    eeef7cc      
    Compare
  
    In order to create a package each parameter must be promoted by adding 0. However, it generates a warning for void * arguments. Added pragma to temporarly suppress that warning inside the macro. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
eeef7cc    to
    b2688a5      
    Compare
  
    | 
           Superseded by #32863.  | 
    
  
    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: Kernel
  
    area: Tests
  Issues related to a particular existing or missing test 
  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.
  
    
  
    
PR is based on #30675 but it extends it with support for creating packages statically.
Staticallymeans that a package (serialized string with arguments) is created as assignment to a buffer. Opposed to runtime package creation withcbprintf_package()(added by #30675) where string is analyzed and based on format specifiers a package is created.In principle,
CBPRINTF_STATIC_PACKAGE(buf, len, "test %d", n)resolves to assignments:Added macros for:
CBPRINTF_MUST_RUNTIME_PACKAGEreturns 1 if runtime packaging must be used.In order to calculate length that can be assigned to const variable 2 step method is used. First part is creating local copies of arguments (handling
sizeof("string")case). Second step macro returns package size:Creating package on stack snippet:
Extended test suite to compare static packaging against runtime whenever possible. Additionally, added 2 tests which validates macros behavior.
I have initial version of logger which is using this extension and supports basic functionality.