CV-Bowen opened a new pull request, #21968:
URL: https://github.com/apache/nuttx/pull/21968
## Summary
Two allocation helpers for rpmsg services, used by later rpmsg changes:
- `drivers/rpmsg: add a small memory pool for rpmsg services`:
`rpmsg_pool_alloc()` / `rpmsg_pool_free()` hand out fixed-size buffers
from a statically defined mempool (`MEMPOOL_DEFINE`, #21876) of
`CONFIG_RPMSG_POOL_COUNT` blocks of `CONFIG_RPMSG_POOL_SIZE` bytes.
With `RPMSG_POOL_COUNT = 0` (the default) they are `alloca()` and a
no-op, so nothing changes unless the pool is enabled.
- `drivers/rpmsg: add rpmsg_alloc_buf() and rpmsg_free_buf()`: a service
can allocate a buffer in the transport's shared memory and pass its
address to the peer instead of copying the data through messages.
The transport provides optional `alloc_buf` / `free_buf` ops;
`rpmsg_support_alloc_buf()` reports whether it does, and
`rpmsg_alloc_buf()` returns NULL when it does not.
- `drivers/rpmsg/rpmsg_virtio: implement the alloc/free buf ops` with
`virtio_malloc_buf()` / `virtio_free_buf()`.
Depends on apache/nuttx#21876 (merged).
## Impact
- New Kconfig `RPMSG_POOL_COUNT` (default 0) and `RPMSG_POOL_SIZE`
(default 64, only with a non-zero count).
- New public API in `include/nuttx/rpmsg/rpmsg.h`; two new optional ops in
the private `struct rpmsg_ops_s`. Transports that leave them NULL
(rpmsg_port, rpmsg_router) are unchanged.
- No in-tree user yet, so no behavior change.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
There is no caller in tree yet, so a test-only patch (not in this PR)
calls both APIs from `rpmsg_ping()` after the ping loop: it allocates
all `RPMSG_POOL_COUNT` pool blocks, checks `mempool_navail()`, frees
them, then calls `rpmsg_alloc_buf(rdev, 256, 8)` on the ping endpoint's
device and frees the buffer.
qemu-armv8a:rpserver + qemu-armv8a:rpproxy (rptun ivshmem), both with
`CONFIG_RPMSG_POOL_COUNT=4`; `rpmsg ping all 1 64 1 0` on each side
reaches the peer over rpmsg_virtio and over rpmsg_port_uart:
| | rpmsg pool (4 blocks) | `rpmsg_alloc_buf(256, 8)` |
|---|---|---|
| server, rpmsg_virtio (driver side) | navail 0 after 4 allocs, 4 after free
| supported, 8-byte aligned buffer, freed |
| proxy, rpmsg_virtio (device side) | same | supported, NULL: the device
side has no shared-memory heap |
| both, rpmsg_port_uart | same | not supported, NULL |
<details><summary>log</summary>
```
[server] pooltest: 4 allocated, navail=0
[server] pooltest: freed, navail=4
[server] buftest: support=1 buf=0x8000416348 aligned=1
[server] buftest: freed
[server] ping times: 1
[server] pooltest: 4 allocated, navail=0
[server] pooltest: freed, navail=4
[server] buftest: support=0 buf=0 aligned=0
[server] ping times: 1
[proxy] pooltest: 4 allocated, navail=0
[proxy] pooltest: freed, navail=4
[proxy] buftest: support=1 buf=0 aligned=0
[proxy] ping times: 1
[proxy] pooltest: 4 allocated, navail=0
[proxy] pooltest: freed, navail=4
[proxy] buftest: support=0 buf=0 aligned=0
[proxy] ping times: 1
```
</details>
Every commit builds with no warning on sim:rpserver with
`RPMSG_POOL_COUNT` 0 and 4.
No regression in rpmsg: sim:rpserver/rpproxy and
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping,
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC
disabled, which current master needs for nxinit to start nsh there; unrelated
to this change.
--
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]