Skip to content

Commit 55d0391

Browse files
DavidCozensclaude
andcommitted
fix: report a baseline-absent figure as absent, and correct the allocation comments
A key the frozen baseline predates was reported as current-minus-zero, which reads as a delta and is not one — mbedtls_peak was claiming 22,236 bytes above a baseline that has never measured it. Baseline_Load now says which keys the file carried, and the report prints "-" for the rest. The allocation comments in FreeRTOSConfig.h and mbedtls_user_config.h still described xTaskCreate on a 96 KiB heap_4 region and a runtime calloc/free pair. Both are wrong after this branch, and the code under them is what changed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 0b57e5d commit 55d0391

6 files changed

Lines changed: 30 additions & 25 deletions

File tree

app/config/FreeRTOSConfig.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2)
4040
#define configCHECK_FOR_STACK_OVERFLOW 2
4141
#define configUSE_MALLOC_FAILED_HOOK 1
42-
/* Static allocation is required by SolidSyslogFreeRtosMutex
43-
* (xSemaphoreCreateMutexStatic places the StaticSemaphore_t inside the
44-
* caller-supplied storage). The idle / timer task static-memory hooks it
45-
* pulls in are satisfied by configKERNEL_PROVIDED_STATIC_MEMORY = 1 — no
46-
* boilerplate in main.c. Dynamic allocation stays on for the lwIP tcpip /
47-
* RX tasks and the interactive / service tasks created via xTaskCreate. */
42+
/* Every task, stack and semaphore this application creates is static, and the
43+
* idle / timer static-memory hooks are satisfied by
44+
* configKERNEL_PROVIDED_STATIC_MEMORY = 1 — no boilerplate in main.c. Dynamic
45+
* allocation stays on only for lwIP's tcpip thread and mailboxes, created inside
46+
* its FreeRTOS port, which offers no static variants. */
4847
#define configSUPPORT_STATIC_ALLOCATION 1
4948
#define configSUPPORT_DYNAMIC_ALLOCATION 1
5049
#define configKERNEL_PROVIDED_STATIC_MEMORY 1

app/config/mbedtls_user_config.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,9 @@
6969
* injected Sleep callback, so MBEDTLS_TIMING_C is unused. */
7070
#undef MBEDTLS_TIMING_C
7171

72-
/* Route mbedTLS allocations through a runtime-installed calloc/free pair. By
73-
* default mbedTLS calls libc calloc/free, which on this target funnels through
74-
* newlib into the small 4 KiB syscall heap in Bdd/Targets/FreeRtos/Common/
75-
* Syscalls.c (shared with this target) — far too small for mbedTLS's
76-
* per-context allocations (IN/OUT buffers plus handshake state run ~10–20 KiB).
77-
* Enabling MBEDTLS_PLATFORM_MEMORY lets BddTargetTlsSender_MbedTls_LwipRawTcp.c
78-
* call mbedtls_platform_set_calloc_free(...) to redirect those allocations to
79-
* pvPortMalloc, which uses the 96 KiB heap_4 region — the textbook
80-
* FreeRTOS+mbedTLS integration. */
72+
/* Route mbedTLS allocations away from libc calloc/free, which on this target
73+
* funnels through newlib into a 4 KiB syscall heap — far too small for mbedTLS's
74+
* per-context allocations. Required by MBEDTLS_MEMORY_BUFFER_ALLOC_C below. */
8175
#define MBEDTLS_PLATFORM_MEMORY
8276

8377
/* mbedTLS sub-allocates from one static buffer the device hands it, rather than

app/measure/Baseline.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
/* Big enough for the handful of `key,value` lines the baseline holds. */
1313
#define BASELINE_BUFFER_SIZE 1024
1414

15-
static void Baseline_Apply(MeasureValues* out, const char* key, const char* value)
15+
static void Baseline_Apply(MeasureValues* out, bool* present, const char* key, const char* value)
1616
{
1717
for (int i = 0; i < MEASURE_KEY_COUNT; i++)
1818
{
1919
if (strcmp(key, MEASURE_KEYS[i]) == 0)
2020
{
2121
out->value[i] = (int32_t) strtol(value, NULL, 10);
22+
present[i] = true;
2223
return;
2324
}
2425
}
2526
}
2627

27-
bool Baseline_Load(MeasureValues* out)
28+
bool Baseline_Load(MeasureValues* out, bool* present)
2829
{
2930
for (int i = 0; i < MEASURE_KEY_COUNT; i++)
3031
{
3132
out->value[i] = 0;
33+
present[i] = false;
3234
}
3335

3436
static char buffer[BASELINE_BUFFER_SIZE];
@@ -58,7 +60,7 @@ bool Baseline_Load(MeasureValues* out)
5860
if (comma != NULL)
5961
{
6062
*comma = '\0';
61-
Baseline_Apply(out, line, comma + 1);
63+
Baseline_Apply(out, present, line, comma + 1);
6264
}
6365
}
6466

app/measure/Baseline.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ extern "C"
1515
* every field first, so a missing file yields an all-zero baseline and
1616
* returns false — which the report renders as "no baseline yet, commit
1717
* these absolutes". Returns true if the file was read. */
18-
bool Baseline_Load(MeasureValues* out);
18+
/* `present[i]` says whether the file actually carried MEASURE_KEYS[i]. A key a
19+
* frozen baseline predates must not be reported as a delta against zero. */
20+
bool Baseline_Load(MeasureValues* out, bool* present);
1921

2022
#ifdef __cplusplus
2123
}

app/measure/Measure.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@ bool Measure_Report(void)
6262
Measure_Current(&current);
6363

6464
MeasureValues baseline;
65-
bool haveBaseline = Baseline_Load(&baseline);
65+
bool present[MEASURE_KEY_COUNT];
66+
bool haveBaseline = Baseline_Load(&baseline, present);
6667

6768
(void) printf("[report] --- SolidSyslog cost above baseline (simulated existing application) ---\n");
6869
(void) printf("[report] key,current,baseline,used_above_baseline\n");
6970
for (int i = 0; i < MEASURE_KEY_COUNT; i++)
7071
{
7172
int32_t currentValue = current.value[i];
73+
if (haveBaseline && !present[i])
74+
{
75+
/* The frozen baseline predates this key. Reporting current-minus-zero
76+
* would look like a delta and be read as one. */
77+
(void) printf("[report] %s,%ld,-,-\n", MEASURE_KEYS[i], (long) currentValue);
78+
continue;
79+
}
7280
int32_t baselineValue = haveBaseline ? baseline.value[i] : 0;
7381
int32_t usedAbove = currentValue - baselineValue;
7482
(void) printf(

run-report.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +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,361616,345832,15784
10+
[report] flash_text,361736,345832,15904
1111
[report] flash_data,656,236,420
1212
[report] static_bss,133152,164508,-31356
1313
[report] heap_used,4440,39224,-34784
14-
[report] mbedtls_peak,22132,0,22132
14+
[report] mbedtls_peak,22236,-,-
1515
[report] stack_log,832,120,712
1616
[report] stack_service,3852,56,3796
1717
[report] --- end ---
1818
[device] ready
1919

2020
size cross-check:
2121
text data bss dec hex filename
22-
361608 664 133152 495424 78f40 /w/build/baseline-cross/baseline.elf
22+
361728 664 133152 495544 78fb8 /w/build/baseline-cross/baseline.elf
2323

2424
--- Oracle listeners (proved before the device ran) ---
2525
OK udp 5514
@@ -29,8 +29,8 @@
2929
OK mtls 6515 — refused a client with no certificate
3030

3131
--- Collector (syslog-ng) received ---
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
32+
wire <134>1 2026-07-28T18:22:03.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-28T18:22:03+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
3434

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

0 commit comments

Comments
 (0)