From patchwork Wed Oct 17 23:40:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84A8C157A for ; Wed, 17 Oct 2018 23:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75891288D0 for ; Wed, 17 Oct 2018 23:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6757A288D2; Wed, 17 Oct 2018 23:40:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4BDA2886E for ; Wed, 17 Oct 2018 23:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbeJRHio (ORCPT ); Thu, 18 Oct 2018 03:38:44 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:46441 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHio (ORCPT ); Thu, 18 Oct 2018 03:38:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=hZy4Y3S5mpmGL40z0C9r2ScWz8pJ+lEmeb8abgmA+kY=; b=R/tg1bgGHRtD 2Zkvf5cNDELTLU2lNh0QfEEB+28/oxky7IToD2dcnBEKksJAh5uwhm5vx7+g/OnTLp6Htkz4AUxXQ M+MCCSn5LYZ4AOkBt6jq9MVB5yidcqgyMCUGCAAteNxkL6t7/ZTeIjzsBZ2XqAtmyC+uW9ZzhhyXk ZESZEPJ2bygKcG+Ef2lIYsgXHavmQMGmALcsPbpHUKDaa2LkFeKTdhS3X8Osg6h2I4IOuqD1lBN3p btoKihIw3rYsctpFxo1QEZkOEx88zzK7rXAal/4kMallcUIKAiDD7WW5aG2JbSmauduUm/YhvrHY6 cjw1bx1gObMFoNB0+JjcrA==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQQ-000Aga-Ij; Thu, 18 Oct 2018 01:40:27 +0200 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id A5272C0859; Thu, 18 Oct 2018 01:40:21 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Dan Williams Subject: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver Date: Wed, 17 Oct 2018 16:40:02 -0700 Message-Id: <20181017234006.124251-4-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00236273624828) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5vdKoF50dk5Pmr2Eh0KaytJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASiYf7H/yBdfVu6BXKOqolT9GfkLnpI 7Igpgzj0Fi/1kgTJsjWw5+0eZIpQIcK9yrSIoiC5DDnaemEOugg39OcBf2ZkFf0bc6TV99q4yFj4 jO7J//0XCxCMJn8bXo41UD0/WD7BAcwhXN3d5OI6tWyH6CLbyF0Zq4b1/7rjUzETJsEY2Io8tF+w JOqGSVax9Cm77niqGZoB5oiisgnJ8hVNJmO4hZrKar0rT3Fu0bhVQ+HVicDfSEki2HQjIzlgulSP bUMSEuFskSoX1rj3Ja6Rz+WIuiLxESilKevuzi8w8V+7HpiXZfFnrsvPrZTEk0NuHNilgcZwLgpa NcLUv7N+wU0sgWWGfvhiumCReJl2fvxcb3XRuJkRyiZZ6HPi7yzMODodi5MLJiAvrVIiQFNhU2e0 TG7gZrtHlR0mmB20Dn0dxFvNNB6n+asAMTtBlzFO/QhyCWC6YCpHNN+dHzcfet9WYpMedYGCnu86 NSYSBriPncBxOEAOQ+52ichbKZqDvZACTpnyVEv7sKwJuf990SV26BqP2cLMwD5eyGrPr/vYRygQ QDw2W1RvRSdcITq04npcDlKcRm8K6UCxnm/d1MHoSYXOgussFKMYrtx189kFIATR8ubvlbl2kpwD bZ3BRBZgCikvOAMF/4pY8933dflf9ntDT37Pcm6lRUBH+WE2OtkGzrUVx52MHuYfPexSk4m5wK8d LOpEo90vBDAk+W1qXhB/kaRrSe/aWhy/zVLO3HfZT/t5PEHawBxJ5/TDqcigOvSxdRnthmhn8Zn6 y90Pz+6rbRCCi63kWHnKnm/+2uO3if45J37r4Xo66cneNHk15VolAGHS5rCXQKDyo2+ZkN3FA6qI /fawoJjK3LI0q854skGDr1SFWz9TrEYi+VTf4Ti2TC8/avI4GsQ15Vr/WU32hkVKCE63DG45yXMD yokpY5MTUUWEH458+tw= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of probing devices sequentially in the PROBE_PREFER_ASYNCHRONOUS mode, scan devices concurrently. This helps when the wall clock time for a single probe is significantly above the CPU time needed for a single probe, e.g. when scanning SCSI LUNs over a storage network. Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Dan Williams Signed-off-by: Bart Van Assche --- drivers/base/bus.c | 3 +-- drivers/base/dd.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8bfd27ec73d6..18ca1178821f 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -696,8 +696,7 @@ int bus_add_driver(struct device_driver *drv) out_unregister: kobject_put(&priv->kobj); - /* drv->p is freed in driver_release() */ - drv->p = NULL; + out_put_bus: bus_put(bus); return error; diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 033382421351..f8d645aa09be 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -691,6 +692,49 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) return ret; } +struct driver_and_dev { + struct device_driver *drv; + struct device *dev; +}; + +static void __driver_probe_device_async(void *data, async_cookie_t cookie) +{ + struct driver_and_dev *dd = data; + struct device_driver *drv = dd->drv; + struct device *dev = dd->dev; + + device_lock(dev); + driver_probe_device(drv, dev); + device_unlock(dev); + kobject_put(&drv->p->kobj); + module_put(drv->owner); + kfree(dd); +} + +static void driver_probe_device_async(struct device_driver *drv, + struct device *dev) +{ + struct driver_and_dev *dd; + + if (!try_module_get(drv->owner)) + return; + dd = kmalloc(sizeof(*dd), GFP_KERNEL); + if (!dd) { + /* If out of memory, scan synchronously. */ + device_lock(dev); + driver_probe_device(drv, dev); + device_unlock(dev); + module_put(drv->owner); + return; + } + *dd = (struct driver_and_dev){ + .drv = drv, + .dev = dev, + }; + kobject_get(&drv->p->kobj); + async_schedule(__driver_probe_device_async, dd); +} + bool driver_allows_async_probing(struct device_driver *drv) { switch (drv->probe_type) { @@ -777,6 +821,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) if (data->check_async && async_allowed != data->want_async) return 0; + if (data->check_async) { + driver_probe_device_async(drv, dev); + return 0; + } + return driver_probe_device(drv, dev); }