]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: Add WQ_PERCPU to alloc_workqueue() users
authorMarco Crivellari <marco.crivellari@suse.com>
Fri, 7 Nov 2025 14:25:26 +0000 (15:25 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 29 Dec 2025 16:18:02 +0000 (10:18 -0600)
Currently work items enqueued by schedule_delayed_work() use "system_wq" (a
per-CPU wq), while queue_delayed_work() uses WORK_CPU_UNBOUND (used when a
CPU is not specified). The same applies to schedule_work() that is using
system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.  This
lack of consistency cannot be addressed without refactoring the API.

alloc_workqueue() treats all queues as per-CPU by default, while unbound
workqueues must opt-in via WQ_UNBOUND.

This default is suboptimal: most workloads benefit from unbound queues,
allowing the scheduler to place worker threads where they're needed and
reducing noise when CPUs are isolated.

This continues the effort to refactor workqueue APIs, which began with the
introduction of new workqueues and a new alloc_workqueue() flag in:

  128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
  930c2ea566af ("workqueue: Add new WQ_PERCPU flag")

Add WQ_PERCPU to explicitly request alloc_workqueue() to be per-CPU when
WQ_UNBOUND has not been specified.

With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND),
any alloc_workqueue() caller that doesn't explicitly specify WQ_UNBOUND
must now use WQ_PERCPU.

Once migration is complete, WQ_UNBOUND can be removed and unbound will
become the implicit default.

Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
[bhelgaas: squash similar commits]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20251107142526.234685-1-marco.crivellari@suse.com
Link: https://patch.msgid.link/20251107142835.237636-1-marco.crivellari@suse.com
Link: https://patch.msgid.link/20251107143108.240025-1-marco.crivellari@suse.com
Link: https://patch.msgid.link/20251107143335.242342-1-marco.crivellari@suse.com
Link: https://patch.msgid.link/20251107143624.244978-1-marco.crivellari@suse.com
drivers/pci/endpoint/functions/pci-epf-mhi.c
drivers/pci/endpoint/functions/pci-epf-ntb.c
drivers/pci/endpoint/functions/pci-epf-test.c
drivers/pci/endpoint/functions/pci-epf-vntb.c
drivers/pci/hotplug/pnv_php.c
drivers/pci/hotplug/shpchp_core.c

index 6643a88c7a0ce38161bc6253c09d29f1c36ba394..27de533f05716a83158dfe72af2bdf7a91dbba28 100644 (file)
@@ -686,7 +686,7 @@ static int pci_epf_mhi_dma_init(struct pci_epf_mhi *epf_mhi)
                goto err_release_tx;
        }
 
-       epf_mhi->dma_wq = alloc_workqueue("pci_epf_mhi_dma_wq", 0, 0);
+       epf_mhi->dma_wq = alloc_workqueue("pci_epf_mhi_dma_wq", WQ_PERCPU, 0);
        if (!epf_mhi->dma_wq) {
                ret = -ENOMEM;
                goto err_release_rx;
index e01a98e74d211174db3075c20457a3183f37e0a5..9ea8b57d69d7905063e6f4a0179616d9dd3815f5 100644 (file)
@@ -2124,8 +2124,8 @@ static int __init epf_ntb_init(void)
 {
        int ret;
 
-       kpcintb_workqueue = alloc_workqueue("kpcintb", WQ_MEM_RECLAIM |
-                                           WQ_HIGHPRI, 0);
+       kpcintb_workqueue = alloc_workqueue("kpcintb",
+                                   WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 0);
        ret = pci_epf_register_driver(&epf_ntb_driver);
        if (ret) {
                destroy_workqueue(kpcintb_workqueue);
index debd235253c5ba54eb8f06d13261c407ee3768ec..62804120cd79a7f4b31c473002e099d5b2612ba6 100644 (file)
@@ -1188,7 +1188,7 @@ static int __init pci_epf_test_init(void)
        int ret;
 
        kpcitest_workqueue = alloc_workqueue("kpcitest",
-                                            WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
+                                   WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 0);
        if (!kpcitest_workqueue) {
                pr_err("Failed to allocate the kpcitest work queue\n");
                return -ENOMEM;
index 3ecc5059f92b31de1f755bf2e7a22fd04741231e..a098727f784bd588d5306a1b68a4a64cac942fdb 100644 (file)
@@ -1651,8 +1651,8 @@ static int __init epf_ntb_init(void)
 {
        int ret;
 
-       kpcintb_workqueue = alloc_workqueue("kpcintb", WQ_MEM_RECLAIM |
-                                           WQ_HIGHPRI, 0);
+       kpcintb_workqueue = alloc_workqueue("kpcintb",
+                                   WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 0);
        ret = pci_epf_register_driver(&epf_ntb_driver);
        if (ret) {
                destroy_workqueue(kpcintb_workqueue);
index c5345bff9a5538480e53a079a325556207b91fe8..35f1758126c68bf8e85013b60e2093d694fef063 100644 (file)
@@ -802,7 +802,7 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
        }
 
        /* Allocate workqueue for this slot's interrupt handling */
-       php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name);
+       php_slot->wq = alloc_workqueue("pciehp-%s", WQ_PERCPU, 0, php_slot->name);
        if (!php_slot->wq) {
                SLOT_WARN(php_slot, "Cannot alloc workqueue\n");
                kfree(php_slot->name);
index 0c341453afc60574b015615c36d4101280123e1b..56308515ecbaf3450bfc21b17b7472eceb69b40b 100644 (file)
@@ -80,7 +80,8 @@ static int init_slots(struct controller *ctrl)
                slot->device = ctrl->slot_device_offset + i;
                slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i);
 
-               slot->wq = alloc_workqueue("shpchp-%d", 0, 0, slot->number);
+               slot->wq = alloc_workqueue("shpchp-%d", WQ_PERCPU, 0,
+                                          slot->number);
                if (!slot->wq) {
                        retval = -ENOMEM;
                        goto error_slot;