Skip to content

libs/libc/time: Add configuration options for the strftime#19024

Merged
lupyuen merged 1 commit into
apache:masterfrom
tiiuae:make_strftime_configurable
Jun 4, 2026
Merged

libs/libc/time: Add configuration options for the strftime#19024
lupyuen merged 1 commit into
apache:masterfrom
tiiuae:make_strftime_configurable

Conversation

@jlaitine

@jlaitine jlaitine commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This adds 3 configuration options for the lib_strftime, which can be used to save flash memory when all the formatters are not needed by an embedded application.

There is always a minimal set of formatters supported: "%a, %b/%h, %d, %H, %m, %M, %S, %Y, %%". To add on top of that one can specify:

  • LIBC_STRFTIME_C_STANDARD_FORMATS : All ISO-C conversion specifiers
  • LIBC_STRFTIME_POSIX_FORMATS : Additional posix formats
  • LIBC_STRFTIME_NONSTANDARD_FORMATS : Additional GNU nonstandard formats

All of these are enabled by default unless building for CONFIG_DEFAULT_SMALL. Disabling these options can save over 3KB of flash on an 32-bit ARM system, when all the format specifiers are not needed.

I have grouped the switch-cases according to the flags, thinking that it was nicer. Now looking at this, I realize that it is quite difficult to review. I can also keep the switch-cases in order, and just scatter the ifdefs around, if that would be preferable, just let me know!

Impact

No impact, unless building for CONFIG_BUILD_SMALL (in which case the formatters needs to be enabled specifically), or if formatters are specifically disabled in the configuration.

Testing

Compilation has been tested on nucleo-f767zi:nsh:

  1. get boards/arm/stm32/nucleo: Fix BBSRAM compilation #19023 so that BBSRAM can be used
  2. Enable the following to pull in strftime (it is used bv boards crashdump saving code):

boards/arm/stm32f7/nucleo-f767zi/configs/nsh/defconfig:

CONFIG_STM32F7_BKPSRAM=y
CONFIG_STM32F7_BBSRAM=y
CONFIG_STM32F7_PWR=y
CONFIG_STM32F7_SAVE_CRASHDUMP=y

  1. Build and monitor flash size:
./tools/configure.sh nucleo-f767zi:nsh
make

LD: nuttx              
Memory region         Used Size  Region Size  %age Used
            itcm:          0 GB         2 MB      0.00%
           flash:      142492 B         2 MB      6.79%
            dtcm:          0 GB       128 KB      0.00%
           sram1:        6032 B       368 KB      1.60%
           sram2:          0 GB        16 KB      0.00%

  1. Disable un-used format specifiers (leave only minimal set):

boards/arm/stm32f7/nucleo-f767zi/configs/nsh/defconfig:

# CONFIG_LIBC_STRFTIME_C_STANDARD_FORMATS is not set
# CONFIG_LIBC_STRFTIME_NONSTANDARD_FORMATS is not set
# CONFIG_LIBC_STRFTIME_POSIX_FORMATS is not set
  1. Build and monitor flash size
make distclean
./tools/configure.sh nucleo-f767zi:nsh
make

LD: nuttx              
Memory region         Used Size  Region Size  %age Used
            itcm:          0 GB         2 MB      0.00%
           flash:      139208 B         2 MB      6.64%
            dtcm:          0 GB       128 KB      0.00%
           sram1:        6032 B       368 KB      1.60%
           sram2:          0 GB        16 KB      0.00%

Diff: 3284 bytes smaller image

In addition, functionality is checked with "date" on Pixhawk4 board, using only minimal set of formatters:


nsh> date
Thu, Jan 13 15:11:49 2000
nsh> date -s "Jun 2 15:40:00 2026"
nsh> date
Tue, Jun 02 15:40:01 2026
nsh> 

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Jun 2, 2026
acassis
acassis previously approved these changes Jun 2, 2026
Comment thread libs/libc/time/Kconfig Outdated
Comment thread libs/libc/time/Kconfig Outdated
linguini1
linguini1 previously approved these changes Jun 2, 2026

@linguini1 linguini1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keep the memory optimizations coming!

@jlaitine jlaitine dismissed stale reviews from linguini1 and acassis via 953f92b June 2, 2026 16:08
@jlaitine jlaitine force-pushed the make_strftime_configurable branch from ed8f683 to 953f92b Compare June 2, 2026 16:08
Comment thread libs/libc/time/Kconfig Outdated
@jlaitine jlaitine force-pushed the make_strftime_configurable branch 2 times, most recently from 85dd0aa to 560beaa Compare June 3, 2026 07:48
@jlaitine

jlaitine commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebase on latest master

@lupyuen

lupyuen commented Jun 3, 2026

Copy link
Copy Markdown
Member

Hi: Could you Rebase your PR with the Master Branch? We fixed the Segger SystemView Error in the CI Build. Thanks :-)

This adds 3 configuration options for the lib_strftime, which can be
used to save flash memory when all the formatters are not needed by an
embedded application.

There is always a minimal set of formatters supported:
"%a, %b/%h, %d, %H, %m, %M, %S, %Y, %%". To add on top of that one can
specify:

- LIBC_STRFTIME_C_STANDARD_FORMATS  : All ISO-C conversion specifiers
- LIBC_STRFTIME_POSIX_FORMATS       : Additional posix formats
- LIBC_STRFTIME_NONSTANDARD_FORMATS : Additional GNU nonstandard formats

All of these are enabled by default unless building for CONFIG_DEFAULT_SMALL.
Disabling these options can save over 3KB of flash on an 32-bit
ARM system, when all the format specifiers are not needed.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
@jlaitine jlaitine force-pushed the make_strftime_configurable branch from 560beaa to 1e73a7c Compare June 3, 2026 12:05
@jlaitine

jlaitine commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

re-based to pass the CI

@lupyuen

lupyuen commented Jun 4, 2026

Copy link
Copy Markdown
Member

FYI: I restarted the CI Build to fix the Docker Image

@lupyuen lupyuen merged commit 116a325 into apache:master Jun 4, 2026
65 of 93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants