Skip to content

Commit 0b57e5d

Browse files
DavidCozensclaude
andcommitted
feat: switch to the allocate-only heap now nothing frees
heap_1 replaces heap_4. Every allocation the device makes now happens once during bring-up and is never returned, so an allocator that cannot free is sufficient — and fragmentation stops being possible rather than merely unlikely. flash_text 362,032 -> 361,616 (-416) heap_used 4,488 -> 4,440 heap_1's vPortFree is configASSERT(pv == NULL), so the invariant is enforced rather than assumed: anything that frees stops the device instead of quietly leaking. heap_peak goes with it. heap_1 only moves a pointer forward, so free memory decreases monotonically and the current figure is the high-water mark by construction — a separate peak would be the same number with a different name. mbedtls_peak stays, because buffer_alloc does free internally. What this constrains: nothing in this device may ever free, including anything built on it. Creating and destroying a netif, or deleting a task, would assert. That is a deliberate trade for a device whose allocation is all at init. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 5d0ffb8 commit 0b57e5d

4 files changed

Lines changed: 9 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ add_library(baseline_upstream OBJECT
9292
${FREERTOS_KERNEL_PATH}/timers.c
9393
${FREERTOS_KERNEL_PATH}/event_groups.c
9494
${FREERTOS_PORT_DIR}/port.c
95-
${FREERTOS_KERNEL_PATH}/portable/MemMang/heap_4.c
95+
${FREERTOS_KERNEL_PATH}/portable/MemMang/heap_1.c
9696
${lwipcore_SRCS}
9797
${lwipcore4_SRCS}
9898
${lwipapi_SRCS}

app/measure/Measure.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const char* const MEASURE_KEYS[MEASURE_KEY_COUNT] = {
3131
"flash_data",
3232
"static_bss",
3333
"heap_used",
34-
"heap_peak",
3534
"mbedtls_peak",
3635
"stack_log",
3736
"stack_service",
@@ -52,10 +51,6 @@ void Measure_Current(MeasureValues* out)
5251
out->value[MEASURE_FLASH_DATA] = (int32_t) ((uintptr_t) _edata - (uintptr_t) _sdata);
5352
out->value[MEASURE_STATIC_BSS] = (int32_t) ((uintptr_t) _ebss - (uintptr_t) _sbss);
5453
out->value[MEASURE_HEAP_USED] = (int32_t) ((uint32_t) configTOTAL_HEAP_SIZE - (uint32_t) xPortGetFreeHeapSize());
55-
/* What the device must actually provision: a TLS handshake frees working state
56-
* on completion, so the figure above understates what was needed to reach it. */
57-
out->value[MEASURE_HEAP_PEAK] =
58-
(int32_t) ((uint32_t) configTOTAL_HEAP_SIZE - (uint32_t) xPortGetMinimumEverFreeHeapSize());
5954
out->value[MEASURE_MBEDTLS_PEAK] = (int32_t) SimulatedExistingApp_MbedTlsPeak();
6055
out->value[MEASURE_STACK_LOG] = Measure_StackUsedBytes(LogTask_Handle(), LOG_TASK_STACK_WORDS);
6156
out->value[MEASURE_STACK_SERVICE] = Measure_StackUsedBytes(ServiceTask_Handle(), SERVICE_TASK_STACK_WORDS);

app/measure/Measure.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ extern "C"
1717
MEASURE_FLASH_TEXT = 0, /* .text + .rodata + init arrays (bytes) */
1818
MEASURE_FLASH_DATA, /* .data (bytes) */
1919
MEASURE_STATIC_BSS, /* .bss (bytes; includes the reserved FreeRTOS heap array) */
20-
MEASURE_HEAP_USED, /* configTOTAL_HEAP_SIZE - free heap (bytes) */
21-
MEASURE_HEAP_PEAK, /* configTOTAL_HEAP_SIZE - lowest free heap ever (bytes) */
20+
MEASURE_HEAP_USED, /* configTOTAL_HEAP_SIZE - free heap; heap_1 never frees, so also the peak */
2221
MEASURE_MBEDTLS_PEAK, /* high-water mark of the static mbedTLS buffer (bytes) */
2322
MEASURE_STACK_LOG, /* log task peak stack used (bytes) */
2423
MEASURE_STACK_SERVICE, /* service task peak stack used (bytes) */

run-report.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
[device] first record logged: yes
88
[report] --- SolidSyslog cost above baseline (simulated existing application) ---
99
[report] key,current,baseline,used_above_baseline
10-
[report] flash_text,362032,345832,16200
10+
[report] flash_text,361616,345832,15784
1111
[report] flash_data,656,236,420
12-
[report] static_bss,133172,164508,-31336
13-
[report] heap_used,4488,39224,-34736
14-
[report] heap_peak,4488,0,4488
15-
[report] mbedtls_peak,22152,0,22152
12+
[report] static_bss,133152,164508,-31356
13+
[report] heap_used,4440,39224,-34784
14+
[report] mbedtls_peak,22132,0,22132
1615
[report] stack_log,832,120,712
1716
[report] stack_service,3852,56,3796
1817
[report] --- end ---
1918
[device] ready
2019

2120
size cross-check:
2221
text data bss dec hex filename
23-
362024 664 133172 495860 790f4 /w/build/baseline-cross/baseline.elf
22+
361608 664 133152 495424 78f40 /w/build/baseline-cross/baseline.elf
2423

2524
--- Oracle listeners (proved before the device ran) ---
2625
OK udp 5514
@@ -30,8 +29,8 @@
3029
OK mtls 6515 — refused a client with no certificate
3130

3231
--- Collector (syslog-ng) received ---
33-
wire <134>1 2026-07-28T16:10:04.100000Z 10.0.2.15 solid-syslog-example - BOOT [meta sequenceId="1" sysUpTime="210"][timeQuality tzKnown="1" isSynced="0"][origin software="solid-syslog-example" swVersion="0.1.0" enterpriseId="32473" ip="10.0.2.15"][logPipeline@32473 transport="mtls" atRest="aes-256-gcm"] device started
34-
parsed PRIORITY=134 TIMESTAMP=2026-07-28T16:10:04+00:00 HOSTNAME=10.0.2.15 APP_NAME=solid-syslog-example PROCID= MSGID=BOOT STRUCTURED_DATA=[meta sequenceId="1" sysUpTime="210"][timeQuality tzKnown="1" isSynced="0"][origin software="solid-syslog-example" swVersion="0.1.0" enterpriseId="32473" ip="10.0.2.15"][logPipeline@32473 transport="mtls" atRest="aes-256-gcm"] MSG=device started
32+
wire <134>1 2026-07-28T16:17:19.100000Z 10.0.2.15 solid-syslog-example - BOOT [meta sequenceId="1" sysUpTime="210"][timeQuality tzKnown="1" isSynced="0"][origin software="solid-syslog-example" swVersion="0.1.0" enterpriseId="32473" ip="10.0.2.15"][logPipeline@32473 transport="mtls" atRest="aes-256-gcm"] device started
33+
parsed PRIORITY=134 TIMESTAMP=2026-07-28T16:17:19+00:00 HOSTNAME=10.0.2.15 APP_NAME=solid-syslog-example PROCID= MSGID=BOOT STRUCTURED_DATA=[meta sequenceId="1" sysUpTime="210"][timeQuality tzKnown="1" isSynced="0"][origin software="solid-syslog-example" swVersion="0.1.0" enterpriseId="32473" ip="10.0.2.15"][logPipeline@32473 transport="mtls" atRest="aes-256-gcm"] MSG=device started
3534

3635
--- Baseline self-check (vs measurements/Secure.csv, tolerance 64 B) ---
3736
(no committed measurements/Secure.csv yet — rerun with CAPTURE=1 to freeze it)

0 commit comments

Comments
 (0)