From patchwork Wed Oct 17 23:40:05 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: 10646605 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 7BE3413A4 for ; Wed, 17 Oct 2018 23:40:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4022886E for ; Wed, 17 Oct 2018 23:40:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63758288EA; Wed, 17 Oct 2018 23:40:48 +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 B1F942886E for ; Wed, 17 Oct 2018 23:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727290AbeJRHiw (ORCPT ); Thu, 18 Oct 2018 03:38:52 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:51297 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHiw (ORCPT ); Thu, 18 Oct 2018 03:38:52 -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=nO9hGMcQKRjA6rZZKW6c9ykm9qIsqa8THPIU/n9Jrvg=; b=njRdfKyNEpDo CvpFrCc01W5oNq8p9JtvUnl45w4HmximVICF/amH2E99NkbDw9+yILFs0LqRLXw+pSH9HQZ3fjw2c JDU/1qT+f3m0v9vXT8PnZBwcYVupYa0+2pol4K66hdayEMayfng5h5bou8XMRUjj4TYrbwtBpg0eG ieRkkz7ihdRggPv+1Gnc/yCGIUNCTyu0VhSnbfFYLqR84KmfqpSpNrSfyvwapQGbwTXy9p3vOWGHe pIxRISHms3rJjRd0IuDA35ru0PPsbncETvvxAXP1PaBf+DjnmUwKgG2G8cbDF/f5gNFOl9228qI8+ DLdvKNHlA3qC/StIAVlS9A==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQW-000AhI-80; Thu, 18 Oct 2018 01:40:32 +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 0ED10C0D44; Thu, 18 Oct 2018 01:40:28 +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 6/7] sd: Rely on the driver core for asynchronous probing Date: Wed, 17 Oct 2018 16:40:05 -0700 Message-Id: <20181017234006.124251-7-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: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5poI8DJzlBnAk/nK8fZda0V602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASiYf7H/yBdfVu6BXKOqolTM7KPjFjO plxfo9E/jkjYyATJsjWw5+0eZIpQIcK9yrSIoiC5DDnaemEOugg39OcBf2ZkFf0bc6TV99q4yFj4 jO7J//0XCxCMJn8bXo41UD0/WD7BAcwhXN3d5OI6tWyH6CLbyF0Zq4b1/7rjUzETJsEY2Io8tF+w JOqGSVax9Cm77niqGZoB5oiisgnJ8hVNJmO4hZrKar0rT3Fu0bhVQ+HVicDfSEki2HQjIzlgulSP bUMSEuFskSoX1rj3Ja6RM0MUNRB5UUlg/nVM5yDiAS5BG4T+EAOyAeD+V7jzhS8h0NTR1H9naQeI xvtDOwtIYQ/4lg9Ffvqg9IG0EE8tjOSHlcLdm2dKulDEMTPR6C7iQwUHAL+rG1YY6u9b0QCb2OUM eHyTpNN0eXybX/w7/6KFccwJNTvq+iKXCh0g3vYauvSHTBbiywHlI+JD9ckolRWu/myC9pefMqhc M13fWFTslzf1KnhXRDw6mr5Drq/iEF0D9rez2RHuRFnnxQj65e7iCsnoIGXFTV/TINEoVdSwecyF 4DA8XADDrh0QZbUsptJ0Vo0bpokCyieEKhTugPGxKgiZtZSFSTJua9iBhedKEy7bP5gIt23U7fpA nNNOSPMhkf0/quG9N0n5Pnwg8gvgnGVzE8S4rYKUaxyrp5bArYUTMKtVVfkeNDYwXq3ECq1y9Ps4 MtRhXMXMUla6jCMlrsv11sF1S7MGW8yMRfUf9oDBqtClgM5jH/om1Q5P+UBfxwtWVTRs22VsCW/y aaMGXoow8jwS+vIg0J2DIilC5famIyanggmnEEY1ln4yMyb8PasQ+c0C4IKe30H3mCt4xiI4Gbe/ duNP6eDbFWCz0yfor4324loUDdooDHenVxueaHqkWaGCoq93Iu1JHNnjpligY7PNUfPHGCzvAA== 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 As explained during the LSF/MM session about increasing SCSI disk probing concurrency, the problems with the current probing approach are as follows: - The driver core is unaware of asynchronous SCSI LUN probing. wait_for_device_probe() waits for all asynchronous probes except asynchronous SCSI disk probes. - There is unnecessary serialization between sd_probe() and sd_remove(). This can lead to a deadlock. Hence this patch that modifies the sd driver such that it uses the driver core framework for asynchronous probing. The async domains and get_device()/put_device() pairs that became superfluous due to this change are removed. This patch reduces the time needed for loading the scsi_debug kernel module with parameters delay=0 and max_luns=256 from 0.7s to 0.1s. In other words, this specific test runs about seven times faster. See also commit 3c31b52f96f7 ("scsi: async sd resume"). 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/scsi/scsi.c | 14 -------------- drivers/scsi/scsi_pm.c | 22 ++-------------------- drivers/scsi/scsi_priv.h | 3 --- drivers/scsi/sd.c | 13 +++---------- 4 files changed, 5 insertions(+), 47 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index fc1356d101b0..1205369ad44f 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -85,19 +85,6 @@ unsigned int scsi_logging_level; EXPORT_SYMBOL(scsi_logging_level); #endif -/* sd, scsi core and power management need to coordinate flushing async actions */ -ASYNC_DOMAIN(scsi_sd_probe_domain); -EXPORT_SYMBOL(scsi_sd_probe_domain); - -/* - * Separate domain (from scsi_sd_probe_domain) to maximize the benefit of - * asynchronous system resume operations. It is marked 'exclusive' to avoid - * being included in the async_synchronize_full() that is invoked by - * dpm_resume() - */ -ASYNC_DOMAIN_EXCLUSIVE(scsi_sd_pm_domain); -EXPORT_SYMBOL(scsi_sd_pm_domain); - /** * scsi_put_command - Free a scsi command block * @cmd: command block to free @@ -839,7 +826,6 @@ static void __exit exit_scsi(void) scsi_exit_devinfo(); scsi_exit_procfs(); scsi_exit_queue(); - async_unregister_domain(&scsi_sd_probe_domain); } subsys_initcall(init_scsi); diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index b44c1bb687a2..f229208bfef3 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -54,9 +54,6 @@ static int scsi_dev_type_suspend(struct device *dev, const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int err; - /* flush pending in-flight resume operations, suspend is synchronous */ - async_synchronize_full_domain(&scsi_sd_pm_domain); - err = scsi_device_quiesce(to_scsi_device(dev)); if (err == 0) { err = cb(dev, pm); @@ -149,18 +146,7 @@ static int scsi_bus_resume_common(struct device *dev, if (scsi_is_sdev_device(dev) && pm_runtime_suspended(dev)) blk_set_runtime_active(to_scsi_device(dev)->request_queue); - if (fn) { - async_schedule_domain(fn, dev, &scsi_sd_pm_domain); - - /* - * If a user has disabled async probing a likely reason - * is due to a storage enclosure that does not inject - * staggered spin-ups. For safety, make resume - * synchronous as well in that case. - */ - if (strncmp(scsi_scan_type, "async", 5) != 0) - async_synchronize_full_domain(&scsi_sd_pm_domain); - } else { + if (!fn) { pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -170,11 +156,7 @@ static int scsi_bus_resume_common(struct device *dev, static int scsi_bus_prepare(struct device *dev) { - if (scsi_is_sdev_device(dev)) { - /* sd probing uses async_schedule. Wait until it finishes. */ - async_synchronize_full_domain(&scsi_sd_probe_domain); - - } else if (scsi_is_host_device(dev)) { + if (scsi_is_host_device(dev)) { /* Wait until async scanning is finished */ scsi_complete_async_scans(); } diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 99f1db5e467e..b9fa363b4bbb 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -175,9 +175,6 @@ static inline int scsi_autopm_get_host(struct Scsi_Host *h) { return 0; } static inline void scsi_autopm_put_host(struct Scsi_Host *h) {} #endif /* CONFIG_PM */ -extern struct async_domain scsi_sd_pm_domain; -extern struct async_domain scsi_sd_probe_domain; - /* scsi_dh.c */ #ifdef CONFIG_SCSI_DH void scsi_dh_add_device(struct scsi_device *sdev); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b79b366a94f7..52eee36d13fb 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -559,6 +559,7 @@ static struct scsi_driver sd_template = { .name = "sd", .owner = THIS_MODULE, .probe = sd_probe, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, .remove = sd_remove, .shutdown = sd_shutdown, .pm = &sd_pm_ops, @@ -3227,12 +3228,8 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen) return 0; } -/* - * The asynchronous part of sd_probe - */ -static void sd_probe_async(void *data, async_cookie_t cookie) +static void sd_probe_part2(struct scsi_disk *sdkp) { - struct scsi_disk *sdkp = data; struct scsi_device *sdp; struct gendisk *gd; u32 index; @@ -3286,7 +3283,6 @@ static void sd_probe_async(void *data, async_cookie_t cookie) sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", sdp->removable ? "removable " : ""); scsi_autopm_put_device(sdp); - put_device(&sdkp->dev); } /** @@ -3378,8 +3374,7 @@ static int sd_probe(struct device *dev) get_device(dev); dev_set_drvdata(dev, sdkp); - get_device(&sdkp->dev); /* prevent release before async_schedule */ - async_schedule_domain(sd_probe_async, sdkp, &scsi_sd_probe_domain); + sd_probe_part2(sdkp); return 0; @@ -3414,8 +3409,6 @@ static int sd_remove(struct device *dev) devt = disk_devt(sdkp->disk); scsi_autopm_get_device(sdkp->device); - async_synchronize_full_domain(&scsi_sd_pm_domain); - async_synchronize_full_domain(&scsi_sd_probe_domain); device_del(&sdkp->dev); del_gendisk(sdkp->disk); sd_shutdown(dev);