Skip to content

Commit 91b7450

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: remove in_workqueue_context() workqueue: Clarify that schedule_on_each_cpu is synchronous memory_hotplug: drop spurious calls to flush_scheduled_work() shpchp: update workqueue usage pciehp: update workqueue usage isdn/eicon: don't call flush_scheduled_work() from diva_os_remove_soft_isr() workqueue: add and use WQ_MEM_RECLAIM flag workqueue: fix HIGHPRI handling in keep_working() workqueue: add queue_work and activate_work trace points workqueue: prepare for more tracepoints workqueue: implement flush[_delayed]_work_sync() workqueue: factor out start_flush_work() workqueue: cleanup flush/cancel functions workqueue: implement alloc_ordered_workqueue() Fix up trivial conflict in fs/gfs2/main.c as per Tejun
2 parents 04cc697 + daaae6b commit 91b7450

17 files changed

Lines changed: 363 additions & 218 deletions

File tree

‎Documentation/workqueue.txt‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ resources, scheduled and executed.
196196
suspend operations. Work items on the wq are drained and no
197197
new work item starts execution until thawed.
198198

199-
WQ_RESCUER
199+
WQ_MEM_RECLAIM
200200

201201
All wq which might be used in the memory reclaim paths _MUST_
202-
have this flag set. This reserves one worker exclusively for
203-
the execution of this wq under memory pressure.
202+
have this flag set. The wq is guaranteed to have at least one
203+
execution context regardless of memory pressure.
204204

205205
WQ_HIGHPRI
206206

@@ -356,24 +356,25 @@ If q1 has WQ_CPU_INTENSIVE set,
356356

357357
6. Guidelines
358358

359-
* Do not forget to use WQ_RESCUER if a wq may process work items which
360-
are used during memory reclaim. Each wq with WQ_RESCUER set has one
361-
rescuer thread reserved for it. If there is dependency among
362-
multiple work items used during memory reclaim, they should be
363-
queued to separate wq each with WQ_RESCUER.
359+
* Do not forget to use WQ_MEM_RECLAIM if a wq may process work items
360+
which are used during memory reclaim. Each wq with WQ_MEM_RECLAIM
361+
set has an execution context reserved for it. If there is
362+
dependency among multiple work items used during memory reclaim,
363+
they should be queued to separate wq each with WQ_MEM_RECLAIM.
364364

365365
* Unless strict ordering is required, there is no need to use ST wq.
366366

367367
* Unless there is a specific need, using 0 for @max_active is
368368
recommended. In most use cases, concurrency level usually stays
369369
well under the default limit.
370370

