Skip to content

Modem CMUX: Optimize away work buf #93454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bjarki-andreasen
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen commented Jul 21, 2025

Work towards removing global buffer sizes for modem modules.

Related PRs: #93441

The cmux work buffer, originally intended as a simple optimization
for receiving data in small chunks rather than 1 byte at a time from
through the modem_pipe_receive() API, is now being used as a global
baseline for the sizes of receive buffers.

This is an issue given this means the work buffer of the CMUX
instance has grown be large enough to store a whole CMUX frame, which
is not neccesary.

An optimization to the modem_cmux module makes the work buffer itself
obsolete, as the data receive buffer (the receive_buf passed to the
modem_cmux instance) can be used as the temporary buffer to store
chunks. We simply receive the data from the pipe, to the remaining
part of the receive buffer, which will always line up with the
current frame being received. To do this trick, all we need to
ensure is that the receive buffer is large enough to store at least
MTU + the CMUX header and footer, which is already the case. To
make this super clear, the struct modem_cmux_config has been
expanded to mention these restrictions and why they are there. The
already present __ASSERTs will make sure the receive buffer is sized
appropriately.

With this change, the previously mentioned parts using the work
buffer size to determine receive buffer sizes, have been updated
to follow the MTU + constant described in the
struct modem_cmux_config.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Add entry in migration guide for 4.3 which mentions why the config
was removed and what to replace uses of the config with.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
The MTU used by CMUX was set by the config CONFIG_MODEM_CMUX_MTU.
This means that all CMUX instances must use the same MTU size.
Different CMUX instances need to be configured with an MTU that
matches the CMUX instance they are connected to.

Additionally, mechanisms outside of CMUX may be used to
negotiate an MTU size at runtime, this is not possible if
the MTU size is specified fixed at build time.

This commit refactors modem_cmux and the modem_cellular driver to
pass the MTU when the modem_cmux instance is initialized.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Copy link

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.

1 participant