jingfei195887 opened a new pull request, #22542: URL: https://github.com/apache/nuttx/pull/22542
## Summary Per-task memory pool accounting and block dumps miss static initial storage. A dynamically allocated initial chunk can also have a different size from later expansion chunks. Visit static initial storage and use the initial chunk's own size for the first queue entry. ## Impact - Corrects existing per-task accounting and block-dump output. - Public APIs, pool layouts, allocation behavior and build configuration are unchanged. - Adds documentation for the storage regions covered by memory pool diagnostics. ## Testing Local Linux x86-64 runs of `sim:nsh` use the attached `mempooldiagcheck` fixture, with both the 64-bit and 32-bit simulator configurations. It creates static, expanding, dynamically initialized, empty and interrupt-reserved pools. It checks accounting against successful allocations and compares each dumped address with the allocated or released addresses. Static fixture pools remain registered for their lifetime; dynamic pools are deinitialized. | Configuration | Baseline | This branch | | --- | --- | --- | | 64-bit, records enabled, sequence numbers enabled | 219 checks, 16 failures; 13/19 dump sections differ | 219 checks, 0 failures; all 19 dump sections match | | 32-bit, records enabled, sequence numbers disabled | 219 checks, 16 failures; 13/19 dump sections differ | 219 checks, 0 failures; all 19 dump sections match | | Backtrace depth 4, recording enabled by default | — | 219 checks, 0 failures; all 19 dump sections match | | Records disabled (`MM_BACKTRACE=-1`) | 138 checks, 0 failures | 138 checks, 0 failures; existing skip-block output retained | Each baseline/branch pair uses an identical configuration and fixture. Optimized `DEFAULT_SMALL` builds disable coverage and keep the diagnostic APIs linked through the fixture. Their text/data/bss changes are **+136 / +0 / +0 bytes**; the optimized branch also passes all 219 checks and 19 dump comparisons. `qemu-armv7r:pnsh` (protected) and `qemu-armv8a:knsh` (kernel) build with records enabled. Both user and kernel MM libraries contain the diagnostic functions. The local Make, CMake and OSTest gate passes at the submitted commit. No real hardware, protected/kernel runtime, SMP, concurrent deinitialization, or allocations from an actual interrupt were tested. Interrupt-reserved free blocks were checked. The procfs write-command interface is outside this patch. Two initial fixture setup attempts were excluded: an unavailable configuration symbol and a missing application registration file. All results below use the corrected fixture. Baseline: `f9d3eb13c3f412426a2658227f2b332e21e3a526`; tested branch: `0c145f262beaab7d0e62c80d11d197402b6c23a2`. <details> <summary>Local build and OSTest results</summary> ```text target : nuttx branch : fs/mempool-diagnostic-initial head : 0c145f262beaab7d0e62c80d11d197402b6c23a2 subject : mm/mempool: include initial blocks in diagnostic traversal commits : 1 base : f9d3eb13c3 (merge-base with upstream/master) behind : 0 commits of upstream/master nuttx : 0c145f262b apps : 0a37af9866 options : CONFIG_MM_BACKTRACE=0 host : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0 checkpatch: rc=0 signer : jingfei <[email protected]> commits missing your Signed-off-by: 0 make build: rc=0 warnings in changed files: 0 ostest: Exiting with status 0 cmake reconfigure: rc=0 cmake build: rc=0 worktree tracked changes after: 0 RESULT: PASS ``` </details> <details> <summary>Protected/kernel build results</summary> ```text qemu-armv7r:pnsh build PASS; MM library diagnostic symbols verified qemu-armv8a:knsh build PASS; MM library diagnostic symbols verified ``` </details> <details> <summary>Optimized size output: baseline, then branch</summary> ```text text data bss dec hex filename 560181 2800 17568 580549 8dbc5 nuttx text data bss dec hex filename 560317 2800 17568 580685 8dc4d nuttx ``` </details> <details> <summary>64-bit baseline runtime log</summary> ```text nsh> mempooldiagcheck MEMPOOLDIAG pointer=8 backtrace=0 CASE static_fixed TASK pool=static_fixed used=0 expected=0 bytes=0 TASK pool=static_fixed used=0 expected=4 bytes=0 FAIL per-task block count FAIL per-task byte count DIAG BEGIN static_fixed -3 DIAG EXPECT 0x401a2470 DIAG EXPECT 0x401a2420 DIAG EXPECT 0x401a23d0 DIAG EXPECT 0x401a2380 DIAG END static_fixed -3 TASK pool=static_fixed used=0 expected=3 bytes=0 FAIL per-task block count FAIL per-task byte count DIAG BEGIN static_fixed -3 DIAG EXPECT 0x401a2470 DIAG EXPECT 0x401a23d0 DIAG EXPECT 0x401a2380 DIAG END static_fixed -3 DIAG BEGIN static_fixed -4 DIAG EXPECT 0x401a2420 DIAG END static_fixed -4 TASK pool=static_fixed used=0 expected=0 bytes=0 CASE static_expand TASK pool=static_expand used=0 expected=0 bytes=0 TASK pool=static_expand used=4 expected=7 bytes=320 FAIL per-task block count FAIL per-task byte count DIAG BEGIN static_expand -3 DIAG EXPECT 0x401a25c0 DIAG EXPECT 0x401a2570 DIAG EXPECT 0x401a2520 DIAG EXPECT 0x75ed20d246f0 DIAG EXPECT 0x75ed20d246a0 DIAG EXPECT 0x75ed20d247b0 DIAG EXPECT 0x75ed20d24760 8 80 16 154 0x75ed20d246f0 8 80 16 155 0x75ed20d246a0 8 80 16 157 0x75ed20d247b0 8 80 16 158 0x75ed20d24760 DIAG END static_expand -3 TASK pool=static_expand used=4 expected=6 bytes=320 FAIL per-task block count FAIL per-task byte count DIAG BEGIN static_expand -3 DIAG EXPECT 0x401a25c0 DIAG EXPECT 0x401a2520 DIAG EXPECT 0x75ed20d246f0 DIAG EXPECT 0x75ed20d246a0 DIAG EXPECT 0x75ed20d247b0 DIAG EXPECT 0x75ed20d24760 8 80 16 154 0x75ed20d246f0 8 80 16 155 0x75ed20d246a0 8 80 16 157 0x75ed20d247b0 8 80 16 158 0x75ed20d24760 DIAG END static_expand -3 DIAG BEGIN static_expand -4 DIAG EXPECT 0x401a2570 DIAG END static_expand -4 TASK pool=static_expand used=0 expected=0 bytes=0 CASE dynamic_large TASK pool=dynamic_large used=0 expected=0 bytes=0 TASK pool=dynamic_large used=6 expected=9 bytes=480 FAIL per-task block count FAIL per-task byte count DIAG BEGIN dynamic_large -3 DIAG EXPECT 0x75ed20d24960 DIAG EXPECT 0x75ed20d24910 DIAG EXPECT 0x75ed20d248c0 DIAG EXPECT 0x75ed20d24870 DIAG EXPECT 0x75ed20d24820 DIAG EXPECT 0x75ed20d24a20 DIAG EXPECT 0x75ed20d249d0 DIAG EXPECT 0x75ed20d24ae0 DIAG EXPECT 0x75ed20d24a90 8 80 16 160 0x75ed20d24960 8 80 16 161 0x75ed20d24910 8 80 16 166 0x75ed20d24a20 8 80 16 167 0x75ed20d249d0 8 80 16 169 0x75ed20d24ae0 8 80 16 170 0x75ed20d24a90 DIAG END dynamic_large -3 TASK pool=dynamic_large used=5 expected=8 bytes=400 FAIL per-task block count FAIL per-task byte count DIAG BEGIN dynamic_large -3 DIAG EXPECT 0x75ed20d24960 DIAG EXPECT 0x75ed20d248c0 DIAG EXPECT 0x75ed20d24870 DIAG EXPECT 0x75ed20d24820 DIAG EXPECT 0x75ed20d24a20 DIAG EXPECT 0x75ed20d249d0 DIAG EXPECT 0x75ed20d24ae0 DIAG EXPECT 0x75ed20d24a90 8 80 16 160 0x75ed20d24960 8 80 16 166 0x75ed20d24a20 8 80 16 167 0x75ed20d249d0 8 80 16 169 0x75ed20d24ae0 8 80 16 170 0x75ed20d24a90 DIAG END dynamic_large -3 DIAG BEGIN dynamic_large -4 DIAG EXPECT 0x75ed20d24910 80 16 0x75ed20d24910 DIAG END dynamic_large -4 TASK pool=dynamic_large used=0 expected=0 bytes=0 CASE dynamic_small TASK pool=dynamic_small used=0 expected=0 bytes=0 TASK pool=dynamic_small used=7 expected=7 bytes=560 DIAG BEGIN dynamic_small -3 DIAG EXPECT 0x75ed20d24870 DIAG EXPECT 0x75ed20d24820 DIAG EXPECT 0x75ed20d24a20 DIAG EXPECT 0x75ed20d249d0 DIAG EXPECT 0x75ed20d24980 DIAG EXPECT 0x75ed20d24930 DIAG EXPECT 0x75ed20d248e0 8 80 16 172 0x75ed20d24870 8 80 16 173 0x75ed20d24820 0 80 16 171 0x75ed20d247d0 101058054 80 16434041037028460038 0x75ed20d24780 117901063 80 16506381209866536711 0x75ed20d24730 8 80 16 175 0x75ed20d24a20 8 80 16 176 0x75ed20d249d0 8 80 16 177 0x75ed20d24980 8 80 16 178 0x75ed20d24930 8 80 16 179 0x75ed20d248e0 DIAG END dynamic_small -3 TASK pool=dynamic_small used=6 expected=6 bytes=480 DIAG BEGIN dynamic_small -3 DIAG EXPECT 0x75ed20d24870 DIAG EXPECT 0x75ed20d24a20 DIAG EXPECT 0x75ed20d249d0 DIAG EXPECT 0x75ed20d24980 DIAG EXPECT 0x75ed20d24930 DIAG EXPECT 0x75ed20d248e0 8 80 16 172 0x75ed20d24870 0 80 16 171 0x75ed20d247d0 101058054 80 16434041037028460038 0x75ed20d24780 117901063 80 16506381209866536711 0x75ed20d24730 8 80 16 175 0x75ed20d24a20 8 80 16 176 0x75ed20d249d0 8 80 16 177 0x75ed20d24980 8 80 16 178 0x75ed20d24930 8 80 16 179 0x75ed20d248e0 DIAG END dynamic_small -3 DIAG BEGIN dynamic_small -4 DIAG EXPECT 0x75ed20d24820 80 16 0x75ed20d24820 DIAG END dynamic_small -4 TASK pool=dynamic_small used=0 expected=0 bytes=0 CASE expand_only TASK pool=expand_only used=0 expected=0 bytes=0 TASK pool=expand_only used=6 expected=6 bytes=480 DIAG BEGIN expand_only -3 DIAG EXPECT 0x75ed20d248c0 DIAG EXPECT 0x75ed20d24870 DIAG EXPECT 0x75ed20d24820 DIAG EXPECT 0x75ed20d249d0 DIAG EXPECT 0x75ed20d24980 DIAG EXPECT 0x75ed20d24930 8 80 16 181 0x75ed20d248c0 8 80 16 182 0x75ed20d24870 8 80 16 183 0x75ed20d24820 8 80 16 185 0x75ed20d249d0 8 80 16 186 0x75ed20d24980 8 80 16 187 0x75ed20d24930 DIAG END expand_only -3 TASK pool=expand_only used=5 expected=5 bytes=400 DIAG BEGIN expand_only -3 DIAG EXPECT 0x75ed20d248c0 DIAG EXPECT 0x75ed20d24820 DIAG EXPECT 0x75ed20d249d0 DIAG EXPECT 0x75ed20d24980 DIAG EXPECT 0x75ed20d24930 8 80 16 181 0x75ed20d248c0 8 80 16 183 0x75ed20d24820 8 80 16 185 0x75ed20d249d0 8 80 16 186 0x75ed20d24980 8 80 16 187 0x75ed20d24930 DIAG END expand_only -3 DIAG BEGIN expand_only -4 DIAG EXPECT 0x75ed20d24870 80 16 0x75ed20d24870 DIAG END expand_only -4 TASK pool=expand_only used=0 expected=0 bytes=0 CASE empty TASK pool=empty used=0 expected=0 bytes=0 TASK pool=empty used=0 expected=0 bytes=0 DIAG BEGIN empty -3 DIAG END empty -3 TASK pool=empty used=0 expected=0 bytes=0 CASE irq_reserved TASK pool=irq_reserved used=0 expected=0 bytes=0 TASK pool=irq_reserved used=4 expected=7 bytes=320 FAIL per-task block count FAIL per-task byte count DIAG BEGIN irq_reserved -3 DIAG EXPECT 0x401a2de0 DIAG EXPECT 0x401a2d90 DIAG EXPECT 0x401a2d40 DIAG EXPECT 0x75ed20d24930 DIAG EXPECT 0x75ed20d248e0 DIAG EXPECT 0x75ed20d249f0 DIAG EXPECT 0x75ed20d249a0 8 80 16 193 0x75ed20d24930 8 80 16 194 0x75ed20d248e0 8 80 16 196 0x75ed20d249f0 8 80 16 197 0x75ed20d249a0 DIAG END irq_reserved -3 TASK pool=irq_reserved used=4 expected=6 bytes=320 FAIL per-task block count FAIL per-task byte count DIAG BEGIN irq_reserved -3 DIAG EXPECT 0x401a2de0 DIAG EXPECT 0x401a2d40 DIAG EXPECT 0x75ed20d24930 DIAG EXPECT 0x75ed20d248e0 DIAG EXPECT 0x75ed20d249f0 DIAG EXPECT 0x75ed20d249a0 8 80 16 193 0x75ed20d24930 8 80 16 194 0x75ed20d248e0 8 80 16 196 0x75ed20d249f0 8 80 16 197 0x75ed20d249a0 DIAG END irq_reserved -3 DIAG BEGIN irq_reserved -4 DIAG EXPECT 0x401a2d90 DIAG EXPECT 0x75ed20d24820 DIAG EXPECT 0x75ed20d24870 80 16 0x75ed20d24870 80 16 0x75ed20d24820 DIAG END irq_reserved -4 TASK pool=irq_reserved used=0 expected=0 bytes=0 MEMPOOLDIAG RESULT checks=219 failures=16 nsh> echo status=$? status=1 nsh> poweroff ``` </details> <details> <summary>64-bit branch runtime log</summary> ```text nsh> mempooldiagcheck MEMPOOLDIAG pointer=8 backtrace=0 CASE static_fixed TASK pool=static_fixed used=0 expected=0 bytes=0 TASK pool=static_fixed used=4 expected=4 bytes=320 DIAG BEGIN static_fixed -3 DIAG EXPECT 0x401a2490 DIAG EXPECT 0x401a2440 DIAG EXPECT 0x401a23f0 DIAG EXPECT 0x401a23a0 8 80 16 146 0x401a2490 8 80 16 147 0x401a2440 8 80 16 148 0x401a23f0 8 80 16 149 0x401a23a0 DIAG END static_fixed -3 TASK pool=static_fixed used=3 expected=3 bytes=240 DIAG BEGIN static_fixed -3 DIAG EXPECT 0x401a2490 DIAG EXPECT 0x401a23f0 DIAG EXPECT 0x401a23a0 8 80 16 146 0x401a2490 8 80 16 148 0x401a23f0 8 80 16 149 0x401a23a0 DIAG END static_fixed -3 DIAG BEGIN static_fixed -4 DIAG EXPECT 0x401a2440 80 16 0x401a2440 DIAG END static_fixed -4 TASK pool=static_fixed used=0 expected=0 bytes=0 CASE static_expand TASK pool=static_expand used=0 expected=0 bytes=0 TASK pool=static_expand used=7 expected=7 bytes=560 DIAG BEGIN static_expand -3 DIAG EXPECT 0x401a25e0 DIAG EXPECT 0x401a2590 DIAG EXPECT 0x401a2540 DIAG EXPECT 0x7c21e13246f0 DIAG EXPECT 0x7c21e13246a0 DIAG EXPECT 0x7c21e13247b0 DIAG EXPECT 0x7c21e1324760 8 80 16 150 0x401a25e0 8 80 16 151 0x401a2590 8 80 16 152 0x401a2540 8 80 16 154 0x7c21e13246f0 8 80 16 155 0x7c21e13246a0 8 80 16 157 0x7c21e13247b0 8 80 16 158 0x7c21e1324760 DIAG END static_expand -3 TASK pool=static_expand used=6 expected=6 bytes=480 DIAG BEGIN static_expand -3 DIAG EXPECT 0x401a25e0 DIAG EXPECT 0x401a2540 DIAG EXPECT 0x7c21e13246f0 DIAG EXPECT 0x7c21e13246a0 DIAG EXPECT 0x7c21e13247b0 DIAG EXPECT 0x7c21e1324760 8 80 16 150 0x401a25e0 8 80 16 152 0x401a2540 8 80 16 154 0x7c21e13246f0 8 80 16 155 0x7c21e13246a0 8 80 16 157 0x7c21e13247b0 8 80 16 158 0x7c21e1324760 DIAG END static_expand -3 DIAG BEGIN static_expand -4 DIAG EXPECT 0x401a2590 80 16 0x401a2590 DIAG END static_expand -4 TASK pool=static_expand used=0 expected=0 bytes=0 CASE dynamic_large TASK pool=dynamic_large used=0 expected=0 bytes=0 TASK pool=dynamic_large used=9 expected=9 bytes=720 DIAG BEGIN dynamic_large -3 DIAG EXPECT 0x7c21e1324960 DIAG EXPECT 0x7c21e1324910 DIAG EXPECT 0x7c21e13248c0 DIAG EXPECT 0x7c21e1324870 DIAG EXPECT 0x7c21e1324820 DIAG EXPECT 0x7c21e1324a20 DIAG EXPECT 0x7c21e13249d0 DIAG EXPECT 0x7c21e1324ae0 DIAG EXPECT 0x7c21e1324a90 8 80 16 160 0x7c21e1324960 8 80 16 161 0x7c21e1324910 8 80 16 162 0x7c21e13248c0 8 80 16 163 0x7c21e1324870 8 80 16 164 0x7c21e1324820 8 80 16 166 0x7c21e1324a20 8 80 16 167 0x7c21e13249d0 8 80 16 169 0x7c21e1324ae0 8 80 16 170 0x7c21e1324a90 DIAG END dynamic_large -3 TASK pool=dynamic_large used=8 expected=8 bytes=640 DIAG BEGIN dynamic_large -3 DIAG EXPECT 0x7c21e1324960 DIAG EXPECT 0x7c21e13248c0 DIAG EXPECT 0x7c21e1324870 DIAG EXPECT 0x7c21e1324820 DIAG EXPECT 0x7c21e1324a20 DIAG EXPECT 0x7c21e13249d0 DIAG EXPECT 0x7c21e1324ae0 DIAG EXPECT 0x7c21e1324a90 8 80 16 160 0x7c21e1324960 8 80 16 162 0x7c21e13248c0 8 80 16 163 0x7c21e1324870 8 80 16 164 0x7c21e1324820 8 80 16 166 0x7c21e1324a20 8 80 16 167 0x7c21e13249d0 8 80 16 169 0x7c21e1324ae0 8 80 16 170 0x7c21e1324a90 DIAG END dynamic_large -3 DIAG BEGIN dynamic_large -4 DIAG EXPECT 0x7c21e1324910 80 16 0x7c21e1324910 DIAG END dynamic_large -4 TASK pool=dynamic_large used=0 expected=0 bytes=0 CASE dynamic_small TASK pool=dynamic_small used=0 expected=0 bytes=0 TASK pool=dynamic_small used=7 expected=7 bytes=560 DIAG BEGIN dynamic_small -3 DIAG EXPECT 0x7c21e1324870 DIAG EXPECT 0x7c21e1324820 DIAG EXPECT 0x7c21e1324a20 DIAG EXPECT 0x7c21e13249d0 DIAG EXPECT 0x7c21e1324980 DIAG EXPECT 0x7c21e1324930 DIAG EXPECT 0x7c21e13248e0 8 80 16 172 0x7c21e1324870 8 80 16 173 0x7c21e1324820 8 80 16 175 0x7c21e1324a20 8 80 16 176 0x7c21e13249d0 8 80 16 177 0x7c21e1324980 8 80 16 178 0x7c21e1324930 8 80 16 179 0x7c21e13248e0 DIAG END dynamic_small -3 TASK pool=dynamic_small used=6 expected=6 bytes=480 DIAG BEGIN dynamic_small -3 DIAG EXPECT 0x7c21e1324870 DIAG EXPECT 0x7c21e1324a20 DIAG EXPECT 0x7c21e13249d0 DIAG EXPECT 0x7c21e1324980 DIAG EXPECT 0x7c21e1324930 DIAG EXPECT 0x7c21e13248e0 8 80 16 172 0x7c21e1324870 8 80 16 175 0x7c21e1324a20 8 80 16 176 0x7c21e13249d0 8 80 16 177 0x7c21e1324980 8 80 16 178 0x7c21e1324930 8 80 16 179 0x7c21e13248e0 DIAG END dynamic_small -3 DIAG BEGIN dynamic_small -4 DIAG EXPECT 0x7c21e1324820 80 16 0x7c21e1324820 DIAG END dynamic_small -4 TASK pool=dynamic_small used=0 expected=0 bytes=0 CASE expand_only TASK pool=expand_only used=0 expected=0 bytes=0 TASK pool=expand_only used=6 expected=6 bytes=480 DIAG BEGIN expand_only -3 DIAG EXPECT 0x7c21e13248c0 DIAG EXPECT 0x7c21e1324870 DIAG EXPECT 0x7c21e1324820 DIAG EXPECT 0x7c21e13249d0 DIAG EXPECT 0x7c21e1324980 DIAG EXPECT 0x7c21e1324930 8 80 16 181 0x7c21e13248c0 8 80 16 182 0x7c21e1324870 8 80 16 183 0x7c21e1324820 8 80 16 185 0x7c21e13249d0 8 80 16 186 0x7c21e1324980 8 80 16 187 0x7c21e1324930 DIAG END expand_only -3 TASK pool=expand_only used=5 expected=5 bytes=400 DIAG BEGIN expand_only -3 DIAG EXPECT 0x7c21e13248c0 DIAG EXPECT 0x7c21e1324820 DIAG EXPECT 0x7c21e13249d0 DIAG EXPECT 0x7c21e1324980 DIAG EXPECT 0x7c21e1324930 8 80 16 181 0x7c21e13248c0 8 80 16 183 0x7c21e1324820 8 80 16 185 0x7c21e13249d0 8 80 16 186 0x7c21e1324980 8 80 16 187 0x7c21e1324930 DIAG END expand_only -3 DIAG BEGIN expand_only -4 DIAG EXPECT 0x7c21e1324870 80 16 0x7c21e1324870 DIAG END expand_only -4 TASK pool=expand_only used=0 expected=0 bytes=0 CASE empty TASK pool=empty used=0 expected=0 bytes=0 TASK pool=empty used=0 expected=0 bytes=0 DIAG BEGIN empty -3 DIAG END empty -3 TASK pool=empty used=0 expected=0 bytes=0 CASE irq_reserved TASK pool=irq_reserved used=0 expected=0 bytes=0 TASK pool=irq_reserved used=7 expected=7 bytes=560 DIAG BEGIN irq_reserved -3 DIAG EXPECT 0x401a2e00 DIAG EXPECT 0x401a2db0 DIAG EXPECT 0x401a2d60 DIAG EXPECT 0x7c21e1324930 DIAG EXPECT 0x7c21e13248e0 DIAG EXPECT 0x7c21e13249f0 DIAG EXPECT 0x7c21e13249a0 8 80 16 189 0x401a2e00 8 80 16 190 0x401a2db0 8 80 16 191 0x401a2d60 8 80 16 193 0x7c21e1324930 8 80 16 194 0x7c21e13248e0 8 80 16 196 0x7c21e13249f0 8 80 16 197 0x7c21e13249a0 DIAG END irq_reserved -3 TASK pool=irq_reserved used=6 expected=6 bytes=480 DIAG BEGIN irq_reserved -3 DIAG EXPECT 0x401a2e00 DIAG EXPECT 0x401a2d60 DIAG EXPECT 0x7c21e1324930 DIAG EXPECT 0x7c21e13248e0 DIAG EXPECT 0x7c21e13249f0 DIAG EXPECT 0x7c21e13249a0 8 80 16 189 0x401a2e00 8 80 16 191 0x401a2d60 8 80 16 193 0x7c21e1324930 8 80 16 194 0x7c21e13248e0 8 80 16 196 0x7c21e13249f0 8 80 16 197 0x7c21e13249a0 DIAG END irq_reserved -3 DIAG BEGIN irq_reserved -4 DIAG EXPECT 0x401a2db0 DIAG EXPECT 0x7c21e1324820 DIAG EXPECT 0x7c21e1324870 80 16 0x7c21e1324870 80 16 0x7c21e1324820 80 16 0x401a2db0 DIAG END irq_reserved -4 TASK pool=irq_reserved used=0 expected=0 bytes=0 MEMPOOLDIAG RESULT checks=219 failures=0 nsh> echo status=$? status=0 nsh> poweroff ``` </details> <details> <summary>Serial runtime matrix results</summary> ```text baseline-final64 rev f9d3eb13c3f arch/arm/pp502x: Finish start-up in the common no-MMU entry. build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/baseline-final64/run.log {"completed": true, "failed_sections": 13, "checks": 219, "failures": 16} static_fixed -3 expected 4 actual 0 static_fixed -3 expected 3 actual 0 static_fixed -4 expected 1 actual 0 static_expand -3 expected 7 actual 4 static_expand -3 expected 6 actual 4 static_expand -4 expected 1 actual 0 dynamic_large -3 expected 9 actual 6 dynamic_large -3 expected 8 actual 5 dynamic_small -3 expected 7 actual 10 dynamic_small -3 expected 6 actual 9 irq_reserved -3 expected 7 actual 4 irq_reserved -3 expected 6 actual 4 irq_reserved -4 expected 3 actual 2 branch64 rev 0c145f262be mm/mempool: include initial blocks in diagnostic traversal build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/branch64/run.log {"completed": true, "failed_sections": 0, "checks": 219, "failures": 0} baseline32 rev f9d3eb13c3f arch/arm/pp502x: Finish start-up in the common no-MMU entry. build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/baseline32/run.log {"completed": true, "failed_sections": 13, "checks": 219, "failures": 16} static_fixed -3 expected 4 actual 0 static_fixed -3 expected 3 actual 0 static_fixed -4 expected 1 actual 0 static_expand -3 expected 7 actual 4 static_expand -3 expected 6 actual 4 static_expand -4 expected 1 actual 0 dynamic_large -3 expected 9 actual 6 dynamic_large -3 expected 8 actual 5 dynamic_small -3 expected 7 actual 10 dynamic_small -3 expected 6 actual 9 irq_reserved -3 expected 7 actual 4 irq_reserved -3 expected 6 actual 4 irq_reserved -4 expected 3 actual 2 branch32 rev 0c145f262be mm/mempool: include initial blocks in diagnostic traversal build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/branch32/run.log {"completed": true, "failed_sections": 0, "checks": 219, "failures": 0} branch-backtrace rev 0c145f262be mm/mempool: include initial blocks in diagnostic traversal build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/branch-backtrace/run.log {"completed": true, "failed_sections": 0, "checks": 219, "failures": 0} baseline-disabled rev f9d3eb13c3f arch/arm/pp502x: Finish start-up in the common no-MMU entry. build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/baseline-disabled/run.log {"completed": true, "failed_sections": 0, "checks": 138, "failures": 0} branch-disabled rev 0c145f262be mm/mempool: include initial blocks in diagnostic traversal build rc=0 run rc=0 log=/home/mi/test/nuttx_apache/fs-upstream/pr-mempool-diagnostics/branch-disabled/run.log {"completed": true, "failed_sections": 0, "checks": 138, "failures": 0} MATRIX PASS: baseline differences observed; branch checks and dump sets pass ``` </details> The fixture can be placed in `apps/examples/mempooldiagcheck/`. Enable `CONFIG_EXAMPLES_MEMPOOLDIAGCHECK=y` and run `mempooldiagcheck` from NSH. <details> <summary>Fixture: Kconfig</summary> ```text config EXAMPLES_MEMPOOLDIAGCHECK tristate "Mempool diagnostic traversal regression" default n ``` </details> <details> <summary>Fixture: Make.defs</summary> ```make ifneq ($(CONFIG_EXAMPLES_MEMPOOLDIAGCHECK),) CONFIGURED_APPS += $(APPDIR)/examples/mempooldiagcheck endif ``` </details> <details> <summary>Fixture: Makefile</summary> ```make include $(APPDIR)/Make.defs PROGNAME = mempooldiagcheck PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = 8192 MODULE = $(CONFIG_EXAMPLES_MEMPOOLDIAGCHECK) MAINSRC = mempooldiagcheck_main.c include $(APPDIR)/Application.mk ``` </details> <details> <summary>Fixture: mempooldiagcheck_main.c</summary> ```c /**************************************************************************** * apps/examples/mempooldiagcheck/mempooldiagcheck_main.c * * SPDX-License-Identifier: Apache-2.0 * ****************************************************************************/ /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> #include <limits.h> #include <malloc.h> #include <stdbool.h> #include <stdio.h> #include <string.h> #include <syslog.h> #include <unistd.h> #include <nuttx/mm/mempool.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #define BLOCKSIZE 64 #define REALSIZE MEMPOOL_REALBLOCKSIZE(BLOCKSIZE) /**************************************************************************** * Private Types ****************************************************************************/ struct diag_storage_s { char buffer[ALIGN_UP(5 * REALSIZE + MEMPOOL_HEADER_SIZE, MM_ALIGN)]; }; /**************************************************************************** * Private Data ****************************************************************************/ static unsigned int g_checks; static unsigned int g_failures; static struct mempool_s g_pools[7]; static struct diag_storage_s g_storage[7] aligned_data(MM_ALIGN); static int g_index; /**************************************************************************** * Private Functions ****************************************************************************/ static void check(bool ok, FAR const char *name) { g_checks++; if (!ok) { g_failures++; printf("FAIL %s\n", name); } } static void counts(FAR struct mempool_s *pool, int used, int freecount) { struct malltask task = { .pid = gettid(), #if CONFIG_MM_BACKTRACE >= 0 .seqmin = 0, .seqmax = ULONG_MAX, #endif }; struct mallinfo_task info; #if CONFIG_MM_BACKTRACE >= 0 info = mempool_info_task(pool, &task); printf("TASK pool=%s used=%d expected=%d bytes=%d\n", pool->name, info.aordblks, used, info.uordblks); check(info.aordblks == used, "per-task block count"); check(info.uordblks == used * REALSIZE, "per-task byte count"); task.pid = INT_MAX; info = mempool_info_task(pool, &task); check(info.aordblks == 0 && info.uordblks == 0, "unrelated task"); #endif task.pid = PID_MM_ALLOC; info = mempool_info_task(pool, &task); check(info.aordblks == used, "aggregate allocated count"); task.pid = PID_MM_FREE; info = mempool_info_task(pool, &task); check(info.aordblks == freecount, "aggregate free count"); } static void dump(FAR struct mempool_s *pool, int pid, FAR void **blocks, int count, int released) { struct mm_memdump_s request = { .pid = pid, #if CONFIG_MM_BACKTRACE >= 0 .seqmin = 0, .seqmax = ULONG_MAX, #endif }; int i; syslog(LOG_INFO, "DIAG BEGIN %s %d\n", pool->name, pid); for (i = 0; i < count; i++) { if ((pid == PID_MM_FREE) == (i == released)) { syslog(LOG_INFO, "DIAG EXPECT %p\n", blocks[i]); } } if (pid == PID_MM_FREE) { for (i = 0; i < pool->interruptsize / REALSIZE; i++) { syslog(LOG_INFO, "DIAG EXPECT %p\n", pool->ibase + i * REALSIZE); } } mempool_memdump(pool, &request); syslog(LOG_INFO, "DIAG END %s %d\n", pool->name, pid); } static void exercise(FAR const char *name, bool is_static, int initial, int expansion, int allocated, int interrupt) { FAR struct mempool_s *pool = &g_pools[g_index]; FAR void *blocks[10]; int actual = 0; int i; printf("CASE %s\n", name); pool->name = name; pool->blocksize = BLOCKSIZE; pool->initialsize = initial * REALSIZE + MEMPOOL_HEADER_SIZE; pool->expandsize = expansion * REALSIZE + MEMPOOL_HEADER_SIZE; pool->interruptsize = interrupt * REALSIZE; if (is_static) { memset(g_storage[g_index].buffer, 0, sizeof(g_storage[g_index].buffer)); pool->initialbase = g_storage[g_index].buffer; } check(mempool_init(pool) == 0, "initialize pool"); counts(pool, 0, initial + interrupt); for (i = 0; i < allocated; i++) { blocks[i] = mempool_allocate(pool, 0); check(blocks[i] != NULL, "allocate block"); if (blocks[i] == NULL) { break; } memset(blocks[i], i + 1, BLOCKSIZE); actual++; } counts(pool, actual, interrupt); dump(pool, PID_MM_ALLOC, blocks, actual, -1); if (actual > 1) { mempool_release(pool, blocks[1]); counts(pool, actual - 1, 1 + interrupt); dump(pool, PID_MM_ALLOC, blocks, actual, 1); dump(pool, PID_MM_FREE, blocks, actual, 1); } for (i = 0; i < actual; i++) { if (i != 1) { check(((FAR unsigned char *)blocks[i])[0] == i + 1, "payload retained"); mempool_release(pool, blocks[i]); } } counts(pool, 0, actual + interrupt); if (!is_static) { check(mempool_deinit(pool) == 0, "deinitialize pool"); } g_index++; } /**************************************************************************** * Public Functions ****************************************************************************/ int main(int argc, FAR char *argv[]) { setlogmask(LOG_UPTO(LOG_INFO)); printf("MEMPOOLDIAG pointer=%zu backtrace=%d\n", sizeof(void *), CONFIG_MM_BACKTRACE); exercise("static_fixed", true, 4, 0, 4, 0); exercise("static_expand", true, 3, 2, 7, 0); exercise("dynamic_large", false, 5, 2, 9, 0); exercise("dynamic_small", false, 2, 5, 7, 0); exercise("expand_only", false, 0, 3, 6, 0); exercise("empty", true, 0, 0, 0, 0); exercise("irq_reserved", true, 3, 2, 7, 2); printf("MEMPOOLDIAG RESULT checks=%u failures=%u\n", g_checks, g_failures); return g_failures == 0 ? 0 : 1; } ``` </details> <details> <summary>Dump address verifier (run on the captured console log beside its config)</summary> ```python import collections import json import re import sys from pathlib import Path path = Path(sys.argv[1]) log = path.read_text(errors='replace') config = (path.parent / 'config').read_text() disabled = 'CONFIG_MM_BACKTRACE=-1\n' in config sections = [] current = None for line in log.splitlines(): if 'DIAG BEGIN ' in line: assert current is None current = {'name': line.split('DIAG BEGIN ')[1], 'expected': [], 'actual': [], 'skipped': 0} elif 'DIAG END ' in line: assert current is not None assert current['name'] == line.split('DIAG END ')[1] current['pass'] = (current['skipped'] == 1 if disabled else collections.Counter(current['actual']) == collections.Counter(current['expected'])) sections.append(current) current = None elif current is not None: pointers = re.findall(r'0x[0-9a-fA-F]+', line) if 'DIAG EXPECT ' in line: assert len(pointers) == 1, line current['expected'].append(int(pointers[0], 16)) elif 'skip block dump' in line: current['skipped'] += 1 elif pointers: current['actual'].append(int(pointers[0], 16)) assert current is None, 'Incomplete diagnostic section' result = re.search(r'MEMPOOLDIAG RESULT checks=(\d+) failures=(\d+)', log) report = {'completed': result is not None, 'sections': sections, 'failed_sections': sum(not x['pass'] for x in sections), 'checks': int(result[1]) if result else None, 'failures': int(result[2]) if result else None} (path.parent / 'diagnostic-report.json').write_text(json.dumps(report, indent=2) + '\n') print(json.dumps({k: v for k, v in report.items() if k != 'sections'})) for s in sections: if not s['pass']: print(s['name'], 'expected', len(s['expected']), 'actual', len(s['actual'])) if '--pass' in sys.argv: assert result and report['failures'] == 0 and report['failed_sections'] == 0 assert len(sections) == 19 assert 'status=0' in log ``` </details> ## PR verification Self-Check - [x] This PR introduces only one functional change. - [x] I have updated all required description fields above. - [x] My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc). - [ ] My PR is still work in progress (not ready for review). - [x] My PR is ready for review and can be safely merged into a codebase. -- 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]
