Skip to content

Conversation

@npitre
Copy link

@npitre npitre commented Mar 1, 2021

This is an alternative to PR #30675.

Before adding packaged support to cbprintf_complete.c:

   text    data     bss     dec     hex filename
   3430       0       0    3430     d66 cbprintf_complete.c.obj

With packaged support added to cbprintf_complete.c per PR #30675:

   text    data     bss     dec     hex filename
   5500       0       0    5500    157c cbprintf_complete.c.obj

This is a code growth of 2070 bytes, in addition to non negligible stack
usage as documented in that PR.

With this alternative approach here we have:

   text    data     bss     dec     hex filename
   1580       0       0    1580     62c cbprintf_packaged.c.obj

( Those numbers are for Aarch64 )

Furthermore, this is completely independent from the printing facility
meaning that it is compatible with both cbprintf_complete and
cbprintf_nano, and cbprintf_complete won't degrade due to additional
stack usage as it remains unchanged.

@github-actions github-actions bot added area: API Changes to public APIs area: Tests Issues related to a particular existing or missing test labels Mar 1, 2021
@nashif nashif requested a review from pabigot March 1, 2021 04:27
Copy link
Contributor

@nordic-krch nordic-krch left a comment

Choose a reason for hiding this comment

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

seems ok, there is a benefit of have it also for cprintf_nano. I will try to adapt static packaging.

Copy link
Contributor

Choose a reason for hiding this comment

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

you have to store float argument even though it is not supported, otherwise output is corrupted for strings containing %f

Copy link
Contributor

Choose a reason for hiding this comment

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

more precisely, you have to consume the float argument even if you're going to discard it.

Copy link
Contributor

Choose a reason for hiding this comment

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

i would prefer that this is stored as u16 together with the value above which also could be u16. 64k should be more than enough for both values and it results in smaller and aligned buffer in the typical cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

what about packaged buffer alignment. It does not matter when cbpprintf is called from the same memory but if package is copied then new buffer must have same alignment as the original one. Maybe require buffer to be aligned?

Copy link
Contributor

@pabigot pabigot left a comment

Choose a reason for hiding this comment

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

If this passes comprehensive tests as in #30675, and meets the needs of #30675, I have no objections.

Copy link
Contributor

Choose a reason for hiding this comment

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

The l and ll length specifiers mean something different for integral, character, and floating point types.

Copy link
Contributor

Choose a reason for hiding this comment

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

more precisely, you have to consume the float argument even if you're going to discard it.

@zephyrbot zephyrbot added the area: Base OS Base OS Library (lib/os) label Mar 1, 2021
@npitre
Copy link
Author

npitre commented Mar 1, 2021 via email

@npitre
Copy link
Author

npitre commented Mar 1, 2021 via email

@nordic-krch
Copy link
Contributor

@npitre

Storing them together isn't a bad idea per se. However that will save
only one byte of storage, and have no material effect on alignment as
what follow are only strings with no alignment.

Strings are optional and rare case and this field is obligatory. When there are no strings, it still needs to be set to 0. Package will be used in logging messages which will be at least word aligned. Typically, a message will have 6-10 words so one additional word is significant.

@npitre
Copy link
Author

npitre commented Mar 1, 2021 via email

@nordic-krch
Copy link
Contributor

looks ok now, can you extract tests into separate commit?

@npitre
Copy link
Author

npitre commented Mar 3, 2021 via email

@nordic-krch
Copy link
Contributor

The API is slightly different from Peter's as the actual size that would have been needed is not available when the return code is -ENOSPC.

No problem from my perspective.

I tried to add a test that runs on all qemu's targets. I've seen two issues:

  • on qemu_leon3 alignment for long long is 8 but it seems that va_arg(long long) reads with 4 byte alignment. On the other hand qemu crashes when trying to write long long to non 8 byte aligned address. I fixed it by adding memcpy (nordic-krch@889322d) and set VA_STACK_ALIGN_LONGLONG to 4 that solved the issue.
  • issues with qemu_xtensa. Not sure what exactly is wrong but it seems that conversion to va_list is not correct.

My work with static packaging and cbprintf_package test can be found here: https://github.com/nordic-krch/zephyr/tree/cbprintf_static_package2

