From patchwork Thu Aug 23 21:35:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 1369021 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 67A61DF2AB for ; Thu, 23 Aug 2012 21:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756941Ab2HWVfg (ORCPT ); Thu, 23 Aug 2012 17:35:36 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:43937 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754134Ab2HWVfe (ORCPT ); Thu, 23 Aug 2012 17:35:34 -0400 Received: by pbbrr13 with SMTP id rr13so2225435pbb.19 for ; Thu, 23 Aug 2012 14:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=fgt9bwHvtsMIZJBjOch932hiLAs1QkKqiEtDf4ZBTcE=; b=iXZZyp/oCLcQkbigSJV+gbnN8B6Pj4xBTx09243Duzx+Sk4lnF9zmbuEoHd/gV/CuO vJ5eEormZa1iqMK8G4/T5f8rm8YZML0A2J23EC+KSNMg4fIMmyAUL0MyTs32PHPfhei8 2FZWn+aN1xz0jeWYyCG9oNQ8FYok9+Tv0t7mUrehuEPr8E+n3hz64VyraR0UFuNrsOuU 0rcFBCKRk8XuOZNfnrjldUHaSTazrx9i2gCBZMRyzjj5JF+B0Uws1ZcDTVLlR8ZmVt2D 8UUn/1RP/4brK+tLMdv1R7IflIIojPK1O8caeIGDOfECGkz4Y/rM4mtBjW2ng8Zxy8D3 DTlg== Received: by 10.68.225.196 with SMTP id rm4mr7711407pbc.131.1345757733940; Thu, 23 Aug 2012 14:35:33 -0700 (PDT) Received: from google.com (wtj.mtv.corp.google.com [172.18.110.84]) by mx.google.com with ESMTPS id qb2sm5481686pbb.15.2012.08.23.14.35.31 (version=SSLv3 cipher=OTHER); Thu, 23 Aug 2012 14:35:32 -0700 (PDT) Date: Thu, 23 Aug 2012 14:35:29 -0700 From: Tejun Heo To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pci: rewrite pci_call_probe() to use workqueue instead of work_on_cpu() Message-ID: <20120823213529.GH14962@google.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_call_probe() uses work_on_cpu(), which creates and tears down a full kthread on each call, to invoke ->probe() on node local CPU for allocation affinity. The same goal can easily be achieved using a work item. This patch rewrites pci_call_probe() so that it uses a work item instead of work_on_cpu(). Note that the function is restructured for simplicity. This adds get/put_online_cpus() pair for devices without node but the overhead of doing so isn't anything material at this level. Signed-off-by: Tejun Heo --- I tested both paths but had to simulate device on foreign node. Thanks. drivers/pci/pci-driver.c | 48 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 5270f1a..554c15a 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -274,11 +274,14 @@ struct drv_dev_and_id { struct pci_driver *drv; struct pci_dev *dev; const struct pci_device_id *id; + struct work_struct work; + int error; }; -static long local_pci_probe(void *_ddi) +static void pci_probe_fn(struct work_struct *work) { - struct drv_dev_and_id *ddi = _ddi; + struct drv_dev_and_id *ddi = container_of(work, struct drv_dev_and_id, + work); struct device *dev = &ddi->dev->dev; int rc; @@ -298,33 +301,38 @@ static long local_pci_probe(void *_ddi) pm_runtime_set_suspended(dev); pm_runtime_put_noidle(dev); } - return rc; + + ddi->error = rc; } static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, const struct pci_device_id *id) { - int error, node; + int node; + int cpu = nr_cpu_ids; struct drv_dev_and_id ddi = { drv, dev, id }; - /* Execute driver initialization on node where the device's - bus is attached to. This way the driver likely allocates - its local memory on the right node without any need to - change it. */ - node = dev_to_node(&dev->dev); - if (node >= 0) { - int cpu; + /* + * Execute driver initialization on node where the device's bus is + * attached to. This way the driver likely allocates its local + * memory on the right node without any need to change it. + */ + get_online_cpus(); - get_online_cpus(); + node = dev_to_node(&dev->dev); + if (node >= 0) cpu = cpumask_any_and(cpumask_of_node(node), cpu_online_mask); - if (cpu < nr_cpu_ids) - error = work_on_cpu(cpu, local_pci_probe, &ddi); - else - error = local_pci_probe(&ddi); - put_online_cpus(); - } else - error = local_pci_probe(&ddi); - return error; + + if (cpu < nr_cpu_ids) { + INIT_WORK_ONSTACK(&ddi.work, pci_probe_fn); + schedule_work_on(cpu, &ddi.work); + flush_work(&ddi.work); + } else { + pci_probe_fn(&ddi.work); + } + + put_online_cpus(); + return ddi.error; } /**