From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Douglas Anderson <dianders@chromium.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Yicong Yang" <yangyicong@hisilicon.com>,
"Tony Lindgren" <tony@atomide.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Johan Hovold" <johan+linaro@kernel.org>,
"John Ogness" <john.ogness@linutronix.de>,
linux-arm-msm@vger.kernel.org,
"Bjorn Andersson" <andersson@kernel.org>,
"Konrad Dybcio" <konrad.dybcio@linaro.org>,
"Stephen Boyd" <swboyd@chromium.org>,
linux-serial <linux-serial@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH v4 2/8] tty: serial: Add uart_fifo_timeout_ms()
Date: Wed, 12 Jun 2024 10:38:08 +0300 (EEST) [thread overview]
Message-ID: <0bb414fa-851b-40cf-ede9-fc6252c6b173@linux.intel.com> (raw)
In-Reply-To: <20240610152420.v4.2.I65a6430ab75f74d20c28b5c5f819dd5b8455933d@changeid>
[-- Attachment #1: Type: text/plain, Size: 2453 bytes --]
On Mon, 10 Jun 2024, Douglas Anderson wrote:
> The current uart_fifo_timeout() returns jiffies, which is not always
> the most convenient for callers. Add a variant uart_fifo_timeout_ms()
> that returns the timeout in milliseconds.
>
> NOTES:
> - msecs_to_jiffies() rounds up, unlike nsecs_to_jiffies(). This is
> because msecs_to_jiffies() is actually intended for device drivers
> to calculate timeout value. This means we don't need to take the max
> of the timeout and "1" since the timeout will always be > 0 ms (we
> add 20 ms of slop).
> - uart_fifo_timeout_ms() returns "unsigned int" but we leave
> uart_fifo_timeout() returning "unsigned long". This matches the
> types of msecs_to_jiffies().
>
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
>
> Changes in v4:
> - New
>
> include/linux/serial_core.h | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index 8cb65f50e830..97968acfd564 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -889,14 +889,21 @@ unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud);
> /*
> * Calculates FIFO drain time.
> */
> -static inline unsigned long uart_fifo_timeout(struct uart_port *port)
> +static inline unsigned int uart_fifo_timeout_ms(struct uart_port *port)
> {
> u64 fifo_timeout = (u64)READ_ONCE(port->frame_time) * port->fifosize;
> + unsigned int fifo_timeout_ms = div_u64(fifo_timeout, NSEC_PER_MSEC);
>
> - /* Add .02 seconds of slop */
> - fifo_timeout += 20 * NSEC_PER_MSEC;
> + /*
> + * Add .02 seconds of slop. This also helps account for the fact that
> + * when we converted from ns to ms that we didn't round up.
> + */
> + return fifo_timeout_ms + 20;
> +}
>
> - return max(nsecs_to_jiffies(fifo_timeout), 1UL);
> +static inline unsigned long uart_fifo_timeout(struct uart_port *port)
> +{
> + return msecs_to_jiffies(uart_fifo_timeout_ms(port));
> }
Hi,
This is definitely towards the right direction! However, it now does
double conversion, first div_u64() and then msecs_to_jiffies(). Perhaps it
would be better to retain the nsecs version (maybe rename it to _ns for
consistency) and add _ms variant that does the nsec -> msec conversion.
--
i.
next prev parent reply other threads:[~2024-06-12 7:38 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 22:24 [PATCH v4 0/8] serial: qcom-geni: Overhaul TX handling to fix crashes/hangs Douglas Anderson
2024-06-10 22:24 ` [PATCH v4 1/8] soc: qcom: geni-se: Add GP_LENGTH/IRQ_EN_SET/IRQ_EN_CLEAR registers Douglas Anderson
2024-06-10 22:24 ` [PATCH v4 2/8] tty: serial: Add uart_fifo_timeout_ms() Douglas Anderson
2024-06-12 7:38 ` Ilpo Järvinen [this message]
2024-06-12 18:45 ` Doug Anderson
2024-06-13 6:56 ` Ilpo Järvinen
2024-06-13 14:02 ` Doug Anderson
2024-06-10 22:24 ` [PATCH v4 3/8] serial: qcom-geni: Fix the timeout in qcom_geni_serial_poll_bit() Douglas Anderson
2024-06-17 18:46 ` Konrad Dybcio
2024-06-10 22:24 ` [PATCH v4 4/8] serial: qcom-geni: Fix arg types for qcom_geni_serial_poll_bit() Douglas Anderson
2024-06-17 18:47 ` Konrad Dybcio
2024-06-10 22:24 ` [PATCH v4 5/8] serial: qcom-geni: Introduce qcom_geni_serial_poll_bitfield() Douglas Anderson
2024-06-17 18:53 ` Konrad Dybcio
2024-06-10 22:24 ` [PATCH v4 6/8] serial: qcom-geni: Just set the watermark level once Douglas Anderson
2024-06-10 22:24 ` [PATCH v4 7/8] serial: qcom-geni: Fix suspend while active UART xfer Douglas Anderson
2024-06-17 19:02 ` Konrad Dybcio
2024-06-24 12:12 ` Johan Hovold
2024-06-24 16:54 ` Johan Hovold
2024-06-24 20:58 ` Doug Anderson
2024-06-25 8:46 ` Johan Hovold
2024-06-10 22:24 ` [PATCH v4 8/8] serial: qcom-geni: Rework TX in FIFO mode to fix hangs/lockups Douglas Anderson
2024-06-17 19:10 ` Konrad Dybcio
2024-06-17 19:37 ` Doug Anderson
2024-06-17 19:54 ` Konrad Dybcio
2024-06-24 12:43 ` Johan Hovold
2024-06-24 21:15 ` Doug Anderson
2024-06-25 11:21 ` Johan Hovold
2024-06-25 14:29 ` Doug Anderson
2024-06-26 8:20 ` Johan Hovold
2024-06-18 10:19 ` [PATCH v4 0/8] serial: qcom-geni: Overhaul TX handling to fix crashes/hangs Konrad Dybcio
2024-06-19 8:25 ` neil.armstrong
2024-06-19 8:50 ` Johan Hovold
2024-06-20 23:13 ` Nícolas F. R. A. Prado
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0bb414fa-851b-40cf-ede9-fc6252c6b173@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=andersson@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=johan+linaro@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=swboyd@chromium.org \
--cc=tony@atomide.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=yangyicong@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox