Skip to content

Commit 41f63c5

Browse files
committed
workqueue: use mod_delayed_work() instead of cancel + queue
Convert delayed_work users doing cancel_delayed_work() followed by queue_delayed_work() to mod_delayed_work(). Most conversions are straight-forward. Ones worth mentioning are, * drivers/edac/edac_mc.c: edac_mc_workq_setup() converted to always use mod_delayed_work() and cancel loop in edac_mc_reset_delay_period() is dropped. * drivers/platform/x86/thinkpad_acpi.c: No need to remember whether watchdog is active or not. @fan_watchdog_active and related code dropped. * drivers/power/charger-manager.c: Seemingly a lot of delayed_work_pending() abuse going on here. [delayed_]work_pending() are unsynchronized and racy when used like this. I converted one instance in fullbatt_handler(). Please conver the rest so that it invokes workqueue APIs for the intended target state rather than trying to game work item pending state transitions. e.g. if timer should be modified - call mod_delayed_work(), canceled - call cancel_delayed_work[_sync](). * drivers/thermal/thermal_sys.c: thermal_zone_device_set_polling() simplified. Note that round_jiffies() calls in this function are meaningless. round_jiffies() work on absolute jiffies not delta delay used by delayed_work. v2: Tomi pointed out that __cancel_delayed_work() users can't be safely converted to mod_delayed_work(). They could be calling it from irq context and if that happens while delayed_work_timer_fn() is running, it could deadlock. __cancel_delayed_work() users are dropped. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Anton Vorontsov <cbouatmailru@gmail.com> Acked-by: David Howells <dhowells@redhat.com> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Doug Thompson <dougthompson@xmission.com> Cc: David Airlie <airlied@linux.ie> Cc: Roland Dreier <roland@kernel.org> Cc: "John W. Linville" <linville@tuxdriver.com> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Len Brown <len.brown@intel.com> Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: Johannes Berg <johannes@sipsolutions.net>
1 parent 8376fe2 commit 41f63c5

18 files changed

Lines changed: 41 additions & 105 deletions

File tree

‎block/genhd.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,10 +1534,8 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask)
15341534

15351535
spin_lock_irq(&ev->lock);
15361536
ev->clearing |= mask;
1537-
if (!ev->block) {
1538-
cancel_delayed_work(&ev->dwork);
1539-
queue_delayed_work(system_nrt_freezable_wq, &ev->dwork, 0);
1540-
}
1537+
if (!ev->block)
1538+
mod_delayed_work(system_nrt_freezable_wq, &ev->dwork, 0);
15411539
spin_unlock_irq(&ev->lock);
15421540
}
15431541

‎drivers/edac/edac_mc.c‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec)
538538
return;
539539

540540
INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function);
541-
queue_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
541+
mod_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
542542
}
543543

544544
/*
@@ -578,21 +578,6 @@ void edac_mc_reset_delay_period(int value)
578578

579579
mutex_lock(&mem_ctls_mutex);
580580

581-
/* scan the list and turn off all workq timers, doing so under lock
582-
*/
583-
list_for_each(item, &mc_devices) {
584-
mci = list_entry(item, struct mem_ctl_info, link);
585-
586-
if (mci->op_state == OP_RUNNING_POLL)
587-
cancel_delayed_work(&mci->work);
588-
}
589-
590-
mutex_unlock(&mem_ctls_mutex);
591-
592-
593-
/* re-walk the list, and reset the poll delay */
594-
mutex_lock(&mem_ctls_mutex);
595-
596581
list_for_each(item, &mc_devices) {
597582
mci = list_entry(item, struct mem_ctl_info, link);
598583

‎drivers/infiniband/core/addr.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,11 @@ static void set_timeout(unsigned long time)
152152
{
153153
unsigned long delay;
154154

155-
cancel_delayed_work(&work);
156-
157155
delay = time - jiffies;
158156
if ((long)delay <= 0)
159157
delay = 1;
160158

161-
queue_delayed_work(addr_wq, &work, delay);
159+
mod_delayed_work(addr_wq, &work, delay);
162160
}
163161

164162
static void queue_req(struct addr_req *req)

‎drivers/infiniband/hw/nes/nes_hw.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,11 +2679,9 @@ static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
26792679
}
26802680
}
26812681
if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_SFP_D) {
2682-
if (nesdev->link_recheck)
2683-
cancel_delayed_work(&nesdev->work);
26842682
nesdev->link_recheck = 1;
2685-
schedule_delayed_work(&nesdev->work,
2686-
NES_LINK_RECHECK_DELAY);
2683+
mod_delayed_work(system_wq, &nesdev->work,
2684+
NES_LINK_RECHECK_DELAY);
26872685
}
26882686
}
26892687

‎drivers/infiniband/hw/nes/nes_nic.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,9 @@ static int nes_netdev_open(struct net_device *netdev)
243243

244244
spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
245245
if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_SFP_D) {
246-
if (nesdev->link_recheck)
247-
cancel_delayed_work(&nesdev->work);
248246
nesdev->link_recheck = 1;
249-
schedule_delayed_work(&nesdev->work, NES_LINK_RECHECK_DELAY);
247+
mod_delayed_work(system_wq, &nesdev->work,
248+
NES_LINK_RECHECK_DELAY);
250249
}
251250
spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
252251

‎drivers/net/wireless/ipw2x00/ipw2100.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,8 +2180,7 @@ static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
21802180

