Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: work_on_cpu: use in drivers/pci/pci-driver.c

This uses work_on_cpu(), rather than altering the cpumask of the
thread which we happen to be.

Note the cleanups:

1) I've removed the CONFIG_NUMA test, since dev_to_node() returns -1
for !CONFIG_NUMA anyway and the compiler will eliminate it.

2) No need to reset mempolicy to default (a bad idea anyway) since
work_on_cpu is run from a workqueue.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

authored by

Rusty Russell and committed by
Jesse Barnes
873392ca a79d682f

+32 -20
+32 -20
drivers/pci/pci-driver.c
··· 16 16 #include <linux/string.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/sched.h> 19 + #include <linux/cpu.h> 19 20 #include "pci.h" 20 21 21 22 /* ··· 186 185 return pci_match_id(drv->id_table, dev); 187 186 } 188 187 188 + struct drv_dev_and_id { 189 + struct pci_driver *drv; 190 + struct pci_dev *dev; 191 + const struct pci_device_id *id; 192 + }; 193 + 194 + static long local_pci_probe(void *_ddi) 195 + { 196 + struct drv_dev_and_id *ddi = _ddi; 197 + 198 + return ddi->drv->probe(ddi->dev, ddi->id); 199 + } 200 + 189 201 static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, 190 202 const struct pci_device_id *id) 191 203 { 192 - int error; 193 - #ifdef CONFIG_NUMA 194 - /* Execute driver initialization on node where the 195 - device's bus is attached to. This way the driver likely 196 - allocates its local memory on the right node without 197 - any need to change it. */ 198 - struct mempolicy *oldpol; 199 - cpumask_t oldmask = current->cpus_allowed; 200 - int node = dev_to_node(&dev->dev); 204 + int error, node; 205 + struct drv_dev_and_id ddi = { drv, dev, id }; 201 206 207 + /* Execute driver initialization on node where the device's 208 + bus is attached to. This way the driver likely allocates 209 + its local memory on the right node without any need to 210 + change it. */ 211 + node = dev_to_node(&dev->dev); 202 212 if (node >= 0) { 213 + int cpu; 203 214 node_to_cpumask_ptr(nodecpumask, node); 204 - set_cpus_allowed_ptr(current, nodecpumask); 205 - } 206 - /* And set default memory allocation policy */ 207 - oldpol = current->mempolicy; 208 - current->mempolicy = NULL; /* fall back to system default policy */ 209 - #endif 210 - error = drv->probe(dev, id); 211 - #ifdef CONFIG_NUMA 212 - set_cpus_allowed_ptr(current, &oldmask); 213 - current->mempolicy = oldpol; 214 - #endif 215 + 216 + get_online_cpus(); 217 + cpu = cpumask_any_and(nodecpumask, cpu_online_mask); 218 + if (cpu < nr_cpu_ids) 219 + error = work_on_cpu(cpu, local_pci_probe, &ddi); 220 + else 221 + error = local_pci_probe(&ddi); 222 + put_online_cpus(); 223 + } else 224 + error = local_pci_probe(&ddi); 215 225 return error; 216 226 } 217 227