Re: patch review: avoid com delay() in VMs

Manuel Bouyer <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
On Fri, Feb 07, 2025 at 06:35:04AM +0100, Emile `iMil' Heitor wrote:
> On Wed, 5 Feb 2025, Emile `iMil' Heitor wrote:
> 
> > After several back-and-forths, thanks Martin, Simon and Taylor for
> > your help, here's a cleaner approach based on prop_dictionary_util,
> > avoiding #ifdefs:
> 
> Another day, another proposal!
> Here are the results of discussions about finally getting rid of delay()
> and instead checking LSR_TXRDY (aka LSR_THRE) or LSR_TSRE (aka LSR_TEMT)
> 
> diff --git a/sys/dev/ic/com.c b/sys/dev/ic/com.c
> index d271b594346..082b5b8a985 100644
> --- a/sys/dev/ic/com.c
> +++ b/sys/dev/ic/com.c
> @@ -536,6 +536,7 @@ com_attach_subr(struct com_softc *sc)
>         struct tty *tp;
>         uint32_t cpr;
>         uint8_t lcr;
> +       int timo;
>         const char *fifo_msg = NULL;
>         prop_dictionary_t dict;
>         bool is_console = true;
> @@ -588,9 +589,13 @@ com_attach_subr(struct com_softc *sc)
>                         sc->sc_lcr = cflag2lcr(comcons_info.cflag);
>                         break;
>                 }
> +               /* wait for output to finish */
> +               timo = 10000;
> +               while (!ISSET(CSR_READ_1(regsp, COM_REG_LSR),
> +                   LSR_TXRDY | LSR_TSRE) && --timo)
> +                       continue;
> 
>                 /* Make sure the console is always "hardwired". */
> -               delay(10000);                   /* wait for output to finish */
>                 if (is_console) {
>                         SET(sc->sc_hwflags, COM_HW_CONSOLE);
>                 }

timo looks way too low to me.
On a multi-gHz CPU, counting from 10000 to 0 doens't even let you send
one byte at 9600bds.

Another way to compute the timeout is probably needed.

-- 
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.