21812181
/* Make sure the RF Kill check timer is running */
21822182
priv->stop_rf_kill = 0;
2183-
cancel_delayed_work(&priv->rf_kill);
2184-
schedule_delayed_work(&priv->rf_kill, round_jiffies_relative(HZ));
2183+
mod_delayed_work(system_wq, &priv->rf_kill, round_jiffies_relative(HZ));
21852184
}
21862185

21872186
static void send_scan_event(void *data)
@@ -4321,9 +4320,8 @@ static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
43214320
"disabled by HW switch\n");
43224321
/* Make sure the RF_KILL check timer is running */
43234322
priv->stop_rf_kill = 0;
4324-
cancel_delayed_work(&priv->rf_kill);
4325-
schedule_delayed_work(&priv->rf_kill,
4326-
round_jiffies_relative(HZ));
4323+
mod_delayed_work(system_wq, &priv->rf_kill,
4324+
round_jiffies_relative(HZ));
43274325
} else
43284326
schedule_reset(priv);
43294327
}

‎drivers/net/wireless/zd1211rw/zd_usb.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,7 @@ void zd_usb_reset_rx_idle_timer(struct zd_usb *usb)
11641164
{
11651165
struct zd_usb_rx *rx = &usb->rx;
11661166

1167-
cancel_delayed_work(&rx->idle_work);
1168-
queue_delayed_work(zd_workqueue, &rx->idle_work, ZD_RX_IDLE_INTERVAL);
1167+
mod_delayed_work(zd_workqueue, &rx->idle_work, ZD_RX_IDLE_INTERVAL);
11691168
}
11701169

11711170
static inline void init_usb_interrupt(struct zd_usb *usb)

‎drivers/platform/x86/thinkpad_acpi.c‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7682,25 +7682,15 @@ static int fan_set_speed(int speed)
76827682

76837683
static void fan_watchdog_reset(void)
76847684
{
7685-
static int fan_watchdog_active;
7686-
76877685
if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
76887686
return;
76897687

7690-
if (fan_watchdog_active)
7691-
cancel_delayed_work(&fan_watchdog_task);
7692-
76937688
if (fan_watchdog_maxinterval > 0 &&
7694-
tpacpi_lifecycle != TPACPI_LIFE_EXITING) {
7695-
fan_watchdog_active = 1;
7696-
if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task,
7697-
msecs_to_jiffies(fan_watchdog_maxinterval
7698-
* 1000))) {
7699-
pr_err("failed to queue the fan watchdog, "
7700-
"watchdog will not trigger\n");
7701-
}
7702-
} else
7703-
fan_watchdog_active = 0;
7689+
tpacpi_lifecycle != TPACPI_LIFE_EXITING)
7690+
mod_delayed_work(tpacpi_wq, &fan_watchdog_task,
7691+
msecs_to_jiffies(fan_watchdog_maxinterval * 1000));
7692+
else
7693+
cancel_delayed_work(&fan_watchdog_task);
77047694
}
77057695

77067696
static void fan_watchdog_fire(struct work_struct *ignored)

‎drivers/power/charger-manager.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,8 @@ static void _setup_polling(struct work_struct *work)
509509
if (!delayed_work_pending(&cm_monitor_work) ||
510510
(delayed_work_pending(&cm_monitor_work) &&
511511
time_after(next_polling, _next_polling))) {
512-
cancel_delayed_work_sync(&cm_monitor_work);
513512
next_polling = jiffies + polling_jiffy;
514-
queue_delayed_work(cm_wq, &cm_monitor_work, polling_jiffy);
513+
mod_delayed_work(cm_wq, &cm_monitor_work, polling_jiffy);
515514
}
516515

517516
out:
@@ -546,10 +545,8 @@ static void fullbatt_handler(struct charger_manager *cm)
546545
if (cm_suspended)
547546
device_set_wakeup_capable(cm->dev, true);
548547

549-
if (delayed_work_pending(&cm->fullbatt_vchk_work))
550-
cancel_delayed_work(&cm->fullbatt_vchk_work);
551-
queue_delayed_work(cm_wq, &cm->fullbatt_vchk_work,
552-
msecs_to_jiffies(desc->fullbatt_vchkdrop_ms));
548+
mod_delayed_work(cm_wq, &cm->fullbatt_vchk_work,
549+
msecs_to_jiffies(desc->fullbatt_vchkdrop_ms));
553550
cm->fullbatt_vchk_jiffies_at = jiffies + msecs_to_jiffies(
554551
desc->fullbatt_vchkdrop_ms);
555552

‎drivers/power/ds2760_battery.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ static void ds2760_battery_external_power_changed(struct power_supply *psy)
355355

356356
dev_dbg(di->dev, "%s\n", __func__);
357357

358-
cancel_delayed_work(&di->monitor_work);
359-
queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10);
358+
mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10);
360359
}
361360

362361

@@ -401,8 +400,7 @@ static void ds2760_battery_set_charged(struct power_supply *psy)
401400

402401
/* postpone the actual work by 20 secs. This is for debouncing GPIO
403402
* signals and to let the current value settle. See AN4188. */
404-
cancel_delayed_work(&di->set_charged_work);
405-
queue_delayed_work(di->monitor_wqueue, &di->set_charged_work, HZ * 20);
403+
mod_delayed_work(di->monitor_wqueue, &di->set_charged_work, HZ * 20);
406404
}
407405

408406
static int ds2760_battery_get_property(struct power_supply *psy,
@@ -616,8 +614,7 @@ static int ds2760_battery_resume(struct platform_device *pdev)
616614
di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
617615
power_supply_changed(&di->bat);
618616

619-
cancel_delayed_work(&di->monitor_work);
620-
queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
617+
mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
621618

622619
return 0;
623620
}

0 commit comments

Comments
 (0)