linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Xin Zhao <jackzxcui1989@163.com>
Cc: jirislaby@kernel.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, tj@kernel.org, hch@infradead.org
Subject: Re: [PATCH] tty: tty_buffer: add interface to queue work on specific wq and cpu
Date: Tue, 21 Oct 2025 06:28:24 +0200	[thread overview]
Message-ID: <2025102141-quintuple-oozy-f2f6@gregkh> (raw)
In-Reply-To: <20251021042110.513095-1-jackzxcui1989@163.com>

On Tue, Oct 21, 2025 at 12:21:10PM +0800, Xin Zhao wrote:
> On the embedded platform, certain critical data, such as IMU data, is
> transmitted through UART. We have customized our own 8250 driver, but
> we still need to reuse the kernel's TTY layer. The tty_flip_buffer_push
> interface in the TTY layer uses system_unbound_wq to handle the flipping
> of the TTY buffer. Although the unbound workqueue can create new threads
> on demand and wake up the kworker thread on an idle CPU, the priority of
> the kworker thread itself is not high. Even if the CPU running this work
> was idle just a moment ago, it may be preempted by real-time tasks or
> other high-priority tasks.
> In our system, the processing interval for each frame of IMU data
> transmitted via UART can experience significant jitter due to this issue.
> Instead of the expected 10 to 15 ms frame processing interval, we see
> spikes up to 30 to 35 ms. Moreover, in just one or two hours, there can
> be 2 to 3 occurrences of such high jitter, which is quite frequent. This
> jitter exceeds the software's tolerable limit of 20 ms.
> Adding the tty_flip_buffer_push_wq interface would allow our 8250 driver
> code to push work to a specified CPU. Since CPU tasks, especially real-time
> tasks, often have a certain distribution pattern in the system, we found
> that by pushing to a specified CPU with a WQ_HIGHPRI workqueue, we can
> stably eliminate the jitter and ensure that the frame processing interval
> remains between 10 and 15 ms. Furthermore, if we implement an RT workqueue
> based on this, using the tty_flip_buffer_push_wq interface to push to the
> RT workqueue(FIFO 1) we can further stabilize the processing interval,
> significantly reducing the occurrences of 14-15 ms intervals and increasing
> the frequency of 11-12 ms intervals.
> 
> Signed-off-by: Xin Zhao <jackzxcui1989@163.com>
> ---
>  drivers/tty/tty_buffer.c | 23 +++++++++++++++++++++++
>  include/linux/tty_flip.h |  3 +++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
> index 67271fc0b..112a650e2 100644
> --- a/drivers/tty/tty_buffer.c
> +++ b/drivers/tty/tty_buffer.c
> @@ -534,6 +534,29 @@ void tty_flip_buffer_push(struct tty_port *port)
>  }
>  EXPORT_SYMBOL(tty_flip_buffer_push);
>  
> +/**
> + * tty_flip_buffer_push		-	push terminal buffers
> + * @port: tty port to push
> + * @wq: workqueue on which to queue work
> + * @cpu: cpu on which to queue work
> + *
> + * Queue a push of the terminal flip buffers to the line discipline. Can be
> + * called from IRQ/atomic context.
> + *
> + * In the event of the queue being busy for flipping the work will be held off
> + * and retried later.
> + */
> +void tty_flip_buffer_push_wq(struct tty_port *port,
> +			     struct workqueue_struct *wq,
> +			     int cpu)
> +{
> +	struct tty_bufhead *buf = &port->buf;
> +
> +	tty_flip_buffer_commit(buf->tail);
> +	queue_work_on(cpu, wq, &buf->work);
> +}
> +EXPORT_SYMBOL(tty_flip_buffer_push_wq);

For obvious reasons, we can not accept new kernel apis without any
in-kernel user.  Please submit this as part of a patch series that adds
the new user.

thanks,

greg k-h

      reply	other threads:[~2025-10-21  4:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21  4:21 [PATCH] tty: tty_buffer: add interface to queue work on specific wq and cpu Xin Zhao
2025-10-21  4:28 ` Greg KH [this message]

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=2025102141-quintuple-oozy-f2f6@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=hch@infradead.org \
    --cc=jackzxcui1989@163.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=tj@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).