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/doc: Point users who run into shell buffer issues to the stdin buffer #20541

Merged

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Apr 5, 2024

Contribution description

Trouble with stdin and the shell can be hard to debug, and may send people off to a wild goose chase:

> coap get 2001:db8:8000:0:acf7:8017:ce77:b42a 5683 /.well-known/core

Is that an issue with CoAP? No. The shell? No. Let's ask on matrix... 🪿🪿🪿

This PR cuts the chase short when looking at the shell documentation and its buffer length.

Testing procedure

Please don't, it's annoying to forget everything written above and go through the debug steps once more with the updated documentation. Instead, just look at the documentation and ponder whether it'd have cut the chase short.

Further processing

The warning can go away once the ISR queue mechanism for stdin is replaced with something that has backpressure, so that (in the concrete case where it was discovered) the USB CDC-ACM can start sending NACKs until the stdin buffer has been read into the command line buffer (or we switch completely to something where stdin either has a configured receive buffer that is switched around fast enough, and the interrupts write into that directly).

@chrysn chrysn requested review from bergzand and MrKevinWeiss April 5, 2024 08:46
@chrysn chrysn added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 5, 2024
@github-actions github-actions bot added the Area: sys Area: System label Apr 5, 2024
@chrysn
Copy link
Member Author

chrysn commented Apr 5, 2024

I'll wait with pushing the merge button until I've seen the rendered artifact.

* and overflows silently. As a consequence, commands through such terminals
* appear to be truncated at @ref STDIO_RX_BUFSIZE bytes (defaulting to 64)
* unless the command is sent in parts (on many terminals, by presing Ctrl-D
* half way through the command).
*/
#define SHELL_DEFAULT_BUFSIZE (128)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not the same as STDIO_RX_BUFSIZE?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't comment on the authors' intentions, but generally I do still think that these are different -- SHELL_DEFAULT_BUFSIZE is about the longest command, STDIO_RX_BUFSIZE is about how many bytes are tolerated to be sent w/o blocking on the application to process them into the buffer (and 64 is surprisingly large for that purpose). Their relation only matters in the case of a line-buffered terminal, which is a choice outside of the control of the embedded application.

If we want to change code and not just docs, I'd prefer we do it right (by allowing backpressure or doing zero-copy) rather than creating a cross-layer configuration dependency when we're already struggling to get our configs transparent.

@riot-ci
Copy link

riot-ci commented Apr 5, 2024

Murdock results

✔️ PASSED

b0bec02 shell/doc: Point users who run into shell buffer issues to the stdin buffer

Success Failures Total Runtime
1 0 1 58s

Artifacts

@kfessel
Copy link
Contributor

kfessel commented Apr 5, 2024

@benpicco benpicco added the Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer label Apr 5, 2024
@@ -75,6 +75,15 @@ extern "C" {

/**
* @brief Default shell buffer size (maximum line length shell can handle)
*
* @warning On terminals that buffer input and send the full command line in one go,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @warning On terminals that buffer input and send the full command line in one go,
* @warning On terminals that buffer input and send the full command line in one go (like `pyterm`),

let's not be vague, this affects our default terminal after all

Copy link
Member Author

Choose a reason for hiding this comment

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

To be frank I don't have the overview of which terminal program we default to, we support so many and I often just socat in to the UART.

If it is really the default for all, we could even say

Suggested change
* @warning On terminals that buffer input and send the full command line in one go,
* @warning On terminals that buffer input and send the full command line in one go (like our default `pyterm`),

but then I'd also look into sharpening the criterion, as it does apparently not affect all stdio. (I guess that UART based could be unaffected because UARTs' units of transfer are smaller than the buffer size, and slow enough that the shell thread can catch up).

Copy link
Member Author

Choose a reason for hiding this comment

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

New text now says "When terminals that buffer input and send the full command line in one go are used on stdin implementations with fast bursts of data", and

+ *   For example, this affects systems with direct USB stdio (@ref
+ *   usbus_cdc_acm_stdio) with the default terminal `pyterm`.

(Sorry, should have been a fixup rather than an amend/force)

@chrysn chrysn force-pushed the doc-shell-constraint branch from 51a2409 to b0bec02 Compare April 5, 2024 15:28
@chrysn chrysn added the Area: doc Area: Documentation label Apr 5, 2024
@MrKevinWeiss MrKevinWeiss added this pull request to the merge queue Apr 9, 2024
Merged via the queue into RIOT-OS:master with commit 5c4480d Apr 9, 2024
27 checks passed
@MrKevinWeiss MrKevinWeiss deleted the doc-shell-constraint branch April 15, 2024 07:54
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.04 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants