pkg/mplaland-printf: Use buffered output#21805
Conversation
|
Ah, I also sneaked in a fix where |
646a6ff to
46359e3
Compare
|
Great thanks. I will need two or three days to find time to test this on hardware. |
|
I suggest we |
|
True. With the number of patches stacking up and upstream being dead, I wonder if we should also just reduce our pain with the integration by just vendoring in the code. |
Apparently there is an actively maintained fork: |
|
OK, but that fork is almost twice as large. And the addition of cmakes increases integration complexity and build time for little to no benefit in our use case... |
mguetschow
left a comment
There was a problem hiding this comment.
Thanks! I think it wouldn't harm to add some documentation to the file about why we use the buffering?
46359e3 to
7ec55c4
Compare
|
I think you have to force-push again, Github seems to be confused because it was already on the queue 🤔 |
With this patch a small (64 byte) on-stack is buffer is used. On stdio transports with extremely high overhead per call of `stdio_write()` (like e.g. telnet or semihosting), this will make the stdio usable again. Compared to e.g. the stdio from newlib, the increased stack requirements are still modest. In addition, the RIOT integration now also checks the return value of `stdio_write()` and loops until all output has been written, fixing loss of output if a transport does not write all data in one go.
7ec55c4 to
30a4647
Compare
|
Something is not quite right. When I run On |
|
Is that issue only happening on USB, or also on UART? If it depends on the transport, it is more likely triggering an issue in the transport rather than actually causing it. There always has been something fishy with the USB CDC ACM, as the first command entered into the shell always contained part of the boot message printed. |
|
Does it work up to 128 B? /**
* @brief Buffer size for STDIN and STDOUT data to and from USB when using
* the USBUS_CDC_ACM_STDIO module
*/
#ifdef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP
#define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (1<<CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP)
#endif
#ifndef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE
#define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (128)
#endifThat seems to then trigger the "drop" flow control path in /* stuff as much data as possible into tsrb, discarding the oldest */
old = irq_disable();
n = tsrb_free(&cdcacm->tsrb);
if (len > n) {
n += tsrb_drop(&cdcacm->tsrb, len - n);
buf += len - n;
} else {
n = len;
}If |
|
Specifically, does this fix the issue? diff --git a/sys/usb/usbus/cdc/acm/cdc_acm.c b/sys/usb/usbus/cdc/acm/cdc_acm.c
index 77c93bcb5a..5528d1f28b 100644
--- a/sys/usb/usbus/cdc/acm/cdc_acm.c
+++ b/sys/usb/usbus/cdc/acm/cdc_acm.c
@@ -158,19 +158,8 @@ size_t usbus_cdc_acm_submit(usbus_cdcacm_device_t *cdcacm, const uint8_t *buf, s
irq_restore(old);
return n;
}
- /* stuff as much data as possible into tsrb, discarding the oldest */
- old = irq_disable();
- n = tsrb_free(&cdcacm->tsrb);
- if (len > n) {
- n += tsrb_drop(&cdcacm->tsrb, len - n);
- buf += len - n;
- } else {
- n = len;
- }
- tsrb_add(&cdcacm->tsrb, buf, n);
- /* behave as if everything has been written correctly */
- irq_restore(old);
- return len;
+
+ return tsrb_add(&cdcacm->tsrb, buf, len);
}
void usbus_cdc_acm_set_coding_cb(usbus_cdcacm_device_t *cdcacm,
diff --git a/sys/usb/usbus/cdc/acm/cdc_acm_stdio.c b/sys/usb/usbus/cdc/acm/cdc_acm_stdio.c
index fe171e7420..aca489a16e 100644
--- a/sys/usb/usbus/cdc/acm/cdc_acm_stdio.c
+++ b/sys/usb/usbus/cdc/acm/cdc_acm_stdio.c
@@ -36,15 +36,9 @@ static uint8_t _cdc_tx_buf_mem[CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE];
static ssize_t _write(const void* buffer, size_t len)
{
- const char *start = buffer;
- while (len) {
- size_t n = usbus_cdc_acm_submit(&cdcacm, buffer, len);
- usbus_cdc_acm_flush(&cdcacm);
- /* Use tsrb and flush */
- buffer = (char *)buffer + n;
- len -= n;
- }
- return (char *)buffer - start;
+ size_t res = usbus_cdc_acm_submit(&cdcacm, buffer, len);
+ usbus_cdc_acm_flush(&cdcacm);
+ return (ssize_t)res;
}
static void _cdc_acm_rx_pipe(usbus_cdcacm_device_t *cdcacm, |
|
Hm not really - what's pointing towards mpland is that the issue also occurs when I add |
Contribution description
With this patch a small (64 byte) on-stack is buffer is used. On stdio transports with extremely high overhead per call of
stdio_write()(like e.g. telnet or semihosting), this will make the stdio usable again.Compared to e.g. the stdio from newlib, the increased stack requirements are still modest.
Testing procedure
Run e.g. an app with lots of stdio output with an stdio transport that has a lot of overhead per
stdio_write()call. E.g.In
master, this will be unusable. (About two chars per second on for semihosting onmaster). With this PR, this should be faster.Issues/PRs references
Fixes a regression from #21438