From 18170ebce129dd826f00fae229f308a744033d6a Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Thu, 21 Mar 2024 16:00:07 +0200 Subject: [PATCH] modem: cmux: make work buffer size configurable A Kconfig item is added and the buffer is embedded into the modem_cmux struct. The default value is increased from 16 to 64 bytes in an effort to reduce the number of modem_pipe_receive() calls. CONFIG_MODEM_CHAT_LOG_BUFFER is renamed to CONFIG_MODEM_CHAT_LOG_BUFFER_SIZE for consistency. Signed-off-by: Tomi Fontanilles --- doc/releases/migration-guide-3.7.rst | 6 ++++++ include/zephyr/modem/cmux.h | 2 ++ subsys/modem/Kconfig | 9 +++++++-- subsys/modem/modem_chat.c | 2 +- subsys/modem/modem_cmux.c | 7 +++---- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/doc/releases/migration-guide-3.7.rst b/doc/releases/migration-guide-3.7.rst index 451e54ecfd33e4..17884b49b3baa9 100644 --- a/doc/releases/migration-guide-3.7.rst +++ b/doc/releases/migration-guide-3.7.rst @@ -188,6 +188,12 @@ LoRaWAN MCUmgr ====== +Modem +===== + +* The ``CONFIG_MODEM_CHAT_LOG_BUFFER`` Kconfig option was + renamed to :kconfig:option:`MODEM_CHAT_LOG_BUFFER_SIZE`. + Shell ===== diff --git a/include/zephyr/modem/cmux.h b/include/zephyr/modem/cmux.h index 58959d6136b969..57ee6a8505b8af 100644 --- a/include/zephyr/modem/cmux.h +++ b/include/zephyr/modem/cmux.h @@ -141,6 +141,8 @@ struct modem_cmux { uint16_t receive_buf_size; uint16_t receive_buf_len; + uint8_t work_buf[CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE]; + /* Transmit buffer */ struct ring_buf transmit_rb; struct k_mutex transmit_rb_lock; diff --git a/subsys/modem/Kconfig b/subsys/modem/Kconfig index 86168ad22c5e08..a71542a706a348 100644 --- a/subsys/modem/Kconfig +++ b/subsys/modem/Kconfig @@ -14,8 +14,8 @@ config MODEM_CHAT if MODEM_CHAT -config MODEM_CHAT_LOG_BUFFER - int "Modem chat log buffer size" +config MODEM_CHAT_LOG_BUFFER_SIZE + int "Modem chat log buffer size in bytes" default 128 endif @@ -29,6 +29,11 @@ config MODEM_CMUX if MODEM_CMUX +config MODEM_CMUX_WORK_BUFFER_SIZE + int "CMUX module work buffer size in bytes" + range 16 1500 + default 64 + module = MODEM_CMUX module-str = modem_cmux source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/modem/modem_chat.c b/subsys/modem/modem_chat.c index c689ff2e0abcd5..e2b36d19c316a1 100644 --- a/subsys/modem/modem_chat.c +++ b/subsys/modem/modem_chat.c @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(modem_chat, CONFIG_MODEM_MODULES_LOG_LEVEL); #if defined(CONFIG_LOG) && (CONFIG_MODEM_MODULES_LOG_LEVEL == LOG_LEVEL_DBG) -static char log_buffer[CONFIG_MODEM_CHAT_LOG_BUFFER]; +static char log_buffer[CONFIG_MODEM_CHAT_LOG_BUFFER_SIZE]; static void modem_chat_log_received_command(struct modem_chat *chat) { diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 6fdc1e52841c2a..3fcca3d6068afb 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -842,11 +842,10 @@ static void modem_cmux_receive_handler(struct k_work *item) { struct k_work_delayable *dwork = k_work_delayable_from_work(item); struct modem_cmux *cmux = CONTAINER_OF(dwork, struct modem_cmux, receive_work); - uint8_t buf[16]; int ret; /* Receive data from pipe */ - ret = modem_pipe_receive(cmux->pipe, buf, sizeof(buf)); + ret = modem_pipe_receive(cmux->pipe, cmux->work_buf, sizeof(cmux->work_buf)); if (ret < 1) { if (ret < 0) { LOG_ERR("Pipe receiving error: %d", ret); @@ -855,8 +854,8 @@ static void modem_cmux_receive_handler(struct k_work *item) } /* Process received data */ - for (uint16_t i = 0; i < (uint16_t)ret; i++) { - modem_cmux_process_received_byte(cmux, buf[i]); + for (int i = 0; i < ret; i++) { + modem_cmux_process_received_byte(cmux, cmux->work_buf[i]); } /* Reschedule received work */