Skip to content
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

shell: rtt: Add detection of host presence #68941

Merged

Conversation

nordic-krch
Copy link
Contributor

If host is not reading RTT data (because there is no PC connection or RTT reading application is not running on the host), thread will stuck continuously trying to write to RTT. All threads with equal or lower priority are blocked then. Adding detection of that case and if host is not reading data for configurable period then data is dropped until host accepts new data.

Fixes #49390.

@nordic-krch nordic-krch added the bug The issue is a bug, or the PR is fixing a bug label Feb 13, 2024
@zephyrbot zephyrbot added the area: Shell Shell subsystem label Feb 13, 2024
@MaureenHelm
Copy link
Member

Does this also fix #68709?

@MaureenHelm MaureenHelm added this to the v3.6.0 milestone Feb 14, 2024
@henrikbrixandersen
Copy link
Member

Does this also fix #68709?

@nordic-krch Ping on the above question?

@JeremiahGillis
Copy link

Does this also fix #68709?

@nordic-krch Ping on the above question?

I created #68709. I copied the changes from @nordic-krch into my local Zephyr v3.4.0. These changes still do not address my issue. log_panic() forces rtt_blocking which causes execution to get suck in this while loop now:

image

@henrikbrixandersen
Copy link
Member

I created #68709. I copied the changes from @nordic-krch into my local Zephyr v3.4.0. These changes still do not address my issue. log_panic() forces rtt_blocking which causes execution to get suck in this while loop now:

image

Much appreciated, thank you for testing.

@JeremiahGillis
Copy link

JeremiahGillis commented Feb 19, 2024

Much appreciated, thank you for testing.

I don't want to clutter this issue up, but if it helps, SEGGER_RTT_WriteNoLock is returning a size of 4 causing this logic to think the host is present. The host was not present in my case until my device hung in execution. Then I connected my J-Link cable and attached my debugger to view.

I think my issue still brings up a valid point about this else statement. If the host was present but became disconnected here, execution would be stuck forever. I would suggest to review the logic below in the log_backend_rtt.c module. This appears to account for problems like mine and host present issues.

static void on_failed_write(int retry_cnt)
{
if (retry_cnt == 0) {
host_present = false;
} else if (is_sync_mode()) {
k_busy_wait(USEC_PER_MSEC *
CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS);
} else {
k_msleep(CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS);
}
}

@nordic-krch
Copy link
Contributor Author

I took the solution from logging. @JeremiahGillis can you verify if that works for you?

@JeremiahGillis
Copy link

I took the solution from logging. @JeremiahGillis can you verify if that works for you?

Thank you. Yes, this works for my issue. I tested with and without the host present. It also works when the host is connected or disconnected during operation.

@nordic-krch
Copy link
Contributor Author

@henrikbrixandersen @jakub-uC can you take a look? @JeremiahGillis confirmed that it solved his issue.

static int write(const struct shell_transport *transport,
const void *data, size_t length, size_t *cnt)
{
struct shell_rtt *sh_rtt = (struct shell_rtt *)transport->ctx;
const uint8_t *data8 = (const uint8_t *)data;
static bool host_present;
Copy link
Contributor

@jakub-uC jakub-uC Mar 26, 2024

Choose a reason for hiding this comment

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

I am a bit concerned about name shadowing. You have already created host_present as a global variable. Was this intentional?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good finding. That was not intentional. Removed.

If host is not reading RTT data (because there is no PC connection
or RTT reading application is not running on the host), thread will
stuck continuously trying to write to RTT. All threads with equal or
lower priority are blocked then. Adding detection of that case and
if host is not reading data for configurable period then data is
dropped until host accepts new data.

Similar solution is using in RTT logging backend.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
@fabiobaltieri fabiobaltieri merged commit 04a74ce into zephyrproject-rtos:main Mar 28, 2024
21 checks passed
@@ -25,7 +31,8 @@ SHELL_DEFINE(shell_rtt, CONFIG_SHELL_PROMPT_RTT, &shell_transport_rtt,

LOG_MODULE_REGISTER(shell_rtt, CONFIG_SHELL_RTT_LOG_LEVEL);

static bool rtt_blocking;
static bool panic_mode;
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable is never set?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link

@aescov aescov Apr 17, 2024

Choose a reason for hiding this comment

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

@nordic-krch @fabiobaltieri : It seems that api for settting panic mode is missing i shell_transport_api. In NCS setup this causes an attempt to lock mutex ISR context, when entering from log_panic.

Copy link
Member

Choose a reason for hiding this comment

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

@aescov could you open either a PR with the fix or an issue so we can assign this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Shell Shell subsystem backport v3.6-branch Request backport to the v3.6-branch bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shell_rtt thread can starve other threads of the same priority
9 participants