All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] console: Use flush() before panic and reset
@ 2023-03-15  0:24 Tony Dinh
  2023-03-15 19:43 ` Simon Glass
  2023-03-22 18:05 ` Tom Rini
  0 siblings, 2 replies; 6+ messages in thread
From: Tony Dinh @ 2023-03-15  0:24 UTC (permalink / raw)
  To: Stefan Roese, Pali Roh�r, Tom Rini, Simon Glass,
	U-Boot Mailing List
  Cc: Michael Walle, 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

Signed-off-by: Tony Dinh <mibodhi@gmail.com>
---

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

diff --git a/arch/arm/lib/reset.c b/arch/arm/lib/reset.c
index 95169bae1c..3e051e36f1 100644
--- a/arch/arm/lib/reset.c
+++ b/arch/arm/lib/reset.c
@@ -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();
 
diff --git a/lib/panic.c b/lib/panic.c
index 58382ac4f4..66ae17f3df 100644
--- a/lib/panic.c
+++ b/lib/panic.c
@@ -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)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] console: Use flush() before panic and reset
  2023-03-15  0:24 [PATCH] console: Use flush() before panic and reset Tony Dinh
@ 2023-03-15 19:43 ` Simon Glass
  2023-03-15 20:29   ` Tony Dinh
  2023-03-16  9:02   ` Stefan Roese
  2023-03-22 18:05 ` Tom Rini
  1 sibling, 2 replies; 6+ messages in thread
From: Simon Glass @ 2023-03-15 19:43 UTC (permalink / raw)
  To: Tony Dinh
  Cc: Stefan Roese, Pali Rohár, Tom Rini, U-Boot Mailing List,
	Michael Walle

On Tue, 14 Mar 2023 at 18:24, Tony Dinh <mibodhi@gmail.com> wrote:
>
> 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
>
> Signed-off-by: Tony Dinh <mibodhi@gmail.com>
> ---
>
>  arch/arm/lib/reset.c | 4 ++--
>  lib/panic.c          | 4 +++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/lib/reset.c b/arch/arm/lib/reset.c
> index 95169bae1c..3e051e36f1 100644
> --- a/arch/arm/lib/reset.c
> +++ b/arch/arm/lib/reset.c
> @@ -25,6 +25,7 @@
>  #include <cpu_func.h>
>  #include <irq_func.h>
>  #include <linux/delay.h>
> +#include <stdio.h>

Reviewed-by: Simon Glass <sjg@chromium.org>

Is flush implemented widely?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] console: Use flush() before panic and reset
  2023-03-15 19:43 ` Simon Glass
@ 2023-03-15 20:29   ` Tony Dinh
  2023-03-16  9:00     ` Stefan Roese
  2023-03-16  9:02   ` Stefan Roese
  1 sibling, 1 reply; 6+ messages in thread
From: Tony Dinh @ 2023-03-15 20:29 UTC (permalink / raw)
  To: Simon Glass, Pali Rohár
  Cc: Stefan Roese, Tom Rini, U-Boot Mailing List, Michael Walle

Hi Simon,

On Wed, Mar 15, 2023 at 12:43 PM Simon Glass <sjg@chromium.org> wrote:
>
> On Tue, 14 Mar 2023 at 18:24, Tony Dinh <mibodhi@gmail.com> wrote:
> >
> > 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
> >
> > Signed-off-by: Tony Dinh <mibodhi@gmail.com>
> > ---
> >
> >  arch/arm/lib/reset.c | 4 ++--
> >  lib/panic.c          | 4 +++-
> >  2 files changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm/lib/reset.c b/arch/arm/lib/reset.c
> > index 95169bae1c..3e051e36f1 100644
> > --- a/arch/arm/lib/reset.c
> > +++ b/arch/arm/lib/reset.c
> > @@ -25,6 +25,7 @@
> >  #include <cpu_func.h>
> >  #include <irq_func.h>
> >  #include <linux/delay.h>
> > +#include <stdio.h>
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] console: Use flush() before panic and reset
  2023-03-15 20:29   ` Tony Dinh
@ 2023-03-16  9:00     ` Stefan Roese
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Roese @ 2023-03-16  9:00 UTC (permalink / raw)
  To: Tony Dinh, Simon Glass, Pali Rohár
  Cc: Tom Rini, U-Boot Mailing List, Michael Walle

On 3/15/23 21:29, Tony Dinh wrote:
> Hi Simon,
> 
> On Wed, Mar 15, 2023 at 12:43 PM Simon Glass <sjg@chromium.org> wrote:
>>
>> On Tue, 14 Mar 2023 at 18:24, Tony Dinh <mibodhi@gmail.com> wrote:
>>>
>>> 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
>>>
>>> Signed-off-by: Tony Dinh <mibodhi@gmail.com>
>>> ---
>>>
>>>   arch/arm/lib/reset.c | 4 ++--
>>>   lib/panic.c          | 4 +++-
>>>   2 files changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/arch/arm/lib/reset.c b/arch/arm/lib/reset.c
>>> index 95169bae1c..3e051e36f1 100644
>>> --- a/arch/arm/lib/reset.c
>>> +++ b/arch/arm/lib/reset.c
>>> @@ -25,6 +25,7 @@
>>>   #include <cpu_func.h>
>>>   #include <irq_func.h>
>>>   #include <linux/delay.h>
>>> +#include <stdio.h>
>>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>
>> 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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] console: Use flush() before panic and reset
  2023-03-15 19:43 ` Simon Glass
  2023-03-15 20:29   ` Tony Dinh
@ 2023-03-16  9:02   ` Stefan Roese
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Roese @ 2023-03-16  9:02 UTC (permalink / raw)
  To: Simon Glass, Tony Dinh
  Cc: Pali Rohár, Tom Rini, U-Boot Mailing List, Michael Walle

On 3/15/23 20:43, Simon Glass wrote:
> On Tue, 14 Mar 2023 at 18:24, Tony Dinh <mibodhi@gmail.com> wrote:
>>
>> 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
>>
>> Signed-off-by: Tony Dinh <mibodhi@gmail.com>
>> ---
>>
>>   arch/arm/lib/reset.c | 4 ++--
>>   lib/panic.c          | 4 +++-
>>   2 files changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/arm/lib/reset.c b/arch/arm/lib/reset.c
>> index 95169bae1c..3e051e36f1 100644
>> --- a/arch/arm/lib/reset.c
>> +++ b/arch/arm/lib/reset.c
>> @@ -25,6 +25,7 @@
>>   #include <cpu_func.h>
>>   #include <irq_func.h>
>>   #include <linux/delay.h>
>> +#include <stdio.h>
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] console: Use flush() before panic and reset
  2023-03-15  0:24 [PATCH] console: Use flush() before panic and reset Tony Dinh
  2023-03-15 19:43 ` Simon Glass
@ 2023-03-22 18:05 ` Tom Rini
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Rini @ 2023-03-22 18:05 UTC (permalink / raw)
  To: Tony Dinh
  Cc: u-boot, Stefan Roese, Simon Glass, Pali Rohár, Michael Walle

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

On Tue, Mar 14, 2023 at 05:24:26PM -0700, Tony Dinh wrote:

> 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
> 
> Signed-off-by: Tony Dinh <mibodhi@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Stefan Roese <sr@denx.de>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-22 18:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15  0:24 [PATCH] console: Use flush() before panic and reset Tony Dinh
2023-03-15 19:43 ` Simon Glass
2023-03-15 20:29   ` Tony Dinh
2023-03-16  9:00     ` Stefan Roese
2023-03-16  9:02   ` Stefan Roese
2023-03-22 18:05 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.