Skip to content

testing/ostest,system/dd: reduce the test image's flash footprint - #4040

Merged
xiaoxiang781216 merged 3 commits into
apache:masterfrom
Fix-Point:g4-flash-ostest-dd
Nov 14, 2026
Merged

xiaoxiang781216 merged 3 commits into
apache:masterfrom
Fix-Point:g4-flash-ostest-dd

Conversation

@Fix-Point

@Fix-Point Fix-Point commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR shrinks the flash footprint of the ostest and dd test utilities to keep the 128 KiB G431 boards linking alongside apache/nuttx#21491.

This is entirely about flash size, not behaviour. The math32 changes in apache/nuttx#21491 replace constant-divisor 64-bit divisions with inline multiply-shift magic, which is a performance win but grows the image by ~256 bytes on 32-bit targets. b-g431b-esc1 and nucleo-g431kb already have only 127/55 bytes of flash free on master, so #21491 pushes them over the edge (the Linux (arm-stm32l-u-g) CI job reports region 'flash' overflowed by 132 bytes and by 188 bytes). To make room without touching the boards' configuration, this PR frees flash in the test utilities:

  1. Narrow the wdog delay math to 32 bits (testing/ostest/wdog.c): every delay in the test stays below 2^32 ns, so keeping the division and modulo 32-bit avoids pulling the 64-bit division library into the image.

  2. Compute the dd copy throughput with integer arithmetic (system/dd/dd_main.c): the throughput was computed in double, which pulls the whole soft-float cluster (__aeabi_dadd and friends, ~2 KiB) into the image. Integer arithmetic -- (total * USEC_PER_SEC / 1024) / elapsed, with the division by 1024 a shift -- keeps one 64-bit division against the division library the image already contains and drops the soft-float cluster.

Measured on nucleo-g431kb:nsh, the image shrinks by 2052 bytes (128536 -> 126484), leaving headroom over the 188-byte shortfall; the same two commits clear b-g431b-esc1:nsh (132 bytes).

The 64-bit division library is still linked after this PR (the unpatched gmtime/printf sites keep it); removing it entirely is a separate, larger change and is deliberately out of scope here.

Impact

  • User impact: none beyond the test utilities. dd prints its KB/s line with integer rounding (off by at most ~1 KB/s versus the old double math) and ostest's wdog timings are unchanged (the delays fit in 32 bits).
  • Build: no CONFIG_* change, no build-system change, no new header.
  • Hardware: targets the small-flash STM32G4 boards; no functional change on any other target.
  • Documentation: none needed.
  • Security: no security impact.
  • Compatibility: dd's output format is unchanged.

Testing

  • Host: Ubuntu 22.04 x86-64, arm-none-eabi-gcc 10.3.1.
  • Board/Configuration: b-g431b-esc1:nsh (Make), nucleo-g431kb:nsh (CMake).
  • Build: clean on both, no new warnings.
  • Size (nucleo-g431kb:nsh, text+data): 128536 -> 126484, -2052 B.
$ arm-none-eabi-size build/nuttx   # after
  125548    936   8784  135268  21064  build/nuttx
  • Run: qemu-armv7a boots; ostest exits 0 (wdog, spinlock and POSIX timer cases pass); dd prints a KB/s line consistent with the integer formula. No real G431 hardware available -- the run is QEMU only.
  • tools/checkpatch.sh: passes on both commits.

wdtest_delay() divided the 64-bit clock_t delay by 1000 and
wdog_test_thread() computed "rand() % rand_ns" in 64 bits, so wdog.c
held four __aeabi_ldivmod libcalls.  Every delay in this test is below
2^32 ns (wdtest_once passes at most 1e6 ns, wdtest_recursive reaches
times * delay_ns = 1e8, and rand_ns is the 12345 constant), so the
narrowing casts are value-preserving and the divisions become native
32-bit operations instead of library calls.

These were the last signed 64-bit division call sites in the
b-g431b-esc1:nsh image; with them gone the __aeabi_ldivmod and
__aeabi_ldiv0 members are no longer pulled in at all.

Evidence (b-g431b-esc1:nsh, Make, arm-none-eabi-gcc 13.2.1, LTO_FULL):
__aeabi_ldivmod call sites 4 -> 0 and the two symbols disappear from
the map (162 B recovered); flash 127824 -> 127620 B, and nucleo-g431kb:nsh (CMake) 127880 ->
127680 B.  The two unsigned
call sites in dd and the spinlock test still hold __udivmoddi4.

Assisted-By: mimo-v2.6-pro
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Fix-Point please fix the style issue.

cederom
cederom previously approved these changes Nov 12, 2026
@cederom

cederom commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

plz fix the issues reported by ci :-)

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Fix-Point please fix compiler warning

Comment thread system/dd/dd_main.c Resolved
The copy throughput in dd_main.c is computed in double, which pulls the
whole soft-float cluster (__aeabi_dadd and friends, ~2 KiB) into the
image.  Compute it in integer arithmetic instead: the divisor is split
so the division by 1024 becomes a shift, keeping one 64-bit division
against the division library the image already contains.

Measured on nucleo-g431kb:nsh (arm-none-eabi-gcc): the dd_main station
drops from 2 KiB of soft-float calls to none, and together with the
wdog narrowing the image shrinks by 2052 bytes (128536 -> 126484),
enough to keep the 128 KiB G431 boards linkable again.

Assisted-By: mimo-v2.6-pro
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit fixed the nxstyle.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
@xiaoxiang781216
xiaoxiang781216 merged commit 7737ccc into apache:master Nov 14, 2026
95 of 115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants