-
Notifications
You must be signed in to change notification settings - Fork 8.2k
shell: shell_uart: add ring_buffers and interrupt support #10923
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
Conversation
|
note that #10924 are needed to make uart with interrupts work. |
Codecov Report
@@ Coverage Diff @@
## master #10923 +/- ##
=======================================
Coverage 53.1% 53.1%
=======================================
Files 218 218
Lines 26853 26853
Branches 5950 5950
=======================================
Hits 14259 14259
Misses 10162 10162
Partials 2432 2432Continue to review full report at Codecov.
|
4c71928 to
532f966
Compare
6d289c6 to
a169deb
Compare
|
sample net/echo_server with netusb with log and shell enable is near its ROM limits (~99% of ROM used) on quark_se_c1000 so any increase is causing compilation failure. I already hit that in #10794 and now here. Here i solved it by disabling built-in commands in shell to save some bytes (~1k). On this branch it is now at 98,05% but this approach will not fly for long. @jukkar what would you suggest for long term? |
|
One easy way to lower the memory consumption is to lower network buffer count, but there is also a limit there after which the device is not very usable from networking point of view. What this limit is depends lot of use cases. |
subsys/shell/shell.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message:
Shell log backend was enabled to early
"too early"
subsys/shell/Kconfig.backends
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks too low for me. I still didn't try to do the usual smoke test of pasting a decent length of line into the new shell - afraid of unpleasant surprises ;-). But with such a receive buffer size surprises are guaranteed. I'd suggest to set to 64 or something. On the contrary, tx buffer can decreased (if really needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, if you paste a line it will loose bytes. i will increase to 64. On the other hand if user is only typing then 8 is more then enough and 56 bytes of ram on some platforms means another feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand if user is only typing then 8 is more then enough and 56 bytes of ram on some platforms means another feature.
Well, we need to think about UX and common usecases. But granted, that can be seen as requiring separate consideration (and testing), so can be done later.
|
So, as usual, this just duplicates effort of subsys/console, instead of reusing and improving it. Well, let there be parallel pathways, until they intersect. I'll be happy to give +1 when same is done to my piece, #10765 ;-). And please specify which boards were tested with this patch - we can expect it's not working with some (or more). (That's also the reason why I don't want to make too much changes at once in #10765 - currently refactor leaves alone (mostly) known-good ISR handling). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it enough to switch off only resize command?
subsys/shell/shell.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happened with todo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo was outdated and should have been removed when k_poll was added
subsys/shell/shell.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand this conversion. log_level is a pointer, you are converting it to bool and passing to function expecting u32_t ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed. I also refactored a bit to cast early those void * to local variables.
subsys/shell/shell_uart.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We shall use
__ASSERT_NO_MSG - Don't you get any compiler warning about unused variable
errwhen assert is off?
jakub-uC
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify some questions.
Yes, it was started weeks before #10765 was public. I expect they will intersect at some point. I accept you offer: you got +1 for #10765, i'm waiting for mine :).
Tested on nrf52. ISR UART backend is use by default if platform supports uart with interrupts. Will see how many uarts implements interrupts correctly. |
I am afraid I took too rough approach disabling IPv6 ;) |
pfalcon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was started weeks before #10765 was public. I expect they will intersect at some point.
Yep, let's look at the bright side of it: because we follow different by close footpaths it'll allow to find the best route to place a highway, likewise, exploring different by close code will allow to explore problem space in more detail and know problem spots/find ways to address them quicker.
UART handling looks OK, approving from that side.
For reference, subsys/console when was written was tested at least on arduino_101 (that's a "different" beast), frdm_k64f, 96b_carbon (these are about the same). Testing included being able to paste more than the rx buffer. That was one of the prompting point and requirement for subsys/console - it was developed for MicroPython porting, and it has "paste mode", which allows you to copy and paste code from a host file, manual, etc. That's the most practical way small-scale repeated interaction, and before subsys/console, nothing in Zephyr allowed pastes to work reliably.
We now have report (#10726) that subsys/console glitches on a particular STM32 chip. And as subsys/console is just a generic produces/consumer queues + ISR, then the problem would be either in UART driver, or that this particular chip has IRQ process not fitting into the model (and I spent enough time to chart what would be the appropriate IRQ handling model for UART drivers, again, it work for as diverse cases as 16550 (arduino_101) and common single-byte RX/TX regs as a baselines for ARM chips). My current mental solution for that is console/subsys (to be upgraded to ring_buffer, like here) is a reference, baseline implementation. It should move to drivers/serial, and a particular driver can either use it, or can override completely. All that are just draft thoughts, should be considered for interaction with #10820, etc. |
a169deb to
4f04b31
Compare
c4e050a to
94d5850
Compare
|
@jarz-nordic please take another look, i've added blocking support to the backend (to handle panic case). Also moved rx polling period to kconfig. |
subsys/shell/Kconfig.backends
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename it to SHELL_BACKEND_SERIAL_USE_INTERRUPTS
0dff87b to
5078243
Compare
Improved RX path to use ring buffer for incoming data instead of single byte buffer. Improved TX path to use ring buffer. Added support for asynchronous UART API (interrupts). Signed-off-by: Krzysztof Chruscinski <[email protected]>
5078243 to
9d72806
Compare
|
@nordic-krch: So, how well did you test this patch with various qemu targets? Are you aware of #8869 for example? In summary, interrupt-driven UART is great boon for real hardware, and curse for QEMU emulations, which don't have faithful IRQ emulation, sometimes even remotely. All in all, I see obvious shell behavior regressions with this patch for BOARD=mps2_an385 in qemu (and that's about to become the default qemu target for arm). |
|
@pfalcon : Old shell was also interrupt driven for Rx. |
Old shell as in "old shell", or as in "new shell before this PR"? The old shell had a pretty fun design, which didn't work well even on real hardware (e.g. for pastes). Here we discuss the problem with QEMU and this particular PR. |
| bool | ||
| default y | ||
| depends on SERIAL_SUPPORT_INTERRUPT | ||
| imply UART_INTERRUPT_DRIVEN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh god, "imply"! That's first time I see it in Kconfig, I swear. I've got so much to learn...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is nice difference. With imply you are able to unselect an option with menuconfig.
|
@pfalcon : old shell as an old shell. So this is not a regression but something we need to improve :) |
|
@jarz-nordic :
Yeah, we mostly left old shell behind (#10769 is again mostly to prove the point that if we replace "old" with "new", we should port over the functionality by default, or someone will ask why we didn't, and we'll need to have an answer, preferably good). So, this is not regression re: old shell. This is qemu-specific regression before and after this patch. You're right that we need to deal with it. Let's move discussion to a more suitable place, I'll see if we can repurpose some existing ticket or it's better to create new. |
Well, i think that we have uart.h api that i should be able to rely on. If specific driver implements interrupt version then it's not my fault if it is faulty :). If qemu interrupt driven uart is lousy then it should be improved or disabled or we should have big banner somewhere |
|
@nordic-krch, @jarz-nordic: Let's move discussion to #8869 please. |
Improved RX path to use ring buffer for incoming data instead of single
byte buffer. Improved TX path to use ring buffer. Added support for
asynchronous UART API (interrupts).
Signed-off-by: Krzysztof Chruscinski [email protected]