tty: Convert from tasklet to BH workqueue
Subsystems (3)
PATCH 1/1 tty: Convert from tasklet to BH workqueue
The only generic interface to execute asynchronously in the BH context is tasklet; however, it's marked deprecated and has some design flaws. To replace tasklets, BH workqueue support was recently added. A BH workqueue behaves similarly to regular workqueues except that the queued work items are executed in the BH context.
This patch converts drivers/tty/* from tasklet to BH workqueue.
Based on the work done by Tejun Heo <[email protected]>
Branch: https://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-6.10
--- drivers/tty/ipwireless/hardware.c | 15 +++--- drivers/tty/serial/atmel_serial.c | 79 ++++++++++++++++--------------- drivers/tty/serial/timbuart.c | 19 ++++---- drivers/tty/vt/keyboard.c | 34 ++++++------- 4 files changed, 76 insertions(+), 71 deletions(-)
drivers/tty/ipwireless/hardware.c +8 -7
@@ -22,6 +22,7 @@#include <linux/kernel.h> #include <linux/list.h> #include <linux/slab.h> +#include <linux/workqueue.h> #include "hardware.h" #include "setup_protocol.h"
@@ -275,7 +276,7 @@ struct ipw_hardware {unsigned int control_lines[NL_NUM_OF_ADDRESSES ];struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES ]; -struct tasklet_struct tasklet; +struct work_struct work;/* The handle for the network layer, for the sending of events to it. */ struct ipw_network *network;
@@ -1006,9 +1007,9 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)/* * Send and receive all queued packets. */ -static void ipwireless_do_tasklet (struct tasklet_struct *t) +static void ipwireless_do_work (struct work_struct *t) { -struct ipw_hardware *hw =from_tasklet (hw, t, tasklet); +struct ipw_hardware *hw =from_work (hw, t, work);unsigned long flags;spin_lock_irqsave (&hw->lock, flags);
@@ -1084,7 +1085,7 @@ static irqreturn_t ipwireless_handle_v1_interrupt(int irq, }if (ack !=0 ) {outw (ack, hw->base_port +IOIR ); -tasklet_schedule (&hw->tasklet); +queue_work (system_bh_wq, &hw->work); }return IRQ_HANDLED ; }
@@ -1189,7 +1190,7 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,acknowledge_pcmcia_interrupt (hw);if (tx || rx) -tasklet_schedule (&hw->tasklet); +queue_work (system_bh_wq, &hw->work);else if (!rx_repeat) {if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {if (hw->serial_number_detected)
@@ -1635,7 +1636,7 @@ struct ipw_hardware *ipwireless_hardware_create(void)INIT_LIST_HEAD (&hw->rx_queue);INIT_LIST_HEAD (&hw->rx_pool);spin_lock_init (&hw->lock); -tasklet_setup (&hw->tasklet, ipwireless_do_tasklet); +INIT_WORK (&hw->work, ipwireless_do_work);INIT_WORK (&hw->work_rx, ipw_receive_data_work);timer_setup (&hw->setup_timer, ipwireless_setup_timer,0 );
@@ -1703,7 +1704,7 @@ static void ipwireless_setup_timer(struct timer_list *t) hw->to_setup =1 ; hw->tx_ready =1 ;spin_unlock_irqrestore (&hw->lock, flags); -tasklet_schedule (&hw->tasklet); +queue_work (system_bh_wq, &hw->work); } mod_timer(&hw->setup_timer,
drivers/tty/serial/atmel_serial.c +40 -39
219 lines not on this page · raw message
drivers/tty/serial/timbuart.c +10 -9
@@ -18,12 +18,13 @@#include <linux/ioport.h> #include <linux/slab.h> #include <linux/module.h> +#include <linux/workqueue.h> #include "timbuart.h" struct timbuart_port {struct uart_port port; -struct tasklet_struct tasklet; +struct work_struct work;int usedma;u32 last_ier;struct platform_device *dev;
@@ -55,8 +56,8 @@ static void timbuart_start_tx(struct uart_port *port)struct timbuart_port *uart = container_of(port, struct timbuart_port, port); -/* do not transfer anything here -> fire off the tasklet */ -tasklet_schedule (&uart->tasklet); +/* do not transfer anything here -> fire off the task */ +queue_work (system_bh_wq, &uart->work); }static unsigned int timbuart_tx_empty (struct uart_port *port)
@@ -169,9 +170,9 @@ static void timbuart_handle_rx_port(struct uart_port *port, u32 isr, u32 *ier)dev_dbg (port->dev,"%s - leaving\n" , __func__); } -static void timbuart_tasklet (struct tasklet_struct *t) +static void timbuart_work (struct work_struct *t) { -struct timbuart_port *uart =from_tasklet (uart, t, tasklet); +struct timbuart_port *uart =from_work (uart, t, work);u32 isr, ier =0 ;uart_port_lock (&uart->port);
@@ -350,11 +351,11 @@ static irqreturn_t timbuart_handleinterrupt(int irq, void *devid)if (ioread8 (uart->port.membase +TIMBUART_IPR )) { uart->last_ier =ioread32 (uart->port.membase +TIMBUART_IER ); -/* disable interrupts, the tasklet enables them again */ +/* disable interrupts, the task enables them again */ iowrite32 (0 , uart->port.membase +TIMBUART_IER );/* fire off bottom half */ -tasklet_schedule (&uart->tasklet); +queue_work (system_bh_wq, &uart->work);return IRQ_HANDLED ; }else
@@ -448,7 +449,7 @@ static int timbuart_probe(struct platform_device *dev) } uart->port.irq = irq; -tasklet_setup (&uart->tasklet, timbuart_tasklet); +INIT_WORK (&uart->work, timbuart_work); err =uart_register_driver (&timbuart_driver);if (err)
@@ -477,7 +478,7 @@ static void timbuart_remove(struct platform_device *dev) {struct timbuart_port *uart =platform_get_drvdata (dev); -tasklet_kill (&uart->tasklet); +cancel_work_sync (&uart->work);uart_remove_one_port (&timbuart_driver, &uart->port);uart_unregister_driver (&timbuart_driver);kfree (uart);
drivers/tty/vt/keyboard.c +18 -16
@@ -46,6 +46,7 @@#include <linux/tty.h> #include <linux/uaccess.h> #include <linux/vt_kern.h> +#include <linux/workqueue.h> #include <asm/irq_regs.h>
@@ -131,8 +132,8 @@ static const unsigned char max_vals[] = {static const int NR_TYPES =ARRAY_SIZE (max_vals); -static void kbd_bh (struct tasklet_struct *unused); -static DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh); +static void kbd_bh (struct work_struct *unused); +static DECLARE_WORK(keyboard_work, kbd_bh);static struct input_handler kbd_handler;static DEFINE_SPINLOCK (kbd_event_lock);
@@ -379,7 +380,7 @@ static void to_utf8(struct vc_data *vc, uint c)/* FIXME: review locking for vt.c callers */ static void set_leds (void ) { -tasklet_schedule (&keyboard_tasklet); +queue_work (system_bh_wq, &keyboard_work); }/*
@@ -1031,12 +1032,12 @@ static int kbd_led_trigger_activate(struct led_classdev *cdev)struct kbd_led_trigger *trigger = container_of(cdev->trigger, struct kbd_led_trigger, trigger); -tasklet_disable (&keyboard_tasklet); +disable_work_sync (&keyboard_work);if (ledstate !=-1U )led_trigger_event (&trigger->trigger, ledstate & trigger->mask ?LED_FULL :LED_OFF ); -tasklet_enable (&keyboard_tasklet); +enable_and_queue_work (system_bh_wq, &keyboard_work);return 0 ; }
@@ -1247,12 +1248,13 @@ void vt_kbd_con_stop(unsigned int console) }/* -* This is the tasklet that updates LED state of LEDs using standard -* keyboard triggers. The reason we use tasklet is that we need to -* handle the scenario when keyboard handler is not registered yet -* but we already getting updates from the VT to update led state. +* This is the task that updates LED state of LEDs using standard +* keyboard triggers. The reason we use workqueue is that we need +* to handle the scenario when keyboard handler is not registered +* yet but we already getting updates from the VT to update led +* state. */ -static void kbd_bh (struct tasklet_struct *unused) +static void kbd_bh (struct work_struct *unused) {unsigned int leds;unsigned long flags;
@@ -1544,7 +1546,7 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,spin_unlock (&kbd_event_lock); -tasklet_schedule (&keyboard_tasklet); +queue_work (system_bh_wq, &keyboard_work); do_poke_blanked_console =1 ;schedule_console_callback (); }
@@ -1616,12 +1618,12 @@ static void kbd_disconnect(struct input_handle *handle)*/ static void kbd_start (struct input_handle *handle) { -tasklet_disable (&keyboard_tasklet); +disable_work_sync (&keyboard_work);if (ledstate !=-1U )kbd_update_leds_helper (handle, &ledstate); -tasklet_enable (&keyboard_tasklet); +enable_and_queue_work (system_bh_wq, &keyboard_work); }static const struct input_device_id kbd_ids[] = {
@@ -1671,8 +1673,8 @@ int __init kbd_init(void)if (error)return error; -tasklet_enable (&keyboard_tasklet); -tasklet_schedule (&keyboard_tasklet); +enable_and_queue_work (system_bh_wq, &keyboard_work); +queue_work (system_bh_wq, &keyboard_work);return 0 ; }
@@ -2233,7 +2235,7 @@ void vt_reset_keyboard(unsigned int console) kb->ledmode =LED_SHOW_FLAGS ; kb->ledflagstate = kb->default_ledflagstate;spin_unlock (&led_lock); -/* do not do set_leds here because this causes an endless tasklet loop +/* do not do set_leds here because this causes an endless loop when the keyboard hasn't been initialized yet */ spin_unlock_irqrestore (&kbd_event_lock, flags); }
Signature · 1 line
2.17.1
Jiri Slaby
maintainerQuoted 11 lines · Allen Pais
The only generic interface to execute asynchronously in the BH context is tasklet; however, it's marked deprecated and has some design flaws. To replace tasklets, BH workqueue support was recently added. A BH workqueue behaves similarly to regular workqueues except that the queued work items are executed in the BH context.
This patch converts
drivers/tty/*from tasklet to BH workqueue.Based on the work done by Tejun Heo <[email protected]>
Branch: https://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-6.10
Quoted 6 lines
Signed-off-by Allen Pais <[email protected]>--- drivers/tty/ipwireless/hardware.c | 15 +++--- drivers/tty/serial/atmel_serial.c | 79 ++++++++++++++++--------------- drivers/tty/serial/timbuart.c | 19 ++++---- drivers/tty/vt/keyboard.c | 34 ++++++-------
Could you CC maintainers of the drivers?
Signature · 2 lines
js suse labs
Jiri Slaby
maintainerQuoted 7 lines · Allen Pais
The only generic interface to execute asynchronously in the BH context is tasklet; however, it's marked deprecated and has some design flaws. To replace tasklets, BH workqueue support was recently added. A BH workqueue behaves similarly to regular workqueues except that the queued work items are executed in the BH context.
This patch converts
drivers/tty/*from tasklet to BH workqueue.
Quickly looking into the changes, could you also elaborate why not to convert most (all?) of them to (non-BH) wq? Or threaded IRQs. Much of the code comes from the pre-WQ era.
thanks,
Signature · 2 lines
js suse labs
Quoted 6 lines
Quoted 6 lines
The only generic interface to execute asynchronously in the BH context is tasklet; however, it's marked deprecated and has some design flaws. To replace tasklets, BH workqueue support was recently added. A BH workqueue behaves similarly to regular workqueues except that the queued work items are executed in the BH context.
Quoted 6 lines
Quoted 1 line
This patch converts
drivers/tty/*from tasklet to BH workqueue.Quickly looking into the changes, could you also elaborate why not to convert most (all?) of them to (non-BH) wq? Or threaded IRQs. Much of the code comes from the pre-WQ era.
You are right. The idea I had was to convert every instance of tasklet to
bh workqueues in the kernel. I will send out a v2, which will use threaded IRQ's.
Thanks.