Skip to contentSkip to conversation

console: Use flush() before panic and reset

PATCH In review Tony Dinh 4 participants 6 messages Mar 15, 2023 – Mar 22, 2023

Subsystems (2)
lore
Share & tools
lore

Tony Dinh

author
#0 lore raw

PATCH 1/1 console: Use flush() before panic and reset

To make sure the panic and the reset messages will go out, console flush() should be used. Sleep periods do not work in early u-boot phase when timer driver is not initialized yet.

Reference: https://lists.denx.de/pipermail/u-boot/2023-March/512233.html

---

 arch/arm/lib/reset.c | 4 ++--
 lib/panic.c          | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm/lib/reset.c +2 -2
index 95169bae1c..3e051e36f1 100644
@@ -25,6 +25,7 @@
 #include <cpu_func.h>
 #include <irq_func.h>
 #include <linux/delay.h>
+#include <stdio.h>
 
 __weak void reset_misc(void)
 {
@@ -33,8 +34,7 @@ __weak void reset_misc(void)
 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	puts ("resetting ...\n");
-
-	mdelay(50);				/* wait 50 ms */
+	flush();
 
 	disable_interrupts();
 
lib/panic.c +3 -1
index 58382ac4f4..66ae17f3df 100644
@@ -15,6 +15,7 @@
 #include <command.h>
 #endif
 #include <linux/delay.h>
+#include <stdio.h>
 
 static void panic_finish(void) __attribute__ ((noreturn));
 
@@ -24,7 +25,8 @@ static void panic_finish(void)
 #if defined(CONFIG_PANIC_HANG)
 	hang();
 #else
-	udelay(100000);	/* allow messages to go out */
+	flush();  /* flush the panic message before reset */
+
 	do_reset(NULL, 0, 0, NULL);
 #endif
 	while (1)
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Tony Dinh

To make sure the panic and the reset messages will go out, console flush() should be used. Sleep periods do not work in early u-boot phase when timer driver is not initialized yet.

Reference: https://lists.denx.de/pipermail/u-boot/2023-March/512233.html

---

 arch/arm/lib/reset.c | 4 ++--
 lib/panic.c          | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm/lib/reset.c +0 -0
index 95169bae1c..3e051e36f1 100644

arch/arm/lib/reset.c line 28

Quoted 4 lines
arch/arm/lib/reset.c +1 -0
@@ -25,6 +25,7 @@
 #include <cpu_func.h>
 #include <irq_func.h>
 #include <linux/delay.h>
+#include <stdio.h>

Is flush implemented widely?

author
#2 lore raw

Hi Simon,

Quoted 27 lines · Simon Glass
Quoted 18 lines · Tony Dinh

To make sure the panic and the reset messages will go out, console flush() should be used. Sleep periods do not work in early u-boot phase when timer driver is not initialized yet.

Reference: https://lists.denx.de/pipermail/u-boot/2023-March/512233.html

---

 arch/arm/lib/reset.c | 4 ++--
 lib/panic.c          | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm/lib/reset.c +0 -0
index 95169bae1c..3e051e36f1 100644

arch/arm/lib/reset.c line 28

Quoted 4 lines
arch/arm/lib/reset.c +1 -0
@@ -25,6 +25,7 @@
 #include <cpu_func.h>
 #include <irq_func.h>
 #include <linux/delay.h>
+#include <stdio.h>
Quoted 1 line

Is flush implemented widely?

Pali wrote that flush function and here was his comment on the referenced thread:
"Moreover there is already new function named flush() which does "wait until stdout message was sent" and can be used instead of those sleeps. I have already did it on some places (see git history for flush function) but seems that you find some more."

So I think the answer is not yet widely implemented.

All the best,
Tony

#3 lore raw
Quoted 32 lines · Tony Dinh

Hi Simon,

Quoted 27 lines · Simon Glass
Quoted 18 lines · Tony Dinh

To make sure the panic and the reset messages will go out, console flush() should be used. Sleep periods do not work in early u-boot phase when timer driver is not initialized yet.

Reference: https://lists.denx.de/pipermail/u-boot/2023-March/512233.html

---

  arch/arm/lib/reset.c | 4 ++--
  lib/panic.c          | 4 +++-
  2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm/lib/reset.c +0 -0
index 95169bae1c..3e051e36f1 100644

arch/arm/lib/reset.c line 28

Quoted 4 lines
arch/arm/lib/reset.c +1 -0
@@ -25,6 +25,7 @@
  #include <cpu_func.h>
  #include <irq_func.h>
  #include <linux/delay.h>
+#include <stdio.h>
Quoted 1 line

Is flush implemented widely?

Quoted 8 lines

Pali wrote that flush function and here was his comment on the referenced thread:
"Moreover there is already new function named flush() which does "wait until stdout message was sent" and can be used instead of those sleeps. I have already did it on some places (see git history for flush function) but seems that you find some more."

So I think the answer is not yet widely implemented.

I just checked and it seems it's supported for all platforms using DM_SERIAL when the serial driver supports the pending() function:

drivers/serial/serial-uclass.c:
#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
static void _serial_flush(struct udevice *dev)

{
	struct dm_serial_ops *ops = serial_get_ops(dev);

	if (!ops->pending)
		return;
	while (ops->pending(dev, false) > 0)
		;
}

#endif

So AFAICT it's implemented widely. Not sure, why CONFIG_CONSOLE_FLUSH_SUPPORT was introduced. It's enabled by default and should be available in all cases IMHO.

Thanks,
Stefan

Reviewed-by
#4 lore raw
In reply to Simon Glass
Quoted 14 lines · Simon Glass
Quoted 13 lines · Tony Dinh

To make sure the panic and the reset messages will go out, console flush() should be used. Sleep periods do not work in early u-boot phase when timer driver is not initialized yet.

Reference: https://lists.denx.de/pipermail/u-boot/2023-March/512233.html

---

  arch/arm/lib/reset.c | 4 ++--
  lib/panic.c          | 4 +++-
  2 files changed, 5 insertions(+), 3 deletions(-)
Quoted 11 lines

arch/arm/lib/reset.c line 28

Quoted 9 lines
arch/arm/lib/reset.c +1 -0
index 95169bae1c..3e051e36f1 100644
@@ -25,6 +25,7 @@
  #include <cpu_func.h>
  #include <irq_func.h>
  #include <linux/delay.h>
+#include <stdio.h>

Thanks,
Stefan

#5 lore raw
In reply to Tony Dinh
Quoted 8 lines · Tony Dinh

To make sure the panic and the reset messages will go out, console flush() should be used. Sleep periods do not work in early u-boot phase when timer driver is not initialized yet.

Reference: https://lists.denx.de/pipermail/u-boot/2023-March/512233.html

Applied to u-boot/master, thanks!

Signature · 1 line
Tom