Skip to content

ESP-IDF: use static queue for blockbuf#245

Merged
szczys merged 3 commits into
mainfrom
szczys/esp-idf-memory-slab
Jun 25, 2026
Merged

ESP-IDF: use static queue for blockbuf#245
szczys merged 3 commits into
mainfrom
szczys/esp-idf-memory-slab

Conversation

@szczys

@szczys szczys commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Move from using dynamic allocation in blockbuf.c to using static allocation based on FreeRTOS queues. This maps well to the memory slabs used in the Zephyr implementation.

resolves: https://github.com/golioth/firmware-issue-tracker/issues/960

szczys added 3 commits June 24, 2026 16:09
Signed-off-by: Mike Szczys <michael.szczys@canonical.com>
Expose the pouch_timeout_to_freertos_ticks() function to the port layer so
it may be used whenever we need to convert pouch_timeout_t to FreeRTOS
ticks. To avoid circular include issues, this functions uses the underlying
int32_t instead of pouch_timeout_t.

Signed-off-by: Mike Szczys <michael.szczys@canonical.com>
Use statically allocated memory handled by FreeRTOS's queue system to
allocate and free blockbuf memory. This maps closely to the memory slabs
used by the Zephyr implementation.

Signed-off-by: Mike Szczys <michael.szczys@canonical.com>
* Time
*------------------------------------------------*/

int32_t pouch_timeout_to_freertos_ticks(int32_t pouch_timeout);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some code smell here because we are not using pouch_timeout_t as the type. To do so we'd need to move other code around to avoid circular dependencies. I thought this a better solution than copying the same function into blockbuf.c. The only real risk here is if the underlying type of pouch_timeout_t changes in the future.

Comment thread port/esp_idf/blockbuf.c

BaseType_t err = xQueueSend(_blockbuf_queue_handle, &buf, 0);
/* This can only return errQUEUE_FULL which should never happen */
configASSERT(pdPASS == err);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hemmed and hawed on this. Asserting here is not fantastic, especially if assertions are turned off in the build, we won't catch this at all. I initially had a log here, but it's the only logging in the whole file which seems like overkill to register a tag just for this.

This is unlikely to happen. The only way I can think of is if someone frees a buffer that has already been freed. We wouldn't be able to put it into the queue (full) so we should fail hard on that anyway.

@szczys szczys merged commit 8475323 into main Jun 25, 2026
24 checks passed
@szczys szczys deleted the szczys/esp-idf-memory-slab branch June 25, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants