Skip to content

Commit a827ea3

Browse files
committed
pciehp: update workqueue usage
* Rename pciehp_wq to pciehp_ordered_wq and add non-ordered pciehp_wq which is used instead of the system workqueue. This is to remove the use of flush_scheduled_work() which is deprecated and scheduled for removal. * With cmwq in place, there's no point in creating workqueues lazily. Create both pciehp_wq and pciehp_ordered_wq upfront. * Include workqueue.h from pciehp.h. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 7bf4a5d commit a827ea3

4 files changed

Lines changed: 24 additions & 25 deletions

File tree

‎drivers/pci/hotplug/pciehp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/sched.h> /* signal_pending() */
3737
#include <linux/pcieport_if.h>
3838
#include <linux/mutex.h>
39+
#include <linux/workqueue.h>
3940

4041
#define MY_NAME "pciehp"
4142

@@ -44,6 +45,7 @@ extern int pciehp_poll_time;
4445
extern int pciehp_debug;
4546
extern int pciehp_force;
4647
extern struct workqueue_struct *pciehp_wq;
48+
extern struct workqueue_struct *pciehp_ordered_wq;
4749

4850
#define dbg(format, arg...) \
4951
do { \

‎drivers/pci/hotplug/pciehp_core.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int pciehp_poll_mode;
4343
int pciehp_poll_time;
4444
int pciehp_force;
4545
struct workqueue_struct *pciehp_wq;
46+
struct workqueue_struct *pciehp_ordered_wq;
4647

4748
#define DRIVER_VERSION "0.4"
4849
#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
@@ -340,18 +341,33 @@ static int __init pcied_init(void)
340341
{
341342
int retval = 0;
342343

344+
pciehp_wq = alloc_workqueue("pciehp", 0, 0);
345+
if (!pciehp_wq)
346+
return -ENOMEM;
347+
348+
pciehp_ordered_wq = alloc_ordered_workqueue("pciehp_ordered", 0);
349+
if (!pciehp_ordered_wq) {
350+
destroy_workqueue(pciehp_wq);
351+
return -ENOMEM;
352+
}
353+
343354
pciehp_firmware_init();
344355
retval = pcie_port_service_register(&hpdriver_portdrv);
345356
dbg("pcie_port_service_register = %d\n", retval);
346357
info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
347-
if (retval)
358+
if (retval) {
359+
destroy_workqueue(pciehp_ordered_wq);
360+
destroy_workqueue(pciehp_wq);
348361
dbg("Failure to register service\n");
362+
}
349363
return retval;
350364
}
351365

352366
static void __exit pcied_cleanup(void)
353367
{
354368
dbg("unload_pciehpd()\n");
369+
destroy_workqueue(pciehp_ordered_wq);
370+
destroy_workqueue(pciehp_wq);
355371
pcie_port_service_unregister(&hpdriver_portdrv);
356372
info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
357373
}

‎drivers/pci/hotplug/pciehp_ctrl.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <linux/types.h>
3333
#include <linux/slab.h>
3434
#include <linux/pci.h>
35-
#include <linux/workqueue.h>
3635
#include "../pci.h"
3736
#include "pciehp.h"
3837

@@ -50,7 +49,7 @@ static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
5049
info->p_slot = p_slot;
5150
INIT_WORK(&info->work, interrupt_event_handler);
5251

53-
schedule_work(&info->work);
52+
queue_work(pciehp_wq, &info->work);
5453

5554
return 0;
5655
}
@@ -345,7 +344,7 @@ void pciehp_queue_pushbutton_work(struct work_struct *work)
345344
kfree(info);
346345
goto out;
347346
}
348-
queue_work(pciehp_wq, &info->work);
347+
queue_work(pciehp_ordered_wq, &info->work);
349348
out:
350349
mutex_unlock(&p_slot->lock);
351350
}
@@ -378,7 +377,7 @@ static void handle_button_press_event(struct slot *p_slot)
378377
if (ATTN_LED(ctrl))
379378
pciehp_set_attention_status(p_slot, 0);
380379

381-
schedule_delayed_work(&p_slot->work, 5*HZ);
380+
queue_delayed_work(pciehp_wq, &p_slot->work, 5*HZ);
382381
break;
383382
case BLINKINGOFF_STATE:
384383
case BLINKINGON_STATE:
@@ -440,7 +439,7 @@ static void handle_surprise_event(struct slot *p_slot)
440439
else
441440
p_slot->state = POWERON_STATE;
442441

443-
queue_work(pciehp_wq, &info->work);
442+
queue_work(pciehp_ordered_wq, &info->work);
444443
}
445444

446445
static void interrupt_event_handler(struct work_struct *work)

‎drivers/pci/hotplug/pciehp_hpc.c‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#include "../pci.h"
4242
#include "pciehp.h"
4343

44-
static atomic_t pciehp_num_controllers = ATOMIC_INIT(0);
45-
4644
static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value)
4745
{
4846
struct pci_dev *dev = ctrl->pcie->port;
@@ -805,8 +803,8 @@ static void pcie_cleanup_slot(struct controller *ctrl)
805803
{
806804
struct slot *slot = ctrl->slot;
807805
cancel_delayed_work(&slot->work);
808-
flush_scheduled_work();
809806
flush_workqueue(pciehp_wq);
807+
flush_workqueue(pciehp_ordered_wq);
810808
kfree(slot);
811809
}
812810

@@ -912,16 +910,6 @@ struct controller *pcie_init(struct pcie_device *dev)
912910
/* Disable sotfware notification */
913911
pcie_disable_notification(ctrl);
914912

915-
/*
916-
* If this is the first controller to be initialized,
917-
* initialize the pciehp work queue
918-
*/
919-
if (atomic_add_return(1, &pciehp_num_controllers) == 1) {
920-
pciehp_wq = create_singlethread_workqueue("pciehpd");
921-
if (!pciehp_wq)
922-
goto abort_ctrl;
923-
}
924-
925913
ctrl_info(ctrl, "HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
926914
pdev->vendor, pdev->device, pdev->subsystem_vendor,
927915
pdev->subsystem_device);
@@ -941,11 +929,5 @@ void pciehp_release_ctrl(struct controller *ctrl)
941929
{
942930
pcie_shutdown_notification(ctrl);
943931
pcie_cleanup_slot(ctrl);
944-
/*
945-
* If this is the last controller to be released, destroy the
946-
* pciehp work queue
947-
*/
948-
if (atomic_dec_and_test(&pciehp_num_controllers))
949-
destroy_workqueue(pciehp_wq);
950932
kfree(ctrl);
951933
}

0 commit comments

Comments
 (0)