@npitre npitre force-pushed the cbprintf_packaged branch from 863c21e to b265cd3 Compare March 4, 2021 02:16
@npitre
Copy link
Author

npitre commented Mar 4, 2021 via email

Copy link
Contributor

@nordic-krch nordic-krch left a comment

Choose a reason for hiding this comment

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

looks good

Copy link
Contributor

@pabigot pabigot left a comment

Choose a reason for hiding this comment

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

This seems fine.

Blocking due to an offline request from @carlescufi: For the commits that have things like:

[ Documentation and commit log shamelessly stolen from Peter Bigot. ]
[ Heavily based on a prior proposal from Peter Bigot. ]

please instead add my Signed-off-by from the original commit to track provenance in accordance with Zephyr policy.

@npitre
Copy link
Author

npitre commented Mar 4, 2021 via email

@npitre npitre force-pushed the cbprintf_packaged branch from b265cd3 to 8d134f4 Compare March 4, 2021 14:34
@carlescufi
Copy link
Member

According to https://docs.zephyrproject.org/latest/contribute/modifying_contributions.html#modifying-contributions I did option 2. If you prefer that I simply add your sign-off that's fine with me.

@npitre thanks. If you don't mind, then I think it's clearer this way.

@npitre
Copy link
Author

npitre commented Mar 4, 2021 via email

@pabigot pabigot self-requested a review March 4, 2021 14:49
Copy link
Contributor

@pabigot pabigot left a comment

Choose a reason for hiding this comment

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

The comment about "shamelessly stolen" seems unnecessary, but the signed-off-lines confirm legal provenance.

@pabigot
Copy link
Contributor

pabigot commented Mar 4, 2021

According to https://docs.zephyrproject.org/latest/contribute/modifying_contributions.html#modifying-contributions I did option 2.

@carlescufi If that's being interpreted to mean that incorporating material from contributions without preserving the signed-off-by line is acceptable, then I think that needs to be fixed. It has to be understood that "signed-off-by" does not mean "agrees with the content and purpose of the commit"; it means "contributions conform to DCO".

IMO. IANAL.

@carlescufi
Copy link
Member

@carlescufi If that's being interpreted to mean that incorporating material from contributions without preserving the signed-off-by line is acceptable, then I think that needs to be fixed. It has to be understood that "signed-off-by" does not mean "agrees with the content and purpose of the commit"; it means "contributions conform to DCO".

Looking back at the text that you and @npitre linked to, I believe you are right @pabigot. Would you mind sending a PR with a proposal to fix this in the doc?

@npitre
Copy link
Author

npitre commented Mar 4, 2021 via email

Nicolas Pitre and others added 3 commits March 5, 2021 00:13
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.

[ Documentation and commit log from Peter Bigot. ]

Signed-off-by: Nicolas Pitre <[email protected]>
Signed-off-by: Peter Bigot <[email protected]>
Tests to exercise the new `cbprintf_package()`, `cbvprintf_package()`
and `cbpprintf()`.

[ Heavily based on a prior proposal from Peter Bigot. ]

Signed-off-by: Nicolas Pitre <[email protected]>
Signed-off-by: Peter Bigot <[email protected]>
Add test to validate cbprintf packaging on various platforms

Signed-off-by: Krzysztof Chruscinski <[email protected]>
@npitre npitre force-pushed the cbprintf_packaged branch from c6de351 to 935ee55 Compare March 5, 2021 05:18
@npitre
Copy link
Author

npitre commented Mar 5, 2021

Pushed a few cleanups and minor changes.

@nordic-krch the two header values are now uint8_t instead of uint16_t
and the arg length and string pointer position are multiples of sizeof(int).

This leaves some room (16 bits on 32-bit systems and 48 bits on 64-bit
systems) for an eventual bitmap indicating which int's were removed from
the package because they were zeroes, either due to padding or placeholders
for string pointers, or zero arguments, etc. That could be useful to
compact things if desired,, especially on 64-bit systems where everything
is aligned to 8-byte boundaries.

@carlescufi carlescufi merged commit dccfe76 into zephyrproject-rtos:master Mar 5, 2021
@npitre npitre deleted the cbprintf_packaged branch March 5, 2021 21:36
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: Base OS Base OS Library (lib/os) area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants