jingfei195887 opened a new pull request, #20628:
URL: https://github.com/apache/nuttx/pull/20628

   ## Summary
   
   Related to the footprint discussion in #20414. Three small, independent
   changes that let size-constrained configurations drop code that currently
   cannot be trimmed. Default (non-`DEFAULT_SMALL`) builds keep today's 
behavior.
   
   1. **mm/mm_heap: optional inline for `mm_addfreechunk()`**
      `mm_addfreechunk()` walks the free list and is inlined into every heap 
path
      (malloc, free, realloc, shrinkchunk, initialize), so each caller carries 
its
      own copy of the loop. New `CONFIG_MM_INLINE_ADDFREECHUNK`
      (`default !DEFAULT_SMALL`). When disabled, `mm_addfreechunk.c` emits one
      shared copy. The function body stays in one place (`mm.h`); the `.c` only
      instantiates it, so no code is duplicated.
   
   2. **sched: optional inline for `nxsched_add_prioritized()`**
      Inlined into all 18 call sites across the scheduler, semaphores, message
      queues and events. New `CONFIG_SCHED_INLINE_ADDPRIORITIZED`
      (`default !DEFAULT_SMALL`), same single-body pattern via
      `sched_addprioritized.c`.
   
   3. **libc: build `lib_cxx_initialize()` only for C++ init**
      Without `CONFIG_HAVE_CXXINITIALIZE` the function body compiles away, but 
the
      empty function and its call from `nxtask_startup()` remain. The file is 
now
      built only when C++ static initialization is supported; otherwise the call
      is a no-op macro.
   
   Items 1 and 2 were made inline for performance in #14144 and #14059. That
   stays the default; only `DEFAULT_SMALL` builds switch to the shared copy.
   
   ## Impact
   
   - Default builds: no functional or size change from items 1 and 2. Both new
     options default to `y` unless `CONFIG_DEFAULT_SMALL=y`.
   - `DEFAULT_SMALL` builds: one extra call/return on heap free-list insertion 
and
     on priority-list insertion, in exchange for code size.
   - No API or ABI change. `lib_cxx_initialize()` is libc-internal
     (`libs/libc/libc.h`).
   - Make and CMake are both updated.
   
   ## Testing
   
   Host: Ubuntu x86_64, arm-none-eabi-gcc 10.3.1 20210621. Rebased on master
   `734b0c5757`. All sizes below come from clean CMake builds.
   
   **Size, `stm32f103-minimum:nsh` (`DEFAULT_SMALL=y`):**
   
   | | text | data | bss |
   |---|---:|---:|---:|
   | master (734b0c5757) | 51975 | 468 | 2952 |
   | this PR | 51399 | 468 | 2952 |
   | **delta** | **-576** | 0 | 0 |
   
   Per commit, applied in order: `mm_addfreechunk` -360, 
`nxsched_add_prioritized`
   -200, `lib_cxx_initialize` -16.
   
   **Both states of each option build**, and the out-of-line symbol is present
   only when the option is off:
   
   | configuration (at this PR) | text | out-of-line symbols |
   |---|---:|---|
   | defaults (`DEFAULT_SMALL=y`, both inline options off) | 51399 | 
`mm_addfreechunk`, `nxsched_add_prioritized` |
   | `MM_INLINE_ADDFREECHUNK=y`, `SCHED_INLINE_ADDPRIORITIZED=y` | 51967 | none 
|
   | `HAVE_CXXINITIALIZE=y` | 51455 | `lib_cxx_initialize` linked |
   
   Other checks:
   - `sim:smp` with both inline options off: builds; one shared copy of each 
function.
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass. `cmake-format 
--check`: clean.
   
   **Runtime, `sim:ostest`:** run with both inline options off and, as a 
control,
   with both on (same tree). Both runs reached `waitpid_test` inside a 540 s
   timeout with no `ERROR`, assertion or panic, and went through the same tests.
   Neither configuration finished ostest in that window, so this shows no
   difference between the two configurations rather than a full ostest pass.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to