All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] RT scheduling policies for workqueues
@ 2022-03-23 14:55 Rasmus Villemoes
  2022-03-23 14:55 ` [RFC PATCH 1/2] workqueue: allow use of realtime scheduling policies Rasmus Villemoes
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Rasmus Villemoes @ 2022-03-23 14:55 UTC (permalink / raw)
  To: Tejun Heo, Lai Jiangshan, linux-kernel
  Cc: André Pribil, Steven Walter, Oleksij Rempel,
	Esben Haabendal, Jiri Slaby, Pengutronix Kernel Team,
	Peter Hurley, linux-rt-users, Rasmus Villemoes

This RFC is motivated by an old problem in the tty layer. Ever since
commit a9c3f68f3cd8 (tty: Fix low_latency BUG), use of UART for
real-time applications has been problematic. Even if both the
application itself and the irq thread are set to SCHED_FIFO, the fact
that the flush_to_ldisc work is scheduled on the generic and global
system_unbound_wq (with all workers running at normal scheduling
priority) means that UART RX can suffer unbounded latency.

This is far from the first time this has come up [1] [2] [3], but so
far no solution acceptable by mainline has been found.

I have been playing around with a solution that would (depending on a
tty.rx_worker module parameter) create a kthread_worker per port,
embed a 'struct kthread_work' alongside the 'struct work_struct' in
struct tty_bufhead, and then choose between the current queue_work()
and kthread_queue_work() based on whether buf->kworker is NULL or
not. That works, but is a bit cumbersome for the application, since it
needs to traverse all of /proc to find the appropriate kthread and set
its priority after opening the tty. It's also not a very pretty
solution.

So, taking a cue from something Linus said in the [2] thread, this is
an attempt at keeping the use of workqueues. A WQ_HIGHPRI, aka nice
-19, workqueue is not enough for RT guarantees. So this extends struct
workqueue_attrs by an 'int policy', allowing userspace via the sysfs
interface to choose, say, SCHED_FIFO 37, for a given workqueue.

This is obviously not for merging as-is, but it is working code that
I've tested would solve the problem we're having (with the few rather
trivial changes in the tty layer, which are not really worth spelling
out here). But before polishing this, I'd like to know if anything
like this has any chance of making it to mainline.



[1] https://lore.kernel.org/linux-rt-users/20180718164958.l3f4ajloobdkp5tz@linutronix.de/T/
[2] https://lore.kernel.org/lkml/20190110101232.9398-1-o.rempel@pengutronix.de/
[3] https://www.spinics.net/lists/linux-serial/msg17782.html


Rasmus Villemoes (2):
  workqueue: allow use of realtime scheduling policies
  workqueue: update sysfs handlers, allow setting RT policies

 include/linux/workqueue.h | 17 +++++++--
 kernel/workqueue.c        | 74 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 80 insertions(+), 11 deletions(-)

-- 
2.31.1


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

end of thread, other threads:[~2022-04-06 13:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 14:55 [RFC PATCH 0/2] RT scheduling policies for workqueues Rasmus Villemoes
2022-03-23 14:55 ` [RFC PATCH 1/2] workqueue: allow use of realtime scheduling policies Rasmus Villemoes
2022-03-23 14:56 ` [RFC PATCH 2/2] workqueue: update sysfs handlers, allow setting RT policies Rasmus Villemoes
2022-03-28 10:05 ` [RFC PATCH 0/2] RT scheduling policies for workqueues Sebastian Andrzej Siewior
2022-03-28 10:09   ` Marc Kleine-Budde
2022-03-28 17:39     ` Tejun Heo
2022-03-28 18:07       ` Marc Kleine-Budde
2022-03-29  6:30       ` Sebastian Andrzej Siewior
2022-03-29  8:33         ` Rasmus Villemoes
2022-03-29 16:57           ` Tejun Heo
2022-04-01  9:21           ` Sebastian Andrzej Siewior
2022-04-06 10:00             ` Rasmus Villemoes

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.