Skip to content

drivers/serial: reduce default SERIAL_NPOLLWAITERS for DEFAULT_SMALL - #22228

Open
Swatantra-66 wants to merge 1 commit into
apache:masterfrom
Swatantra-66:fix/serial-npollwaiters-default-small
Open

Swatantra-66 wants to merge 1 commit into
apache:masterfrom
Swatantra-66:fix/serial-npollwaiters-default-small

Conversation

@Swatantra-66

@Swatantra-66 Swatantra-66 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses Issue #20414 ([HELP] Improve NuttX bloated size).

Change CONFIG_SERIAL_NPOLLWAITERS default from 4 to 2 across all configurations per review suggestion by (@xiaoxiang781216 )

Serial ports (such as console or telemetry UARTs) rarely have more than two threads simultaneously polling or selecting on the same file descriptor.

In include/nuttx/serial/serial.h, struct uart_dev_s carries an array of poll descriptor pointers:

FAR struct pollfd_s *fds[CONFIG_SERIAL_NPOLLWAITERS];

Reducing CONFIG_SERIAL_NPOLLWAITERS from 4 to 2 eliminates two pointer entries per allocated serial device:

  • 32-bit architectures (ARM Cortex-M, RISC-V 32, etc.): Saves 8 bytes of RAM per UART device instance (e.g. g_usart1dev in .data / .bss).
  • 64-bit architectures: Saves 16 bytes of RAM per UART device instance.

Code Size Impact

Measured on stm32f103-minimum:nsh (arm-none-eabi-gcc 10.3.1 -Os):

Metric Before (SERIAL_NPOLLWAITERS=4) After (SERIAL_NPOLLWAITERS=2) Delta
Flash (text) 53,719 B 53,711 B -8 B
RAM (data) 344 B 336 B -8 B
RAM (bss) 3,136 B 3,136 B 0 B
Total Size 57,199 B 57,183 B -16 B

Impact

  • Is new feature added?: No.
  • Is existing feature changed?: Yes, defaults CONFIG_SERIAL_NPOLLWAITERS to 2.
  • Impact on user: None. Targets requiring more concurrent poll waiters can explicitly set CONFIG_SERIAL_NPOLLWAITERS in their defconfig or menuconfig.
  • Impact on build: None.
  • Impact on hardware: Flash and RAM savings across all targets with serial drivers.
  • Impact on documentation: Updated Documentation/os/drivers/character/serial.rst.

Testing

Build host: Linux container (nuttx-builder) with arm-none-eabi-gcc 10.3.1.
Target board: stm32f103-minimum:nsh.

1. Style & Documentation Verification

  • nxstyle include/nuttx/serial/serial.h: PASSED (0 errors, 0 warnings).
  • Documentation/os/drivers/character/serial.rst: documentation updated and consistent.

2. Kconfig Default Verification

  • CONFIG_SERIAL_NPOLLWAITERS defaults to 2.

3. Build & Size Comparison Logs

Before (CONFIG_SERIAL_NPOLLWAITERS=4):

CP: arch/dummy/Kconfig to /repos/nuttx/arch/dummy/dummy_kconfig
CP: boards/dummy/Kconfig to /repos/nuttx/boards/dummy/dummy_kconfig
LN: platform/board to /repos/apps/platform/dummy
Register: nsh
Register: sh
LD: nuttx
CP: nuttx.bin
   text	   data	    bss	    dec	    hex	filename
  53719	    344	   3136	  57199	   df6f	nuttx

After (CONFIG_SERIAL_NPOLLWAITERS=2):

LD: nuttx
CP: nuttx.bin
   text	   data	    bss	    dec	    hex	filename
  53711	    336	   3136	  57183	   df5f	nuttx

Comment thread drivers/serial/Kconfig Resolved
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

arduino-mega2560

  • flash: .data -4 B, .text +8 B (+0.0%, 64,629 B / 262,144 B, total: 25% used)
  • sram: .data -4 B (-0.1%, 2,764 B / 8,192 B, total: 34% used)

esp32-devkitc

  • ROM: .dram0.data -8 B, .flash.text +4 B (-0.0%, 133,480 B / 4,194,272 B, total: 3% used)
  • dram0_0_seg: .dram0.data -8 B (-0.1%, 10,268 B / 180,736 B, total: 6% used)
  • irom0_0_seg: .flash.text +4 B (+0.0%, 99,140 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .data -8 B (-0.0%, 86,632 B / 4,194,304 B, total: 2% used)
  • sram: .bss -16 B, .data -8 B (-0.6%, 3,996 B / 16,384 B, total: 24% used)

mps2-an500-citest

  • flash: .data -8 B, .text -8 B (-0.0%, 247,304 B / 4,194,304 B, total: 6% used)
  • sram1: .data -8 B (-0.0%, 16,300 B / 16,777,216 B, total: 0% used)

mps2-an500-citest-protected

  • flash: .data -8 B, .text -8 B (-0.0%, 116,448 B / 4,194,304 B, total: 3% used)
  • sram1: .data -8 B (-0.1%, 8,368 B / 16,777,216 B, total: 0% used)

qemu-armv8a

  • Code: .text.uart_poll +12 B, .text.uart_poll_notify -8 B (+0.0%, 377,636 B)
  • Data: .data.g_uart1port -16 B (-0.0%, 78,241 B)

rx65n-rsk2mb

  • RAM: .data -8 B (-0.1%, 6,920 B / 262,144 B, total: 3% used)

s698pm-dkit

  • Data: .data -32 B (-0.3%, 12,128 B)

stm32-nucleo-f103rb

  • flash: .data -8 B, .text -8 B (-0.0%, 35,080 B / 131,072 B, total: 27% used)
  • sram: .data -8 B (-0.3%, 2,500 B / 20,480 B, total: 12% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@Swatantra-66
Swatantra-66 force-pushed the fix/serial-npollwaiters-default-small branch from fd59245 to 747c4b3 Compare November 24, 2026 07:18
GUIDINGLI
GUIDINGLI previously approved these changes Nov 24, 2026
jerpelea
jerpelea previously approved these changes Nov 24, 2026
Change CONFIG_SERIAL_NPOLLWAITERS default from 4 to 2 across all
configurations. Most serial applications only poll stdin for POLLIN
and do not require 4 simultaneous poll waiter slots. Reducing
CONFIG_SERIAL_NPOLLWAITERS from 4 to 2 eliminates two pollfd pointer
entries from struct uart_dev_s, saving 8 bytes of RAM per allocated
serial port on 32-bit architectures (16 bytes on 64-bit architectures),
and 16 bytes total on stm32f103-minimum:nsh.

Also refresh existing board defconfigs where CONFIG_SERIAL_NPOLLWAITERS=2
was explicitly set to avoid defconfig normalization warnings in CI.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swatantra Yadav <maverickswatantra@gmail.com>
@Swatantra-66

Swatantra-66 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

removed redundant CONFIG_SERIAL_NPOLLWAITERS=2 from the existing board defconfigs (imx93-evk, mpfs/icicle, esp32 devkitc:wamr_wasi_debug) so defconfig normalization passes cleanly in CI without leaving uncommitted changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Board: arm64 Board: risc-v Board: xtensa Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants