Repository navigation
Description
Is your feature request related to a problem? Please describe.
- We are moving to POSIX compliant time representation (The Open Group Base Specifications Issue 8 IEEE Std 1003.1-2024 [1][2][3]) with
uint64_t. - POSIX
sys/types.h[3] defines:time_tas "Used for time in seconds"
time_tshall be an integer type with a width (see <stdint.h>) of at least 64 bits. - What it solves:
- year 2038 problem.
- 32-bit system clock wrapped in ~497 days and almost every active board already enabled it.
- runtime time overflow calculation errors after some weeks.
- What it breaks:
- 8/16/32-bit platforms are most likely impacted by increased code size (i.e. ~2KB) when
long longtype is not natively supported. - time calculation will be slower on older platforms.
- non-atomic time access (needs some additional protection).
- 8/16/32-bit platforms are most likely impacted by increased code size (i.e. ~2KB) when
This is a long standing challenge discussed on our mailing list [4][5].
Related PR: #18840, #14460, apache/nuttx-apps#3468.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/
[2] https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html
[3] https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html
[4] https://www.mail-archive.com/[email protected]/msg12060.html
[5] https://www.mail-archive.com/[email protected]/msg14534.html
Describe the solution you'd like
- We are moving towards POSIX standard compliant time representation with
int64_ttype as default. - We need alternative portable implementation of the time representation on platforms that do not support native
int64_ttype that will solve size increase, slow down, and non-atomic time access protections, but still assure POSIX compliant interface. - Form the OS perspective both implementations should provide exactly the same and one-to-one compatible / replaceable solution, but the "portable" should assure best fit for the small architectures.
Describe alternatives you've considered
No response
Verification
- I have verified before submitting the report.
Activity
Brijesh-Thakkar commentedon Oct 23, 2026
Hi @cederom, I'd like to work on this.
Current master: #18840 / apache/nuttx-apps#3468 are merged, time_t and clock_t are
int64_t, CONFIG_SYSTEM_TIME64 is gone. No open PR addresses #18849.
I measured the cost of the #18840 series (nuttx 9a84223 -> end of series, same
defconfig, arm-none-eabi-gcc 14.2.1 / avr-gcc 14.3.0):
So the ~2 KB estimate in the issue looks about right for small parts.
Side notes from testing: z80sim does not build with sdcc 4.5.0 even before #18840
(sdcc rejects -isystem), and no z80/z16 config is in tools/ci/testlist, so I couldn't
evaluate them. I'd suggest scoping this issue to AVR and small 32-bit parts first.
Proposed staged plan:
that default to today's int64_t operations, and convert sched/wdog, sched/timer and
clock_systime_* to use them. Output should be byte-identical on existing configs.
helpers, keeping the int64_t POSIX interface and using the existing seqlock for reads.
Does this direction look right? Is a no-behavior-change helper PR OK as the first step?
Brijesh-Thakkar commentedon Oct 29, 2026
Hi @cederom, just following up on this.
Would it be okay to start with the helper refactoring PR?
xiaoxiang781216 commentedon Oct 29, 2026
so, the plan still keep 64bit time_t/clock_t, but optimize the math operation for each arch?
Brijesh-Thakkar commentedon Oct 30, 2026
@xiaoxiang781216 yes, time_t/clock_t stay int64_t; no POSIX/API change.
Before proposing code I'm measuring where the size actually goes. Early symbol diff on
nucleo-f072rb:nsh (M0) shows ~80% of the +1.5 KB from #18840 is libgcc's generic 64-bit
divide/multiply (__divdi3, __udivmoddi4, __aeabi_ldivmod...), pulled in by only four
callers: clock_systime_timespec, uptime_read, clock_basetime and long long printf
(__ultoa_invert). Three of them divide by constants.
I'm checking whether avoiding those few divisions removes the libgcc code entirely, and
will post numbers before suggesting a direction.
xiaoxiang781216 commentedon Oct 30, 2026
yes, it's right approach to avoid the kernel common link libgcc 64bit functions.
xiaoxiang781216 commentedon Oct 30, 2026
__ultoa_invert is fixed by: #20996
Brijesh-Thakkar commentedon Oct 30, 2026
Thanks @xiaoxiang781216, good to know about #20996. I'll drop __ultoa_invert from my side,
rebase on top of #20996, and send a PR for the remaining kernel call sites
(clock_systime_timespec, uptime_read, clock_basetime) with before/after sizes for
nucleo-f072rb, stm32vldiscovery and breadxavr.
Side finding: div_const in include/nuttx/lib/math32.h gates its reciprocal-multiply path
on CONFIG_HAVE_EXPRESSION_STATEMENT, but nothing defines that symbol anywhere in the tree,
so the fast path is dead code. Forcing it on made M0 slightly bigger (+116 B, it pulls in
__aeabi_lmul instead), so I'm not relying on it. Should it be removed, or wired up?
Brijesh-Thakkar commentedon Oct 30, 2026
Update after measuring on top of #20996:
so no extra kernel helpers are needed there.
libgcc's routines (+306..+972 B on breadxavr), so I'm not proposing them. The one site that
does pay off is clock_basetime's multiply: #XXXXX (-82 B on breadxavr).
it further would need a different internal time representation.
@cederom given these numbers, do you still want a "portable" representation for 8-bit targets,
or is the remaining cost acceptable?
Brijesh-Thakkar commentedon Oct 30, 2026
Summary of what I measured for this issue:
common code with DEBUG_FULLOPT (stm32vldiscovery -872 B), so no further kernel changes are
needed there.
the remaining 64-bit divisions were always larger than libgcc's routines (+306..+972 B), and
the one multiply site I tried (sched/clock: use 32x32->64 multiply in clock_basetime #21212) only helps with recent avr-gcc; on CI's avr-gcc 5.4.0
it's +8 B, so I closed it.
internal time representation for 8-bit targets.
@cederom given these numbers, is the remaining cost acceptable for v13, or do you want a
"portable" representation for 8-bit?