Skip to content

Commit 5d0b302

Browse files
tokangasbjarki-andreasen
authored andcommitted
[nrf fromtree] shell: Make TX mutex timeout configurable
The 50 ms TX mutex timeouts introduced in commit b0a0feb cause dropped messages when used with the shell log backend. This commit makes time timeout configurable using the CONFIG_SHELL_TX_TIMEOUT_MS Kconfig option and makes the default timeout longer when shell log backend is enabled. Link: #90215 Signed-off-by: Tommi Kangas <[email protected]> (cherry picked from commit 941dcd3)
1 parent 231cc29 commit 5d0b302

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

subsys/shell/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,16 @@ config SHELL_CUSTOM_HEADER
326326
extension of the shell APIs at the macro level. Please use cautiously!
327327
The internal shell API may change in future releases.
328328

329+
config SHELL_TX_TIMEOUT_MS
330+
int "Shell TX timeout in milliseconds"
331+
default 500 if SHELL_LOG_BACKEND
332+
default 50
333+
help
334+
The timeout in milliseconds for the shell TX mutex. This is used to
335+
prevent deadlocks when called from other than the shell's processing thread.
336+
When using the shell log backend, the timeout should be longer to avoid
337+
timeouts due to log processing. A value of 0 means no timeout.
338+
329339
source "subsys/shell/modules/Kconfig"
330340

331341
endif # SHELL

subsys/shell/shell.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
"WARNING: A print request was detected on not active shell backend.\n"
3232
#define SHELL_MSG_TOO_MANY_ARGS "Too many arguments in the command.\n"
3333
#define SHELL_INIT_OPTION_PRINTER (NULL)
34-
#define SHELL_TX_MTX_TIMEOUT_MS 50
34+
#if (CONFIG_SHELL_TX_TIMEOUT_MS == 0)
35+
#define SHELL_TX_MTX_TIMEOUT K_FOREVER
36+
#else
37+
#define SHELL_TX_MTX_TIMEOUT K_MSEC(CONFIG_SHELL_TX_TIMEOUT_MS)
38+
#endif
3539

3640
#define SHELL_THREAD_PRIORITY \
3741
COND_CODE_1(CONFIG_SHELL_THREAD_PRIORITY_OVERRIDE, \
@@ -1355,7 +1359,7 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
13551359
K_FOREVER);
13561360

13571361
if (err != 0) {
1358-
if (k_mutex_lock(&sh->ctx->wr_mtx, K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)) != 0) {
1362+
if (k_mutex_lock(&sh->ctx->wr_mtx, SHELL_TX_MTX_TIMEOUT) != 0) {
13591363
return;
13601364
}
13611365
z_shell_fprintf(sh, SHELL_ERROR,
@@ -1448,7 +1452,7 @@ int shell_start(const struct shell *sh)
14481452
z_shell_log_backend_enable(sh->log_backend, (void *)sh, sh->ctx->log_level);
14491453
}
14501454

1451-
if (k_mutex_lock(&sh->ctx->wr_mtx, K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)) != 0) {
1455+
if (k_mutex_lock(&sh->ctx->wr_mtx, SHELL_TX_MTX_TIMEOUT) != 0) {
14521456
return -EBUSY;
14531457
}
14541458

@@ -1552,7 +1556,7 @@ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
15521556
return;
15531557
}
15541558

1555-
if (k_mutex_lock(&sh->ctx->wr_mtx, K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)) != 0) {
1559+
if (k_mutex_lock(&sh->ctx->wr_mtx, SHELL_TX_MTX_TIMEOUT) != 0) {
15561560
return;
15571561
}
15581562

@@ -1692,7 +1696,7 @@ int shell_prompt_change(const struct shell *sh, const char *prompt)
16921696

16931697
size_t prompt_length = z_shell_strlen(prompt);
16941698

1695-
if (k_mutex_lock(&sh->ctx->wr_mtx, K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)) != 0) {
1699+
if (k_mutex_lock(&sh->ctx->wr_mtx, SHELL_TX_MTX_TIMEOUT) != 0) {
16961700
return -EBUSY;
16971701
}
16981702

@@ -1715,7 +1719,7 @@ int shell_prompt_change(const struct shell *sh, const char *prompt)
17151719

17161720
void shell_help(const struct shell *sh)
17171721
{
1718-
if (k_mutex_lock(&sh->ctx->wr_mtx, K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)) != 0) {
1722+
if (k_mutex_lock(&sh->ctx->wr_mtx, SHELL_TX_MTX_TIMEOUT) != 0) {
17191723
return;
17201724
}
17211725
shell_internal_help_print(sh);
@@ -1750,7 +1754,7 @@ int shell_execute_cmd(const struct shell *sh, const char *cmd)
17501754
sh->ctx->cmd_buff_len = cmd_len;
17511755
sh->ctx->cmd_buff_pos = cmd_len;
17521756

1753-
if (k_mutex_lock(&sh->ctx->wr_mtx, K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)) != 0) {
1757+
if (k_mutex_lock(&sh->ctx->wr_mtx, SHELL_TX_MTX_TIMEOUT) != 0) {
17541758
return -ENOEXEC;
17551759
}
17561760
ret_val = execute(sh);

0 commit comments

Comments
 (0)