public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Xin Zhao <jackzxcui1989@163.com>
Cc: tj@kernel.org, jirislaby@kernel.org, hch@infradead.org,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v3] tty: tty_port: add workqueue to flip tty buffer
Date: Wed, 26 Nov 2025 13:10:49 +0100	[thread overview]
Message-ID: <2025112654-shaping-undoing-afe4@gregkh> (raw)
In-Reply-To: <20251125021959.1509256-1-jackzxcui1989@163.com>

On Tue, Nov 25, 2025 at 10:19:59AM +0800, Xin Zhao wrote:
> On Mon, Nov 24, 2025 at 06:02:07AM -1000 Tejun Heo <tj@kernel.org> wrote:
> 
> > > On Mon, Nov 24, 2025 at 01:17:51PM +0800, Xin Zhao wrote:
> > > > > +/**
> > > > > + * tty_flip_wq_init -- prepare workqueue for tty/pty flip buffer work
> > > > > + * @port: tty_port of the device
> > > > > + * @driver: tty_driver for this device
> > > > > + * @index: index of the tty
> > > > > + *
> > > > > + * Not all tty_port will be initialized by tty_port_init where tty_flip_wq will
> > > > > + * be set to system_unbound_wq as default. Allocate workqueue with WQ_SYSFS for
> > > > > + * flip buffer, so that cpumask and nice can be changed dynamically.
> > > > > + */
> > > > > +void tty_flip_wq_init(struct tty_port *port, struct tty_driver *driver,
> > > > > +		      unsigned int index)
> > > > > +{
> > > > > +	char name[64];
> > > > > +
> > > > > +	if (driver->type == TTY_DRIVER_TYPE_PTY) {
> > > > > +		port->buf.tty_flip_wq = pty_flip_wq;
> > > > > +		return;
> > > > > +	}
> > > > > +	tty_line_name(driver, index, name);
> > > > > +	if (!port->buf.tty_flip_wq
> > > > > +		|| port->buf.tty_flip_wq == system_unbound_wq) {
> > > > > +		port->buf.tty_flip_wq = alloc_workqueue("%s-flip-wq",
> > > > > +							WQ_UNBOUND | WQ_SYSFS,
> > > > > +							0, name);
> > > > > +		if (unlikely(!port->buf.tty_flip_wq))
> > > > > +			port->buf.tty_flip_wq = system_unbound_wq;
> > > > > +	}
> > > > > +}
> > > 
> > > These look overly elaborate to me. Just fail init if workqueue allocation
> > > fails? Also, is it necessary for each port to have separate port?
> > 
> > Sorry, I meant a separate workqueue.
> 
> I admit it is a bit complex.
> I searched for a long time and found in function tty_port_link_device seems to be an
> appropriate place to initialize the workqueue. However, the tty_port_link_device
> interface does not return a value, so error handling seems to be quite difficult.
> 
> Greg KH suggested creating a workqueue for each tty port, as follow:
> > >  
> > >  	tty_flip_buffer_commit(buf->tail);
> > > -	queue_work(system_unbound_wq, &buf->work);
> > > +	queue_work(port->wq_tty_flip ?: system_unbound_wq, &buf->work);
> > 
> > Why not just do this for all tty ports?  What is the benifit of keeping
> > this on the system_unbound_wq for all other tty devices?
> 
> I think if there are many tty devices on the system, having separate workqueues
> might be the right approach. Or should a single tty_driver share one?
> 
> Greg and Jiri Slaby have any comments on this?

I don't know, what have you found in your testing?  Will multiple
workqueues cause too much overhead for large multi-port systems (i.e.
modem banks?)

Perhaps start with just a single workqueue and then increase it if there
is contention later if people notice?

thanks,

greg k-h

  reply	other threads:[~2025-11-26 12:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27  6:09 [PATCH v3] tty: tty_port: add workqueue to flip tty buffer Xin Zhao
2025-11-24  5:17 ` Xin Zhao
2025-11-24 16:02   ` Tejun Heo
2025-11-24 16:02     ` Tejun Heo
2025-11-25  2:19     ` Xin Zhao
2025-11-26 12:10       ` Greg KH [this message]
2025-11-26 14:46         ` Xin Zhao
2025-11-26 16:37           ` Tejun Heo

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=2025112654-shaping-undoing-afe4@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