371-
* A wq serves as a domain for forward progress guarantee (WQ_RESCUER),
372-
flush and work item attributes. Work items which are not involved
373-
in memory reclaim and don't need to be flushed as a part of a group
374-
of work items, and don't require any special attribute, can use one
375-
of the system wq. There is no difference in execution
376-
characteristics between using a dedicated wq and a system wq.
371+
* A wq serves as a domain for forward progress guarantee
372+
(WQ_MEM_RECLAIM, flush and work item attributes. Work items which
373+
are not involved in memory reclaim and don't need to be flushed as a
374+
part of a group of work items, and don't require any special
375+
attribute, can use one of the system wq. There is no difference in
376+
execution characteristics between using a dedicated wq and a system
377+
wq.
377378

378379
* Unless work items are expected to consume a huge amount of CPU
379380
cycles, using a bound wq is usually beneficial due to the increased

‎drivers/ata/libata-sff.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3335,7 +3335,7 @@ void ata_sff_port_init(struct ata_port *ap)
33353335

33363336
int __init ata_sff_init(void)
33373337
{
3338-
ata_sff_wq = alloc_workqueue("ata_sff", WQ_RESCUER, WQ_MAX_ACTIVE);
3338+
ata_sff_wq = alloc_workqueue("ata_sff", WQ_MEM_RECLAIM, WQ_MAX_ACTIVE);
33393339
if (!ata_sff_wq)
33403340
return -ENOMEM;
33413341

‎drivers/isdn/hardware/eicon/divasmain.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <asm/uaccess.h>
1616
#include <asm/io.h>
1717
#include <linux/ioport.h>
18-
#include <linux/workqueue.h>
1918
#include <linux/pci.h>
2019
#include <linux/interrupt.h>
2120
#include <linux/list.h>
@@ -546,7 +545,6 @@ void diva_os_remove_soft_isr(diva_os_soft_isr_t * psoft_isr)
546545
void *mem;
547546

548547
tasklet_kill(&pdpc->divas_task);
549-
flush_scheduled_work();
550548
mem = psoft_isr->object;
551549
psoft_isr->object = NULL;
552550
diva_os_free(0, mem);

‎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
}

‎drivers/pci/hotplug/shpchp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/delay.h>
3636
#include <linux/sched.h> /* signal_pending(), struct timer_list */
3737
#include <linux/mutex.h>
38+
#include <linux/workqueue.h>
3839

3940
#if !defined(MODULE)
4041
#define MY_NAME "shpchp"
@@ -46,6 +47,7 @@ extern int shpchp_poll_mode;
4647
extern int shpchp_poll_time;
4748
extern int shpchp_debug;
4849
extern struct workqueue_struct *shpchp_wq;
50+
extern struct workqueue_struct *shpchp_ordered_wq;
4951

5052
#define dbg(format, arg...) \
5153
do { \

‎drivers/pci/hotplug/shpchp_core.c‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
#include <linux/types.h>
3434
#include <linux/slab.h>
3535
#include <linux/pci.h>
36-
#include <linux/workqueue.h>
3736
#include "shpchp.h"
3837

3938
/* Global variables */
4039
int shpchp_debug;
4140
int shpchp_poll_mode;
4241
int shpchp_poll_time;
4342
struct workqueue_struct *shpchp_wq;
43+
struct workqueue_struct *shpchp_ordered_wq;
4444

4545
#define DRIVER_VERSION "0.4"
4646
#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
@@ -174,8 +174,8 @@ void cleanup_slots(struct controller *ctrl)
174174
slot = list_entry(tmp, struct slot, slot_list);
175175
list_del(&slot->slot_list);
176176
cancel_delayed_work(&slot->work);
177-
flush_scheduled_work();
178177
flush_workqueue(shpchp_wq);
178+
flush_workqueue(shpchp_ordered_wq);
179179
pci_hp_deregister(slot->hotplug_slot);
180180
}
181181
}
@@ -360,16 +360,32 @@ static int __init shpcd_init(void)
360360
{
361361
int retval = 0;
362362

363+
shpchp_wq = alloc_ordered_workqueue("shpchp", 0);
364+
if (!shpchp_wq)
365+
return -ENOMEM;
366+
367+
shpchp_ordered_wq = alloc_ordered_workqueue("shpchp_ordered", 0);
368+
if (!shpchp_ordered_wq) {
369+
destroy_workqueue(shpchp_wq);
370+
return -ENOMEM;
371+
}
372+
363373
retval = pci_register_driver(&shpc_driver);
364374
dbg("%s: pci_register_driver = %d\n", __func__, retval);
365375
info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
376+
if (retval) {
377+
destroy_workqueue(shpchp_ordered_wq);
378+
destroy_workqueue(shpchp_wq);
379+
}
366380
return retval;
367381
}
368382

369383
static void __exit shpcd_cleanup(void)
370384
{
371385
dbg("unload_shpchpd()\n");
372386
pci_unregister_driver(&shpc_driver);
387+
destroy_workqueue(shpchp_ordered_wq);
388+
destroy_workqueue(shpchp_wq);
373389
info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
374390
}
375391

‎drivers/pci/hotplug/shpchp_ctrl.c‎

Lines changed: 3 additions & 4 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 "shpchp.h"
3837

@@ -52,7 +51,7 @@ static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
5251
info->p_slot = p_slot;
5352
INIT_WORK(&info->work, interrupt_event_handler);
5453

55-
schedule_work(&info->work);
54+
queue_work(shpchp_wq, &info->work);
5655

5756
return 0;
5857
}
@@ -457,7 +456,7 @@ void shpchp_queue_pushbutton_work(struct work_struct *work)
457456
kfree(info);
458457
goto out;
459458
}
460-
queue_work(shpchp_wq, &info->work);
459+
queue_work(shpchp_ordered_wq, &info->work);
461460
out:
462461
mutex_unlock(&p_slot->lock);
463462
}
@@ -505,7 +504,7 @@ static void handle_button_press_event(struct slot *p_slot)
505504
p_slot->hpc_ops->green_led_blink(p_slot);
506505
p_slot->hpc_ops->set_attention_status(p_slot, 0);
507506

508-
schedule_delayed_work(&p_slot->work, 5*HZ);
507+
queue_delayed_work(shpchp_wq, &p_slot->work, 5*HZ);
509508
break;
510509
case BLINKINGOFF_STATE:
511510
case BLINKINGON_STATE:

0 commit comments

Comments
 (0)