From patchwork Wed Sep 26 21:01:03 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: 10616823 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 E580615A6 for ; Wed, 26 Sep 2018 21:01:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D614D2B869 for ; Wed, 26 Sep 2018 21:01:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D41462B833; Wed, 26 Sep 2018 21:01:50 +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 5BAAA2B869 for ; Wed, 26 Sep 2018 21:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727057AbeI0DQg (ORCPT ); Wed, 26 Sep 2018 23:16:36 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:53707 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727124AbeI0DQg (ORCPT ); Wed, 26 Sep 2018 23:16:36 -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=QxyVFFFH0KxZQYz13tx8mOL3Nv2m1yeIspJ43d05LW8=; b=lJcwDrbn3C6v sxMM/An7BBJWEL7bPe3RF7zeJZDAOlEXPg32+fYFXVTLYv1v73ZXNqJMSOzlWz5omOF1OCWulOfbF rWXfMrj768zf9wYlxZEiLQc1fIuUR35DNGv4aybR88GAem5Z2mfNmTVgjOuUfIi/oXY3K+FUxdwrG jIechMdz8MIo7UpLhq+dKGftrOSaPjIKPvvaUY/C1iq2+YeArNgBErUJA9ss2JFfU8eGGXUFmoF7c iM8108eMcSnhFaLVgqhkpoRDhQ7N6n4KiAFc/3d0hqiP0oMLIklKd6EXdP+0ZW6nNfXtg3reDSjzR enbVenFw93nrG8iv4sug+Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwC-000Cgu-N6; Wed, 26 Sep 2018 23:01:38 +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 0B9F2C047F; Wed, 26 Sep 2018 23:01:19 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v11 1/8] block: Move power management code into a new source file Date: Wed, 26 Sep 2018 14:01:03 -0700 Message-Id: <20180926210110.20362-2-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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 (3.58067525344e-05) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5steieHvr6nRU1CygHHLUbt602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMHSXqg+1/i6wndRZnDou0t3MjnTf0b3I3aEFy BYPo6QcHX5Cpvt/psaJ6aKC9ndNRr5DxNcC3a9NPOOrpbOsc/15aEsY3o6JdH+0MvJ57YUkHffPj aOUqQrKwFZ0r5HuSZWIhmoxQGt3RhzWMa6r8xgqrqdnV/2ZaZt/O+8fKpbgBygjquXX47K/XLNzQ wRtK0rkcsjN5WTUa2rnvyK8KFNUcgLpncXQjTqRSupcUAdvnmAJMd2XJi2WBeegORjwPcUteS3C7 JQjXdMuE7CS5inlds4jtgW6NDRRWzqEH5+aovGSYm4DcPiK1RTzGCOye8p8NyvSkRHwTwTx9G1M5 EMvdGlnEQJMn5KuObFLxmLqt3Kp8qWCPA1FZmxuhCvuDChIMUBexuGo66F0oVT5ebLBeh8VM266o EX729IUf2PrnsXEBAaJKYpjfiKWbEgl3VN2XPrW0GWVtggfTAFWe5tezYqxGMqsKjARq8PBC4qjt NuCyq3bWzUVTawdcppuUzbBZVuMc79ykmmxiW8WEzzCMIG782Q35z7cX7fYYativnBqkdNfJiIp5 625MlL2N/ZpHR821I3ej0XyyWQz0YAEiRQv+PVjjwa+Z5RFCOMSnhLdk6ydE9LIadmZ0hfZBCtbE guydx7+/OTtKDkewxchOtbkvKh6j5V/eNBMucjn1Zsi9ltMHn9uJ3LU07RloP8lGoJ0Gl8mguiiF t2cNluAC8puPex6GxI6zaPdtK+ie4fulhnSKM6+cJSPuNjAUtgZkcRkCnoMzps1w8ZlyWhLf664X dAHfysyXN4qVU7zaLgNeXsteXbVZ7V7Chserd3TerAeYACzCsgvB4EF76lFfEoXm0/FPF8PR0w36 3lnOjEfyhfVmDFQ4iZHgSboBWJiFA7unadJ7QPnyb8IX1dd1LqYC/51Yw6/N6SqgAFdQvy23SZXS fMZ7RzHGH1l2P9GRlIAs+idL8owqtnKHSXyV66CW3t7Vh1oWmQVaJsnuyf/9FwsQjCZ/G16ONVA9 ZdeHk2ffieDVD4iy08ZiiykcXIjnpOooukgSz+HhAncvEPFWWNtpsvZpiX1a3BQY X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the code for runtime power management from blk-core.c into the new source file blk-pm.c. Move the corresponding declarations from into . For CONFIG_PM=n, leave out the declarations of the functions that are not used in that mode. This patch not only reduces the number of #ifdefs in the block layer core code but also reduces the size of header file and hence should help to reduce the build time of the Linux kernel if CONFIG_PM is not defined. Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/Kconfig | 3 + block/Makefile | 1 + block/blk-core.c | 196 +---------------------------------------- block/blk-pm.c | 188 +++++++++++++++++++++++++++++++++++++++ block/blk-pm.h | 43 +++++++++ block/elevator.c | 22 +---- drivers/scsi/scsi_pm.c | 1 + drivers/scsi/sd.c | 1 + drivers/scsi/sr.c | 1 + include/linux/blk-pm.h | 24 +++++ include/linux/blkdev.h | 23 ----- 11 files changed, 264 insertions(+), 239 deletions(-) create mode 100644 block/blk-pm.c create mode 100644 block/blk-pm.h create mode 100644 include/linux/blk-pm.h diff --git a/block/Kconfig b/block/Kconfig index 1f2469a0123c..85263e7bded6 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -228,4 +228,7 @@ config BLK_MQ_RDMA depends on BLOCK && INFINIBAND default y +config BLK_PM + def_bool BLOCK && PM + source block/Kconfig.iosched diff --git a/block/Makefile b/block/Makefile index 572b33f32c07..27eac600474f 100644 --- a/block/Makefile +++ b/block/Makefile @@ -37,3 +37,4 @@ obj-$(CONFIG_BLK_WBT) += blk-wbt.o obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o obj-$(CONFIG_BLK_DEBUG_FS_ZONED)+= blk-mq-debugfs-zoned.o obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o +obj-$(CONFIG_BLK_PM) += blk-pm.o diff --git a/block/blk-core.c b/block/blk-core.c index 4dbc93f43b38..6d4dd176bd9d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -42,6 +42,7 @@ #include "blk.h" #include "blk-mq.h" #include "blk-mq-sched.h" +#include "blk-pm.h" #include "blk-rq-qos.h" #ifdef CONFIG_DEBUG_FS @@ -1726,16 +1727,6 @@ void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part) } EXPORT_SYMBOL_GPL(part_round_stats); -#ifdef CONFIG_PM -static void blk_pm_put_request(struct request *rq) -{ - if (rq->q->dev && !(rq->rq_flags & RQF_PM) && !--rq->q->nr_pending) - pm_runtime_mark_last_busy(rq->q->dev); -} -#else -static inline void blk_pm_put_request(struct request *rq) {} -#endif - void __blk_put_request(struct request_queue *q, struct request *req) { req_flags_t rq_flags = req->rq_flags; @@ -3757,191 +3748,6 @@ void blk_finish_plug(struct blk_plug *plug) } EXPORT_SYMBOL(blk_finish_plug); -#ifdef CONFIG_PM -/** - * blk_pm_runtime_init - Block layer runtime PM initialization routine - * @q: the queue of the device - * @dev: the device the queue belongs to - * - * Description: - * Initialize runtime-PM-related fields for @q and start auto suspend for - * @dev. Drivers that want to take advantage of request-based runtime PM - * should call this function after @dev has been initialized, and its - * request queue @q has been allocated, and runtime PM for it can not happen - * yet(either due to disabled/forbidden or its usage_count > 0). In most - * cases, driver should call this function before any I/O has taken place. - * - * This function takes care of setting up using auto suspend for the device, - * the autosuspend delay is set to -1 to make runtime suspend impossible - * until an updated value is either set by user or by driver. Drivers do - * not need to touch other autosuspend settings. - * - * The block layer runtime PM is request based, so only works for drivers - * that use request as their IO unit instead of those directly use bio's. - */ -void blk_pm_runtime_init(struct request_queue *q, struct device *dev) -{ - /* Don't enable runtime PM for blk-mq until it is ready */ - if (q->mq_ops) { - pm_runtime_disable(dev); - return; - } - - q->dev = dev; - q->rpm_status = RPM_ACTIVE; - pm_runtime_set_autosuspend_delay(q->dev, -1); - pm_runtime_use_autosuspend(q->dev); -} -EXPORT_SYMBOL(blk_pm_runtime_init); - -/** - * blk_pre_runtime_suspend - Pre runtime suspend check - * @q: the queue of the device - * - * Description: - * This function will check if runtime suspend is allowed for the device - * by examining if there are any requests pending in the queue. If there - * are requests pending, the device can not be runtime suspended; otherwise, - * the queue's status will be updated to SUSPENDING and the driver can - * proceed to suspend the device. - * - * For the not allowed case, we mark last busy for the device so that - * runtime PM core will try to autosuspend it some time later. - * - * This function should be called near the start of the device's - * runtime_suspend callback. - * - * Return: - * 0 - OK to runtime suspend the device - * -EBUSY - Device should not be runtime suspended - */ -int blk_pre_runtime_suspend(struct request_queue *q) -{ - int ret = 0; - - if (!q->dev) - return ret; - - spin_lock_irq(q->queue_lock); - if (q->nr_pending) { - ret = -EBUSY; - pm_runtime_mark_last_busy(q->dev); - } else { - q->rpm_status = RPM_SUSPENDING; - } - spin_unlock_irq(q->queue_lock); - return ret; -} -EXPORT_SYMBOL(blk_pre_runtime_suspend); - -/** - * blk_post_runtime_suspend - Post runtime suspend processing - * @q: the queue of the device - * @err: return value of the device's runtime_suspend function - * - * Description: - * Update the queue's runtime status according to the return value of the - * device's runtime suspend function and mark last busy for the device so - * that PM core will try to auto suspend the device at a later time. - * - * This function should be called near the end of the device's - * runtime_suspend callback. - */ -void blk_post_runtime_suspend(struct request_queue *q, int err) -{ - if (!q->dev) - return; - - spin_lock_irq(q->queue_lock); - if (!err) { - q->rpm_status = RPM_SUSPENDED; - } else { - q->rpm_status = RPM_ACTIVE; - pm_runtime_mark_last_busy(q->dev); - } - spin_unlock_irq(q->queue_lock); -} -EXPORT_SYMBOL(blk_post_runtime_suspend); - -/** - * blk_pre_runtime_resume - Pre runtime resume processing - * @q: the queue of the device - * - * Description: - * Update the queue's runtime status to RESUMING in preparation for the - * runtime resume of the device. - * - * This function should be called near the start of the device's - * runtime_resume callback. - */ -void blk_pre_runtime_resume(struct request_queue *q) -{ - if (!q->dev) - return; - - spin_lock_irq(q->queue_lock); - q->rpm_status = RPM_RESUMING; - spin_unlock_irq(q->queue_lock); -} -EXPORT_SYMBOL(blk_pre_runtime_resume); - -/** - * blk_post_runtime_resume - Post runtime resume processing - * @q: the queue of the device - * @err: return value of the device's runtime_resume function - * - * Description: - * Update the queue's runtime status according to the return value of the - * device's runtime_resume function. If it is successfully resumed, process - * the requests that are queued into the device's queue when it is resuming - * and then mark last busy and initiate autosuspend for it. - * - * This function should be called near the end of the device's - * runtime_resume callback. - */ -void blk_post_runtime_resume(struct request_queue *q, int err) -{ - if (!q->dev) - return; - - spin_lock_irq(q->queue_lock); - if (!err) { - q->rpm_status = RPM_ACTIVE; - __blk_run_queue(q); - pm_runtime_mark_last_busy(q->dev); - pm_request_autosuspend(q->dev); - } else { - q->rpm_status = RPM_SUSPENDED; - } - spin_unlock_irq(q->queue_lock); -} -EXPORT_SYMBOL(blk_post_runtime_resume); - -/** - * blk_set_runtime_active - Force runtime status of the queue to be active - * @q: the queue of the device - * - * If the device is left runtime suspended during system suspend the resume - * hook typically resumes the device and corrects runtime status - * accordingly. However, that does not affect the queue runtime PM status - * which is still "suspended". This prevents processing requests from the - * queue. - * - * This function can be used in driver's resume hook to correct queue - * runtime PM status and re-enable peeking requests from the queue. It - * should be called before first request is added to the queue. - */ -void blk_set_runtime_active(struct request_queue *q) -{ - spin_lock_irq(q->queue_lock); - q->rpm_status = RPM_ACTIVE; - pm_runtime_mark_last_busy(q->dev); - pm_request_autosuspend(q->dev); - spin_unlock_irq(q->queue_lock); -} -EXPORT_SYMBOL(blk_set_runtime_active); -#endif - int __init blk_dev_init(void) { BUILD_BUG_ON(REQ_OP_LAST >= (1 << REQ_OP_BITS)); diff --git a/block/blk-pm.c b/block/blk-pm.c new file mode 100644 index 000000000000..9b636960d285 --- /dev/null +++ b/block/blk-pm.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include + +/** + * blk_pm_runtime_init - Block layer runtime PM initialization routine + * @q: the queue of the device + * @dev: the device the queue belongs to + * + * Description: + * Initialize runtime-PM-related fields for @q and start auto suspend for + * @dev. Drivers that want to take advantage of request-based runtime PM + * should call this function after @dev has been initialized, and its + * request queue @q has been allocated, and runtime PM for it can not happen + * yet(either due to disabled/forbidden or its usage_count > 0). In most + * cases, driver should call this function before any I/O has taken place. + * + * This function takes care of setting up using auto suspend for the device, + * the autosuspend delay is set to -1 to make runtime suspend impossible + * until an updated value is either set by user or by driver. Drivers do + * not need to touch other autosuspend settings. + * + * The block layer runtime PM is request based, so only works for drivers + * that use request as their IO unit instead of those directly use bio's. + */ +void blk_pm_runtime_init(struct request_queue *q, struct device *dev) +{ + /* Don't enable runtime PM for blk-mq until it is ready */ + if (q->mq_ops) { + pm_runtime_disable(dev); + return; + } + + q->dev = dev; + q->rpm_status = RPM_ACTIVE; + pm_runtime_set_autosuspend_delay(q->dev, -1); + pm_runtime_use_autosuspend(q->dev); +} +EXPORT_SYMBOL(blk_pm_runtime_init); + +/** + * blk_pre_runtime_suspend - Pre runtime suspend check + * @q: the queue of the device + * + * Description: + * This function will check if runtime suspend is allowed for the device + * by examining if there are any requests pending in the queue. If there + * are requests pending, the device can not be runtime suspended; otherwise, + * the queue's status will be updated to SUSPENDING and the driver can + * proceed to suspend the device. + * + * For the not allowed case, we mark last busy for the device so that + * runtime PM core will try to autosuspend it some time later. + * + * This function should be called near the start of the device's + * runtime_suspend callback. + * + * Return: + * 0 - OK to runtime suspend the device + * -EBUSY - Device should not be runtime suspended + */ +int blk_pre_runtime_suspend(struct request_queue *q) +{ + int ret = 0; + + if (!q->dev) + return ret; + + spin_lock_irq(q->queue_lock); + if (q->nr_pending) { + ret = -EBUSY; + pm_runtime_mark_last_busy(q->dev); + } else { + q->rpm_status = RPM_SUSPENDING; + } + spin_unlock_irq(q->queue_lock); + return ret; +} +EXPORT_SYMBOL(blk_pre_runtime_suspend); + +/** + * blk_post_runtime_suspend - Post runtime suspend processing + * @q: the queue of the device + * @err: return value of the device's runtime_suspend function + * + * Description: + * Update the queue's runtime status according to the return value of the + * device's runtime suspend function and mark last busy for the device so + * that PM core will try to auto suspend the device at a later time. + * + * This function should be called near the end of the device's + * runtime_suspend callback. + */ +void blk_post_runtime_suspend(struct request_queue *q, int err) +{ + if (!q->dev) + return; + + spin_lock_irq(q->queue_lock); + if (!err) { + q->rpm_status = RPM_SUSPENDED; + } else { + q->rpm_status = RPM_ACTIVE; + pm_runtime_mark_last_busy(q->dev); + } + spin_unlock_irq(q->queue_lock); +} +EXPORT_SYMBOL(blk_post_runtime_suspend); + +/** + * blk_pre_runtime_resume - Pre runtime resume processing + * @q: the queue of the device + * + * Description: + * Update the queue's runtime status to RESUMING in preparation for the + * runtime resume of the device. + * + * This function should be called near the start of the device's + * runtime_resume callback. + */ +void blk_pre_runtime_resume(struct request_queue *q) +{ + if (!q->dev) + return; + + spin_lock_irq(q->queue_lock); + q->rpm_status = RPM_RESUMING; + spin_unlock_irq(q->queue_lock); +} +EXPORT_SYMBOL(blk_pre_runtime_resume); + +/** + * blk_post_runtime_resume - Post runtime resume processing + * @q: the queue of the device + * @err: return value of the device's runtime_resume function + * + * Description: + * Update the queue's runtime status according to the return value of the + * device's runtime_resume function. If it is successfully resumed, process + * the requests that are queued into the device's queue when it is resuming + * and then mark last busy and initiate autosuspend for it. + * + * This function should be called near the end of the device's + * runtime_resume callback. + */ +void blk_post_runtime_resume(struct request_queue *q, int err) +{ + if (!q->dev) + return; + + spin_lock_irq(q->queue_lock); + if (!err) { + q->rpm_status = RPM_ACTIVE; + __blk_run_queue(q); + pm_runtime_mark_last_busy(q->dev); + pm_request_autosuspend(q->dev); + } else { + q->rpm_status = RPM_SUSPENDED; + } + spin_unlock_irq(q->queue_lock); +} +EXPORT_SYMBOL(blk_post_runtime_resume); + +/** + * blk_set_runtime_active - Force runtime status of the queue to be active + * @q: the queue of the device + * + * If the device is left runtime suspended during system suspend the resume + * hook typically resumes the device and corrects runtime status + * accordingly. However, that does not affect the queue runtime PM status + * which is still "suspended". This prevents processing requests from the + * queue. + * + * This function can be used in driver's resume hook to correct queue + * runtime PM status and re-enable peeking requests from the queue. It + * should be called before first request is added to the queue. + */ +void blk_set_runtime_active(struct request_queue *q) +{ + spin_lock_irq(q->queue_lock); + q->rpm_status = RPM_ACTIVE; + pm_runtime_mark_last_busy(q->dev); + pm_request_autosuspend(q->dev); + spin_unlock_irq(q->queue_lock); +} +EXPORT_SYMBOL(blk_set_runtime_active); diff --git a/block/blk-pm.h b/block/blk-pm.h new file mode 100644 index 000000000000..1ffc8ef203ec --- /dev/null +++ b/block/blk-pm.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _BLOCK_BLK_PM_H_ +#define _BLOCK_BLK_PM_H_ + +#include + +#ifdef CONFIG_PM +static inline void blk_pm_requeue_request(struct request *rq) +{ + if (rq->q->dev && !(rq->rq_flags & RQF_PM)) + rq->q->nr_pending--; +} + +static inline void blk_pm_add_request(struct request_queue *q, + struct request *rq) +{ + if (q->dev && !(rq->rq_flags & RQF_PM) && q->nr_pending++ == 0 && + (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING)) + pm_request_resume(q->dev); +} + +static inline void blk_pm_put_request(struct request *rq) +{ + if (rq->q->dev && !(rq->rq_flags & RQF_PM) && !--rq->q->nr_pending) + pm_runtime_mark_last_busy(rq->q->dev); +} +#else +static inline void blk_pm_requeue_request(struct request *rq) +{ +} + +static inline void blk_pm_add_request(struct request_queue *q, + struct request *rq) +{ +} + +static inline void blk_pm_put_request(struct request *rq) +{ +} +#endif + +#endif /* _BLOCK_BLK_PM_H_ */ diff --git a/block/elevator.c b/block/elevator.c index 6a06b5d040e5..e18ac68626e3 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -41,6 +41,7 @@ #include "blk.h" #include "blk-mq-sched.h" +#include "blk-pm.h" #include "blk-wbt.h" static DEFINE_SPINLOCK(elv_list_lock); @@ -557,27 +558,6 @@ void elv_bio_merged(struct request_queue *q, struct request *rq, e->type->ops.sq.elevator_bio_merged_fn(q, rq, bio); } -#ifdef CONFIG_PM -static void blk_pm_requeue_request(struct request *rq) -{ - if (rq->q->dev && !(rq->rq_flags & RQF_PM)) - rq->q->nr_pending--; -} - -static void blk_pm_add_request(struct request_queue *q, struct request *rq) -{ - if (q->dev && !(rq->rq_flags & RQF_PM) && q->nr_pending++ == 0 && - (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING)) - pm_request_resume(q->dev); -} -#else -static inline void blk_pm_requeue_request(struct request *rq) {} -static inline void blk_pm_add_request(struct request_queue *q, - struct request *rq) -{ -} -#endif - void elv_requeue_request(struct request_queue *q, struct request *rq) { /* diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index b44c1bb687a2..a2b4179bfdf7 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b79b366a94f7..64514e8359e4 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index d0389b20574d..4f07b3410595 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/blk-pm.h b/include/linux/blk-pm.h new file mode 100644 index 000000000000..b80c65aba249 --- /dev/null +++ b/include/linux/blk-pm.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _BLK_PM_H_ +#define _BLK_PM_H_ + +struct device; +struct request_queue; + +/* + * block layer runtime pm functions + */ +#ifdef CONFIG_PM +extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev); +extern int blk_pre_runtime_suspend(struct request_queue *q); +extern void blk_post_runtime_suspend(struct request_queue *q, int err); +extern void blk_pre_runtime_resume(struct request_queue *q); +extern void blk_post_runtime_resume(struct request_queue *q, int err); +extern void blk_set_runtime_active(struct request_queue *q); +#else +static inline void blk_pm_runtime_init(struct request_queue *q, + struct device *dev) {} +#endif + +#endif /* _BLK_PM_H_ */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1d5e14139795..cd863511dedb 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1280,29 +1280,6 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id, extern void blk_put_queue(struct request_queue *); extern void blk_set_queue_dying(struct request_queue *); -/* - * block layer runtime pm functions - */ -#ifdef CONFIG_PM -extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev); -extern int blk_pre_runtime_suspend(struct request_queue *q); -extern void blk_post_runtime_suspend(struct request_queue *q, int err); -extern void blk_pre_runtime_resume(struct request_queue *q); -extern void blk_post_runtime_resume(struct request_queue *q, int err); -extern void blk_set_runtime_active(struct request_queue *q); -#else -static inline void blk_pm_runtime_init(struct request_queue *q, - struct device *dev) {} -static inline int blk_pre_runtime_suspend(struct request_queue *q) -{ - return -ENOSYS; -} -static inline void blk_post_runtime_suspend(struct request_queue *q, int err) {} -static inline void blk_pre_runtime_resume(struct request_queue *q) {} -static inline void blk_post_runtime_resume(struct request_queue *q, int err) {} -static inline void blk_set_runtime_active(struct request_queue *q) {} -#endif - /* * blk_plug permits building a queue of related requests by holding the I/O * fragments for a short period. This allows merging of sequential requests From patchwork Wed Sep 26 21:01:04 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: 10616817 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 9CF04180E for ; Wed, 26 Sep 2018 21:01:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F56F2B85F for ; Wed, 26 Sep 2018 21:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D73A2B86C; Wed, 26 Sep 2018 21:01:46 +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 9C55A2B878 for ; Wed, 26 Sep 2018 21:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbeI0DQd (ORCPT ); Wed, 26 Sep 2018 23:16:33 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:41873 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbeI0DQc (ORCPT ); Wed, 26 Sep 2018 23:16:32 -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=+VcNzbkhGi6Lb7ACQi0kZag72EO0/h+29OjjJFUxzAI=; b=IxAGlQUnNf0k XWHtIgL/xSwj+6ZlmSZyId8lw1V2gKBBT7PQXi034YnM7YatH1TU70Q8HsXMh8R42FhbtbGiWXZjw Jd+xKm9c3L+8IsGYWpAi0MhcFJ3fx0iBr9eLFbsrC8SAyCksd23yUzrjHMw9IlCg8bWWoDn6r1Ay/ q154MtDQe6/LFpQKv7uI2MsQc1Ki81LyVxZZMDxB38Fc9KD2HCdhCXVaVFv5gmlH5KcTrra2AnL3T wFz1kRCmlqOAbu2ruU24fryBfu/Q5I7qwVq1qMYEZAZjtpD0gwieE/EHEs8YU5oox6/yLZ0NSvkSV pAoAS90U/9XMZXoLk37wlA==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwD-000BlW-Mp; Wed, 26 Sep 2018 23:01:38 +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 5414EC0517; Wed, 26 Sep 2018 23:01:22 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Johannes Thumshirn , Alan Stern Subject: [PATCH v11 2/8] block, scsi: Change the preempt-only flag into a counter Date: Wed, 26 Sep 2018 14:01:04 -0700 Message-Id: <20180926210110.20362-3-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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.00201244804899) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5kPdNHMykLsz+yOSpKFWti9602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMHSXqg+1/i6wndRZnDou0t3MjnTf0b3I3aEFy BYPo6Qeyf2Ayw+2NrC15TvhOk6pQJqQHBevYa9nN8mUIQlJ9WY4MfV5hi61CqoYUfGZVBWQIQZqZ 9VYloGcRwm9W9EtxCfTjZrP1NGPuIIwhdSez7lprjQPFk8m4tSTfORUp3ykGtwKY6DS+SpoDJebm bap+qGwJH8+A52d1poZINYoW9wBBhZhu/RbUg9UkZa4GOA7o0okJaE8GqrQcOA/I5j6z9mwSGfNa BmafifTJSMMwOJchIdn9WjoIe8SEjL77E2RRh+7MnWbw7fXOUdDwPDg2bN87qJveuvI4FkaTzox5 7en0TkQuIdVjxFJSAPHvCxKJKuWBdR7YVGu3dD+xoi67r0TCUZsaG+mLAH7VoDC8TEHvm3Pq/TMV hLiLVSlbDnLxMg+tusI0bd26SWMjAgXw31/E3ahF5MMcDI7KdpjQKXV03l7WBaRxJ7yoJ3IKvCYv P92yJqFDUMWgYkYfhC80a8lAKYNtqEsHRfxQgIiuywCa/QYlJHXn0HHVtjhKEP24sffQX1o0gBXz k0Y91KPW6J1fhOzjF0b4LXcjJZ5loiDNf4LhktxaTgfAYLYiStVrSlHVtLHaZkFpoXAuc0NS16Kl usqJ8hbFAHHMFBzjqSlADpsrRqn5Jpuf+kRv1g8Te5rdilVCCfSu51hI99R4i3H9f7we29ciaD/8 EjIFKfVMC/0z9VT6J51+EkUQd7rKATDDBZ7fFc0FDw0l2bg+RuQm3HCO5MWXKMmMA1ef4kiVL2KE QJlMoR2TOPXQbWZYviAbJ0viZDrdelLyeN/2l9UvxdUuxhgy1UgE7lWmo7wKcfIpPo3vv82R1c8N Xqt6jvJsmaZpbKRZNsABnVcYdlUSxVR0EOyhVYwy6sZ0p9EyvDkN3AfUBddcu9g0UhyJvXzobDJy UVEv3v3xOoI2V0bkGRWsfttAG/pnMLcZFc2wWVbjHO/cpJpsYlvFhM9du1Tr+KAnEl6h2QN7FJBw oApFJJJ3+3GhjK7Gku3lzsf6aC/gK6YvCJx47zPlUt4= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The RQF_PREEMPT flag is used for three purposes: - In the SCSI core, for making sure that power management requests are executed even if a device is in the "quiesced" state. - For domain validation by SCSI drivers that use the parallel port. - In the IDE driver, for IDE preempt requests. Rename "preempt-only" into "pm-only" because the primary purpose of this mode is power management. Since the power management core may but does not have to resume a runtime suspended device before performing system-wide suspend and since a later patch will set "pm-only" mode as long as a block device is runtime suspended, make it possible to set "pm-only" mode from more than one context. Since with this change scsi_device_quiesce() is no longer idempotent, make that function return early if it is called for a quiesced queue. Signed-off-by: Bart Van Assche Acked-by: Martin K. Petersen Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Reviewed-by: Ming Lei Cc: Jianchao Wang Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-core.c | 35 ++++++++++++++++++----------------- block/blk-mq-debugfs.c | 10 +++++++++- drivers/scsi/scsi_lib.c | 11 +++++++---- include/linux/blkdev.h | 14 +++++++++----- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 6d4dd176bd9d..1a691f5269bb 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -422,24 +422,25 @@ void blk_sync_queue(struct request_queue *q) EXPORT_SYMBOL(blk_sync_queue); /** - * blk_set_preempt_only - set QUEUE_FLAG_PREEMPT_ONLY + * blk_set_pm_only - increment pm_only counter * @q: request queue pointer - * - * Returns the previous value of the PREEMPT_ONLY flag - 0 if the flag was not - * set and 1 if the flag was already set. */ -int blk_set_preempt_only(struct request_queue *q) +void blk_set_pm_only(struct request_queue *q) { - return blk_queue_flag_test_and_set(QUEUE_FLAG_PREEMPT_ONLY, q); + atomic_inc(&q->pm_only); } -EXPORT_SYMBOL_GPL(blk_set_preempt_only); +EXPORT_SYMBOL_GPL(blk_set_pm_only); -void blk_clear_preempt_only(struct request_queue *q) +void blk_clear_pm_only(struct request_queue *q) { - blk_queue_flag_clear(QUEUE_FLAG_PREEMPT_ONLY, q); - wake_up_all(&q->mq_freeze_wq); + int pm_only; + + pm_only = atomic_dec_return(&q->pm_only); + WARN_ON_ONCE(pm_only < 0); + if (pm_only == 0) + wake_up_all(&q->mq_freeze_wq); } -EXPORT_SYMBOL_GPL(blk_clear_preempt_only); +EXPORT_SYMBOL_GPL(blk_clear_pm_only); /** * __blk_run_queue_uncond - run a queue whether or not it has been stopped @@ -918,7 +919,7 @@ EXPORT_SYMBOL(blk_alloc_queue); */ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) { - const bool preempt = flags & BLK_MQ_REQ_PREEMPT; + const bool pm = flags & BLK_MQ_REQ_PREEMPT; while (true) { bool success = false; @@ -926,11 +927,11 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) rcu_read_lock(); if (percpu_ref_tryget_live(&q->q_usage_counter)) { /* - * The code that sets the PREEMPT_ONLY flag is - * responsible for ensuring that that flag is globally - * visible before the queue is unfrozen. + * The code that increments the pm_only counter is + * responsible for ensuring that that counter is + * globally visible before the queue is unfrozen. */ - if (preempt || !blk_queue_preempt_only(q)) { + if (pm || !blk_queue_pm_only(q)) { success = true; } else { percpu_ref_put(&q->q_usage_counter); @@ -955,7 +956,7 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) wait_event(q->mq_freeze_wq, (atomic_read(&q->mq_freeze_depth) == 0 && - (preempt || !blk_queue_preempt_only(q))) || + (pm || !blk_queue_pm_only(q))) || blk_queue_dying(q)); if (blk_queue_dying(q)) return -ENODEV; diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index cb1e6cf7ac48..a5ea86835fcb 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -102,6 +102,14 @@ static int blk_flags_show(struct seq_file *m, const unsigned long flags, return 0; } +static int queue_pm_only_show(void *data, struct seq_file *m) +{ + struct request_queue *q = data; + + seq_printf(m, "%d\n", atomic_read(&q->pm_only)); + return 0; +} + #define QUEUE_FLAG_NAME(name) [QUEUE_FLAG_##name] = #name static const char *const blk_queue_flag_name[] = { QUEUE_FLAG_NAME(QUEUED), @@ -132,7 +140,6 @@ static const char *const blk_queue_flag_name[] = { QUEUE_FLAG_NAME(REGISTERED), QUEUE_FLAG_NAME(SCSI_PASSTHROUGH), QUEUE_FLAG_NAME(QUIESCED), - QUEUE_FLAG_NAME(PREEMPT_ONLY), }; #undef QUEUE_FLAG_NAME @@ -209,6 +216,7 @@ static ssize_t queue_write_hint_store(void *data, const char __user *buf, static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs[] = { { "poll_stat", 0400, queue_poll_stat_show }, { "requeue_list", 0400, .seq_ops = &queue_requeue_list_seq_ops }, + { "pm_only", 0600, queue_pm_only_show, NULL }, { "state", 0600, queue_state_show, queue_state_write }, { "write_hints", 0600, queue_write_hint_show, queue_write_hint_store }, { "zone_wlock", 0400, queue_zone_wlock_show, NULL }, diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index eb97d2dd3651..62348412ed1b 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -3046,11 +3046,14 @@ scsi_device_quiesce(struct scsi_device *sdev) */ WARN_ON_ONCE(sdev->quiesced_by && sdev->quiesced_by != current); - blk_set_preempt_only(q); + if (sdev->quiesced_by == current) + return 0; + + blk_set_pm_only(q); blk_mq_freeze_queue(q); /* - * Ensure that the effect of blk_set_preempt_only() will be visible + * Ensure that the effect of blk_set_pm_only() will be visible * for percpu_ref_tryget() callers that occur after the queue * unfreeze even if the queue was already frozen before this function * was called. See also https://lwn.net/Articles/573497/. @@ -3063,7 +3066,7 @@ scsi_device_quiesce(struct scsi_device *sdev) if (err == 0) sdev->quiesced_by = current; else - blk_clear_preempt_only(q); + blk_clear_pm_only(q); mutex_unlock(&sdev->state_mutex); return err; @@ -3088,7 +3091,7 @@ void scsi_device_resume(struct scsi_device *sdev) mutex_lock(&sdev->state_mutex); WARN_ON_ONCE(!sdev->quiesced_by); sdev->quiesced_by = NULL; - blk_clear_preempt_only(sdev->request_queue); + blk_clear_pm_only(sdev->request_queue); if (sdev->sdev_state == SDEV_QUIESCE) scsi_device_set_state(sdev, SDEV_RUNNING); mutex_unlock(&sdev->state_mutex); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index cd863511dedb..13bb54f26736 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -504,6 +504,12 @@ struct request_queue { * various queue flags, see QUEUE_* below */ unsigned long queue_flags; + /* + * Number of contexts that have called blk_set_pm_only(). If this + * counter is above zero then only RQF_PM and RQF_PREEMPT requests are + * processed. + */ + atomic_t pm_only; /* * ida allocated id for this queue. Used to index queues from @@ -698,7 +704,6 @@ struct request_queue { #define QUEUE_FLAG_REGISTERED 26 /* queue has been registered to a disk */ #define QUEUE_FLAG_SCSI_PASSTHROUGH 27 /* queue supports SCSI commands */ #define QUEUE_FLAG_QUIESCED 28 /* queue has been quiesced */ -#define QUEUE_FLAG_PREEMPT_ONLY 29 /* only process REQ_PREEMPT requests */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_SAME_COMP) | \ @@ -736,12 +741,11 @@ bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q); ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ REQ_FAILFAST_DRIVER)) #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) -#define blk_queue_preempt_only(q) \ - test_bit(QUEUE_FLAG_PREEMPT_ONLY, &(q)->queue_flags) +#define blk_queue_pm_only(q) atomic_read(&(q)->pm_only) #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) -extern int blk_set_preempt_only(struct request_queue *q); -extern void blk_clear_preempt_only(struct request_queue *q); +extern void blk_set_pm_only(struct request_queue *q); +extern void blk_clear_pm_only(struct request_queue *q); static inline int queue_in_flight(struct request_queue *q) { From patchwork Wed Sep 26 21:01: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: 10616819 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 B250C180E for ; Wed, 26 Sep 2018 21:01:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4F122B84D for ; Wed, 26 Sep 2018 21:01:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A324C2B87C; Wed, 26 Sep 2018 21:01:47 +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 214A12B84D for ; Wed, 26 Sep 2018 21:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726778AbeI0DQe (ORCPT ); Wed, 26 Sep 2018 23:16:34 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:46583 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727131AbeI0DQe (ORCPT ); Wed, 26 Sep 2018 23:16:34 -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=v4hELt/yIVDIucauBFCBmaAn4vItU8CslCk+rcK/oVE=; b=B1rxZI9z7ESZ 1THNwMY/h1/X1/5D2izIv4QHAkmQGb7jKmT8sWnLPwxGh3KudJ3S/BiqWTapLbVwPxbgkNUgkH2X3 J5OP5RAo6qSrFifl1UrD4JM6I/1fTBNiZTzT8ezqtoV9ct2fVD1Na/rNGFLDrrZGCd57BH9Ma8inm 9bleR2Vgev7ZPHbWWaVGmKlc1xDMNsmypS6YoNH1tttxtdELXzCuGgtpyu/nWKi/G0AzZVKCwrI0i ygCSlnqZv3Z/5Rue85kstFYoLbChzebcl4p7WU4wNotRsKAoYfp7wsh1CvDYrAx7StlrBD/ujBWoK cJsAm8SF9P4HgHlkLm1JOw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwE-000Ch9-M6; Wed, 26 Sep 2018 23:01:39 +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 30979C0511; Wed, 26 Sep 2018 23:01:24 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , "Martin K . Petersen" , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v11 3/8] block: Split blk_pm_add_request() and blk_pm_put_request() Date: Wed, 26 Sep 2018 14:01:05 -0700 Message-Id: <20180926210110.20362-4-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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: EX5BVjFpneJeBchSMxfU5l9p2RykhusDbB+PzKuxLKl602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMQkpuFrILVINAX/FRRdHr3yMkm/wiy60JYYB9 uF3NAa2g1pZKwiWCImQQO2sJllH2SGIdHuYbIJvBnZmUT8jII/ODWQ+TOBzfO9ZWChwqLrRtQGa8 rfVqcnGFOMq2D/9ZqvrTdEmAmAz04LoQQdgc4aYARgjnuHaYoBczpAr33GpjBMLLaM2KtLCkia0v MuKlBxbS7+nVR7qfIyvZKnVQNeKVse1sVhWabI0/+PN3sILfno2VGCQBTzV5700QuyS2nB91/WsJ i78ADPGYDhYdq/2p7chPBr9Suc7XsfyyMyRMs3x71t5DHCETMYRS4C1JUuIF2yn03s7TS3ghm2vg BtmmngDbiCqrDh/638bDFveIcHlK5Xt74cx9xpLTapBBIWJTOvft3Y9D3D5je6Fi1aSZOeuLeApg TfFSSpne6KJYbuQrf2k+DKrsx9JdAdbfrp4mNrOT5C/nYMDaWYUKFPMY4F2VSLjcAX5wkBjuRtGq r3wBwEeX6Ai55FPRpzhbMjMm/D2rEPnNAuCCnt9B9yxnMyDcssgJk4TFOnIdiKwgr/U0flMcy2Vi /IcBgY4a/OOwajxbqjCef6Smuows/rE2LVWBPF9IzF6zg4ZEKfAjd0WvgVSVkM9+5JhInxQze/Qk ioJxyfHmUVFdcKIc0G60KJiD32bchiuBPQIfMzbOudhi11hQc8pktdd7tiISsjH69DXQvqXCOgKH wqsoNN4F1lU/G5bsD6sx+ZbP+ok6iq4BARkMc7GL4L2H5LT1WkE9KY9LcGdyxgcUHrldmFBrMyfp YuyanAZpMXssfrVFND0q3lxSCbF8ydR7MXDsLJ9uRReSv8I4hhmhe4tLeYtGRDz0z+XkjgXpC0sZ BDKEikTSRw8lxi7VJgFyVuZVskP7V5Y77AVSbw8rDRvcV+uO5TcDeKjrEmYPn2IVWRvMxBtjAPy6 eLm/JRe7n5dpYhai3vEoMrcP3ydYA96eq5Klr/Cq7U2vgXLghPzhXKb8XG910biZEcomWehz4u8s zDg6HYuTCyYgL61SIkBTYTWFca/UjxrIgBCE9DdH/TDk2EPy497nssgnoMkIb3rMFAyxyz4M82bX +iXOYfJTgg== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the pm_request_resume() and pm_runtime_mark_last_busy() calls into two new functions and thereby separate legacy block layer code from code that works for both the legacy block layer and blk-mq. A later patch will add calls to the new functions in the blk-mq code. Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Cc: Martin K. Petersen Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-core.c | 1 + block/blk-pm.h | 36 +++++++++++++++++++++++++++++++----- block/elevator.c | 1 + 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 1a691f5269bb..fd91e9bf2893 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1744,6 +1744,7 @@ void __blk_put_request(struct request_queue *q, struct request *req) blk_req_zone_write_unlock(req); blk_pm_put_request(req); + blk_pm_mark_last_busy(req); elv_completed_request(q, req); diff --git a/block/blk-pm.h b/block/blk-pm.h index 1ffc8ef203ec..a8564ea72a41 100644 --- a/block/blk-pm.h +++ b/block/blk-pm.h @@ -6,8 +6,23 @@ #include #ifdef CONFIG_PM +static inline void blk_pm_request_resume(struct request_queue *q) +{ + if (q->dev && (q->rpm_status == RPM_SUSPENDED || + q->rpm_status == RPM_SUSPENDING)) + pm_request_resume(q->dev); +} + +static inline void blk_pm_mark_last_busy(struct request *rq) +{ + if (rq->q->dev && !(rq->rq_flags & RQF_PM)) + pm_runtime_mark_last_busy(rq->q->dev); +} + static inline void blk_pm_requeue_request(struct request *rq) { + lockdep_assert_held(rq->q->queue_lock); + if (rq->q->dev && !(rq->rq_flags & RQF_PM)) rq->q->nr_pending--; } @@ -15,17 +30,28 @@ static inline void blk_pm_requeue_request(struct request *rq) static inline void blk_pm_add_request(struct request_queue *q, struct request *rq) { - if (q->dev && !(rq->rq_flags & RQF_PM) && q->nr_pending++ == 0 && - (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING)) - pm_request_resume(q->dev); + lockdep_assert_held(q->queue_lock); + + if (q->dev && !(rq->rq_flags & RQF_PM)) + q->nr_pending++; } static inline void blk_pm_put_request(struct request *rq) { - if (rq->q->dev && !(rq->rq_flags & RQF_PM) && !--rq->q->nr_pending) - pm_runtime_mark_last_busy(rq->q->dev); + lockdep_assert_held(rq->q->queue_lock); + + if (rq->q->dev && !(rq->rq_flags & RQF_PM)) + --rq->q->nr_pending; } #else +static inline void blk_pm_request_resume(struct request_queue *q) +{ +} + +static inline void blk_pm_mark_last_busy(struct request *rq) +{ +} + static inline void blk_pm_requeue_request(struct request *rq) { } diff --git a/block/elevator.c b/block/elevator.c index e18ac68626e3..1c992bf6cfb1 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -601,6 +601,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where) trace_block_rq_insert(q, rq); blk_pm_add_request(q, rq); + blk_pm_request_resume(q); rq->q = q; From patchwork Wed Sep 26 21:01:06 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: 10616825 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 A9CC8174A for ; Wed, 26 Sep 2018 21:01:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C3F42B869 for ; Wed, 26 Sep 2018 21:01:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9933E2B879; Wed, 26 Sep 2018 21:01:51 +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 3128A2B870 for ; Wed, 26 Sep 2018 21:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727131AbeI0DQi (ORCPT ); Wed, 26 Sep 2018 23:16:38 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:46671 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbeI0DQi (ORCPT ); Wed, 26 Sep 2018 23:16:38 -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=uBCfc78iVK3mvbYzGk18tJrA36SMVNqu3pSnJ8jVaSA=; b=uavhuxIxsSk9 kBd6Uo6nXUWRyOmAJjWIe7KX4RVuRBwi0ELZJlTzI374KlQu+njK1Vnn2p4zX0qGdQ5LaQHyMOieZ XxwD27BEGcOGDHjguuseM1e4O0EwDsvTz/GZgEGuvjsmwCYJZirL/3KqN/+1rh2Ur8Hlhc1FltOTz UZ0aPDffSrzKPqhGnewexDhULoMTqoLAEJ/q1slOl/5/pYCanujxwXZORBJ6izSqdpBntEoqzvcHV CwZmiexaW0za5B/RLeKjTDqARty4IeQDvvP11z+64FLi7X8yO7ck8YBxRFXwS93/5IbJrLoiBK8d4 XwkH3WfxieT9zWaWOhGnbw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwE-000Blr-VH; Wed, 26 Sep 2018 23:01:39 +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 55414C065E; Wed, 26 Sep 2018 23:01:26 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v11 4/8] block: Schedule runtime resume earlier Date: Wed, 26 Sep 2018 14:01:06 -0700 Message-Id: <20180926210110.20362-5-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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: EX5BVjFpneJeBchSMxfU5s+ojrpHzeOiaJyewGmENbV602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMHSXqg+1/i6wndRZnDou0t3MjnTf0b3I3aEFy BYPo6QcHX5Cpvt/psaJ6aKC9ndNRr5DxNcC3a9NPOOrpbOsc/15aEsY3o6JdH+0MvJ57YUkHffPj aOUqQrKwFZ0r5HuSZWIhmoxQGt3RhzWMa6r8xqTQml8ZpIdNBYk88gmcEZ2Cn3oZFShGuGVczvnn MQuy0rkcsjN5WTUa2rnvyK8KFNUcgLpncXQjTqRSupcUAdtQNIZbvzaTp2lzb6yKeJkRcUteS3C7 JQjXdMuE7CS5inlds4jtgW6NDRRWzqEH5+aovGSYm4DcPiK1RTzGCOye8p8NyvSkRHwTwTx9G1M5 EMvdGlnEQJMn5KuObFLxmLqt3Kp8qWCPA1FZmxuhCvuDChIMUBexuGo66F0oVT5ebLBeh8VM266o EX729IUf2Pr+dLgyKn9hRrl7f5fMIEgk5YE5enyccp7RH4WQio3uGUQXsmt/yNpx0PklCztQ7ciy NKvOeLJBg69UhVs/U6xGTgdl742lubk8D3PFoMK67nWQXKQwCFnQgA0sBDrZ5mVqDHVMl1DgJAAN N/5ANsJ1yB2Iv44ISCaVZLyGUM3tAWVpwuzASwXZPOiPrlfesJK/suF3acs/X22+AMezOe+pxeX6 qMom3D4eWmNLtpDoqbL/gtR/SxTxy6k0zK2Jk/vFGF7aZL3P9Pdh/hfO3aeIaBTscQtCa4mpKA50 dHa0uQcr5m7TQiFvcgJmYP1xS/Dpfj5sSQhb3cc4IkKXIhy+shfp3qXUBJH0ogh67fyHwPsvjpNI nfsJSJl6zhVId9zcybgz9lqyJYrkJyOhiWOF4LUtds2PIVxqDVyVUR6OBgUQig1f8ciIH+8RsANu THlM8jeeJSytG/Wf88r2kBubgREubOAI1HpTo1uFObA6Ssw4Oh2LkwsmIC+tUiJAU2FJ/Wta3xQp 0jLHPrxMKzbLqiGD4YwNTvEMgsAYUF+aNC8/3bImoUNQxaBiRh+ELzQgNXgpws1XL6/EsMqND8pC zcQD+FJh68swwj4fTNFxyvNNa6ADxjxmugIOVqoVYrw= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of scheduling runtime resume of a request queue after a request has been queued, schedule asynchronous resume during request allocation. The new pm_request_resume() calls occur after blk_queue_enter() has increased the q_usage_counter request queue member. This change is needed for a later patch that will make request allocation block while the queue status is not RPM_ACTIVE. Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-core.c | 3 ++- block/elevator.c | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index fd91e9bf2893..fec135ae52cf 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -956,7 +956,8 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) wait_event(q->mq_freeze_wq, (atomic_read(&q->mq_freeze_depth) == 0 && - (pm || !blk_queue_pm_only(q))) || + (pm || (blk_pm_request_resume(q), + !blk_queue_pm_only(q)))) || blk_queue_dying(q)); if (blk_queue_dying(q)) return -ENODEV; diff --git a/block/elevator.c b/block/elevator.c index 1c992bf6cfb1..e18ac68626e3 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -601,7 +601,6 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where) trace_block_rq_insert(q, rq); blk_pm_add_request(q, rq); - blk_pm_request_resume(q); rq->q = q; From patchwork Wed Sep 26 21:01:07 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: 10616829 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 A021D15A6 for ; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 928602B870 for ; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90F642B86C; Wed, 26 Sep 2018 21:01:53 +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 1832F2B879 for ; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727124AbeI0DQk (ORCPT ); Wed, 26 Sep 2018 23:16:40 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:44823 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbeI0DQk (ORCPT ); Wed, 26 Sep 2018 23:16:40 -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=IF2qX/VHgwfR5z/Fh0rti5j8s+5Wa+vP3yUmJLbaJ14=; b=QQ8HtB4T0V/5 GOqkrUxbdoC/YjC4RCU/TVsjMfCnYTtLBwWhCqzhGJ0ToWm7DDpcjnF5ehjo0ZToXdZEY7yLvFAKm qE7tN+LEOa9xpEpgb4vzPQSWi4PwADnTxsj1wx1VWxjKFqRPMbuKY9IsUvvp1Ti4uWFM9XeNRbXhy 3+b2qOUL4EvEpaysxxJ4XhuklO1AOrRL5wo+DeRMlcWJS9H5S+yWfw/pdUJOMCZWUe6QrBgolqTUO rjIHWodKmvCDKn2GzV/CPWuwGllSmLteHQGDbPdWST7b1JEhusIL+2amvx6R3yBirlhv/fW64dZWA 863RlqKGb8TmhXEwMNYWyg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwG-000Chy-Qe; Wed, 26 Sep 2018 23:01:41 +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 39A98C070B; Wed, 26 Sep 2018 23:01:28 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v11 5/8] percpu-refcount: Introduce percpu_ref_resurrect() Date: Wed, 26 Sep 2018 14:01:07 -0700 Message-Id: <20180926210110.20362-6-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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.00930287330497) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5sTkyRxkXLtrs6iLERTcNJV602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMzOveuRed9T7jhw/gvmQMah2BgHj1qqhphqeY tp8kfYc/OC96MFmLMn3a2CpBH+gVn+aqqhGehaqtjJG3CJ2yQxgb4qHU7qdjHk+p65BWNojnx8ye plRO3sLIqUlSH7OGvdxBh33r2iOnQNRiYFbeuI/apDCv4F6+gjF5H/I+cgmEcU1f8H19rtY8rZ5d 9L6w6J2bQL19VsxDRzkjBksh9sU0mfwm4D7Y6hdTgZY2kGtYIRYrgwmNBHQ/PlvDLtE2X4Lmr1Eh eh1oAvdyPjNZzZkHtDUeNUPQBvuvTgeocAejtRu5bPC8zl5GPOV9RgMxYWA4ryBb6FrOHzigF4y0 YSOV7QtxJNU+igS6jZCzGqp4kWEmSuvVokrtS84c/atNgYaek/ieoycx5b/lM6HtBzqsOfS1M5Vy YnCojwm7ad63wOzweEy7wCy4L5c/QhZ1rKEHWRD4jzLpim6oa19OKIalL4LoE8AgSzw+KJWjcRvn 9G9MXx3ddMlEc1je9VmHE1+Q9DR4YbQGRn/SCFVSMcnBwnfP7vEWuFdTNkRGVKAamUdylUIKhf3z 2GAHxH7IGHvMFS9R5GM5ovW4ogvVUp7MRJS/jV5z2CK2GM2WgFNgOzqC6O9vDGfG0JRx6xblTX5z omQNzPsffpxoygoK9pWfl7pZaq2OSE6KmBLM5Hfxb5tGDl/EOfj7AjBtUminERWeKKG4PAQYNyav p7c49FtiVj2dQIdtpWb9DGpHRP1rFy3c7RPTULYRp5fhF+0VbDpbQ5kQMtyxYtYunIjNerY1bFNu qLdtH2eYxHCMBe9y2DNwOgV373pfDhBQ21Od6Pt9Zuh5sUny4SJzXtd/yv52d5ii37lsoiY4WlOu gNPAUNUBeQhuaAL6LSHgXSKR50oTLts/mAi3bdTt+kCc099R/pB2d6wxTH4NIgbaz2LZtslouRgY aQdXViPmaVJWcESf3l4QIqLeDGPNdpzYInX9F8/OraGqi3c39Zt9mfMSWy9Woxn8mOOntMfLY7+D hYot+jIbIy+j2P+LZ+1+Cg== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function will be used in a later patch to switch the struct request_queue q_usage_counter from killed back to live. In contrast to percpu_ref_reinit(), this new function does not require that the refcount is zero. Signed-off-by: Bart Van Assche Acked-by: Tejun Heo Reviewed-by: Ming Lei Cc: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn --- include/linux/percpu-refcount.h | 1 + lib/percpu-refcount.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index 009cdf3d65b6..b297cd1cd4f1 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -108,6 +108,7 @@ void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref); void percpu_ref_switch_to_percpu(struct percpu_ref *ref); void percpu_ref_kill_and_confirm(struct percpu_ref *ref, percpu_ref_func_t *confirm_kill); +void percpu_ref_resurrect(struct percpu_ref *ref); void percpu_ref_reinit(struct percpu_ref *ref); /** diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c index 9f96fa7bc000..de10b8c0bff6 100644 --- a/lib/percpu-refcount.c +++ b/lib/percpu-refcount.c @@ -356,11 +356,35 @@ EXPORT_SYMBOL_GPL(percpu_ref_kill_and_confirm); */ void percpu_ref_reinit(struct percpu_ref *ref) { + WARN_ON_ONCE(!percpu_ref_is_zero(ref)); + + percpu_ref_resurrect(ref); +} +EXPORT_SYMBOL_GPL(percpu_ref_reinit); + +/** + * percpu_ref_resurrect - modify a percpu refcount from dead to live + * @ref: perpcu_ref to resurrect + * + * Modify @ref so that it's in the same state as before percpu_ref_kill() was + * called. @ref must be dead but must not yet have exited. + * + * If @ref->release() frees @ref then the caller is responsible for + * guaranteeing that @ref->release() does not get called while this + * function is in progress. + * + * Note that percpu_ref_tryget[_live]() are safe to perform on @ref while + * this function is in progress. + */ +void percpu_ref_resurrect(struct percpu_ref *ref) +{ + unsigned long __percpu *percpu_count; unsigned long flags; spin_lock_irqsave(&percpu_ref_switch_lock, flags); - WARN_ON_ONCE(!percpu_ref_is_zero(ref)); + WARN_ON_ONCE(!(ref->percpu_count_ptr & __PERCPU_REF_DEAD)); + WARN_ON_ONCE(__ref_is_percpu(ref, &percpu_count)); ref->percpu_count_ptr &= ~__PERCPU_REF_DEAD; percpu_ref_get(ref); @@ -368,4 +392,4 @@ void percpu_ref_reinit(struct percpu_ref *ref) spin_unlock_irqrestore(&percpu_ref_switch_lock, flags); } -EXPORT_SYMBOL_GPL(percpu_ref_reinit); +EXPORT_SYMBOL_GPL(percpu_ref_resurrect); From patchwork Wed Sep 26 21:01:08 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: 10616815 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 863B415A6 for ; Wed, 26 Sep 2018 21:01:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78BB32B86C for ; Wed, 26 Sep 2018 21:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CE922B879; Wed, 26 Sep 2018 21:01:46 +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 DE0432B86C for ; Wed, 26 Sep 2018 21:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726107AbeI0DQd (ORCPT ); Wed, 26 Sep 2018 23:16:33 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:38727 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726778AbeI0DQd (ORCPT ); Wed, 26 Sep 2018 23:16:33 -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=q4rx56HlzfQWPmgUMNgD+dZUKP3vcxLqqv9uiYS7+IQ=; b=kLZovlGqURcR kLPcEYWjIUAlkilgMZ8NU2BIK/KgML9zojnHguDmJLa+OloxYQZf9CIf2FELiA4qqyyha3GRaH3i5 FtRF27Up/7EhymZZykij5/QLmWt20apFOwId59UI1eXqgA+u1qdV4eijYAofV7siBrmh7NdFPfMpS UZ+yl6t39t8QfYPnO+g9uuNIZrb5gCPCYiThRyfApSS4ZY/WMN0bZffUtS/IGSekdbLHULYSYhwux YzoTpaxddHcnkDwF4HimdPK77LfLUrjJI98jmhyUdAjvyHqoNrZH4JmKg0Nuhgr+kqtiZ+wyA35fF hPTth/Tl9iL48tPFpoHYTg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwD-000BmJ-RN; Wed, 26 Sep 2018 23:01:38 +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 EBD23C0690; Wed, 26 Sep 2018 23:01:29 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v11 6/8] block: Allow unfreezing of a queue while requests are in progress Date: Wed, 26 Sep 2018 14:01:08 -0700 Message-Id: <20180926210110.20362-7-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5naqiBtMkwFQhvjcAAPuFMN602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMzOveuRed9T7jhw/gvmQMah2BgHj1qqhphqeY tp8kfYc/OC96MFmLMn3a2CpBH+gVn+aqqhGehaqtjJG3CJ2yQxgb4qHU7qdjHk+p65BWNojnx8ye plRO3sLIqUlSH7OGPoFy+OyPxFiXY+zczH/YQo/apDCv4F6+gjF5H/I+cgmEcU1f8H19rtY8rZ5d 9L6w7MrCEId3NbacnImG6gr74MU0mfwm4D7Y6hdTgZY2kGtYIRYrgwmNBHQ/PlvDLtE2X4Lmr1Eh eh1oAvdyPjNZzZkHtDUeNUPQBvuvTgeocAejtRu5bPC8zl5GPOV9RgMxYWA4ryBb6FrOHzigF4y0 YSOV7QtxJNU+igS6jZCzGqp4kWEmSuvVokrtS84c/atN49m/kXtHMZLehVy2OJlt2j3dKxLhoxcm aInYbR5vlqEQ8FC0xKoqAYUC3b/iKxAn7sn//RcLEIwmfxtejjVQPT77A8B3kacn2DKQiba9BNy5 DmlqDiC2WJYfar6LudlMJG8uvyH0HdgIr9W6KBoPmK0jiD6XqsJZtjQxlyCdsexVa64RpPjJgueU tJDRCGDETg49kW3dsUmKMMrElKDAuek3rArodW3i6wDiKKplXYE24owvMGC3U9iOpsGH0C9xKtsE GFxQKV/A63DgbXxEgLqblXF8C5qxxm0pSqlykiqeRArt8zAuv1CL1PnX7j1uJwcvz6VMYEhUT3Fs SRfv27XVwE0TChgFTatR4JQ5EqPV2ZkaS9pjBWrImk+ftYZUUxDFDGperhAL8csF0HfIeSG7X+t1 TW39Ja77LGPpOwAfdqWM/2Uv9Se3gPchNwlSBBVweHe0r89stuxGFeu80NjpWIf2u9hECzjHVJYm zB0wNFwKBhAh7NeKYzwwwYGpIXFoD3qBQ/+jD8DnbY4P22mARozswtw2zJlBnPnfa0dz8Ne0ck6P 4ivKdWmRJx+gN88F2PY5Qd/IVA8Jo8TFp7yCKYHAkCy5d3koL3/Zyry2SweqbjhutBuGyPj/pbiB X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A later patch will call blk_freeze_queue_start() followed by blk_mq_unfreeze_queue() without waiting for q_usage_counter to drop to zero. Make sure that this doesn't cause a kernel warning to appear by switching from percpu_ref_reinit() to percpu_ref_resurrect(). The former namely requires that the refcount it operates on is zero. Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn --- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 85a1c1a59c72..96d501e8663c 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -198,7 +198,7 @@ void blk_mq_unfreeze_queue(struct request_queue *q) freeze_depth = atomic_dec_return(&q->mq_freeze_depth); WARN_ON_ONCE(freeze_depth < 0); if (!freeze_depth) { - percpu_ref_reinit(&q->q_usage_counter); + percpu_ref_resurrect(&q->q_usage_counter); wake_up_all(&q->mq_freeze_wq); } } From patchwork Wed Sep 26 21:01:09 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: 10616821 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 CCCC5174A for ; Wed, 26 Sep 2018 21:01:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE85C2B878 for ; Wed, 26 Sep 2018 21:01:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCE3D2B881; Wed, 26 Sep 2018 21:01: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 2A3F82B801 for ; Wed, 26 Sep 2018 21:01:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727026AbeI0DQf (ORCPT ); Wed, 26 Sep 2018 23:16:35 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:37853 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbeI0DQf (ORCPT ); Wed, 26 Sep 2018 23:16:35 -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=tXt2S3f0cnj/DVH76u7GSUkd1X8RXNQU/GVfW/sF/P8=; b=CYj6tYonx5+A 09qpWBlpFv+2W6S1CTL6KJbS6jkGhdrJ3pmDpzvWEDIbiW8NXYVzkQLPWnPtIYCLwsKc0Iar16Mn2 Pk8S69XbqEKjIVegruxKPw6eIZypkwRHjRtOAMrEhK3ABMU7xl0Lsn/MxZNGvwQpEwxE8Zg9Xld2I ixXAz0m9QUZyruUw30OTQHCilVyaFJRloFpZjPJn4l42QiTZdNdnx7k/BLxqyYhCebQC5Jsnl4NIv N2nZyMtp83V1jo4FlwOhSbcZnZcI3K9TmX1/NNXrVxLWN8ht9dvrqt6TmKy65k5W1ApRAsoZLl2xS S7oUFCn5HS0HFNKZ/R3JEw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwC-000Cir-PB; Wed, 26 Sep 2018 23:01:38 +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 A979BC07CD; Wed, 26 Sep 2018 23:01:31 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v11 7/8] block: Make blk_get_request() block for non-PM requests while suspended Date: Wed, 26 Sep 2018 14:01:09 -0700 Message-Id: <20180926210110.20362-8-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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.00702039783103) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5oG5pPxYsxo4YlzuwMGJl4J602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMHSXqg+1/i6wndRZnDou0t3MjnTf0b3I3aEFy BYPo6QcHX5Cpvt/psaJ6aKC9ndNRr5DxNcC3a9NPOOrpbOsc/15aEsY3o6JdH+0MvJ57YUkHffPj aOUqQrKwFZ0r5HuSZWIhmoxQGt3RhzWMa6r8xndMcSzaPnz+cBwIIQlLH3rKLMyCg2dNZJAK3gbN iIyd0rkcsjN5WTUa2rnvyK8KFNUcgLpncXQjTqRSupcUAdvnmAJMd2XJi2WBeegORjwPcUteS3C7 JQjXdMuE7CS5inlds4jtgW6NDRRWzqEH5+aovGSYm4DcPiK1RTzGCOye8p8NyvSkRHwTwTx9G1M5 EMvdGlnEQJMn5KuObFLxmLqt3Kp8qWCPA1FZmxuhCvuDChIMUBexuGo66F0oVT5ebLBeh8VM266o EX729IUf2PrnsXEBAaJKYpjfiKWbEgl3VN2XPrW0GWVtggfTAFWe5tezYqxGMqsKjARq8PBC4qjt NuCyq3bWzUVTawdcppuUzbBZVuMc79ykmmxiW8WEzzCMIG782Q35z7cX7fYYativnBqkdNfJiIp5 625MlL2N/ZpHR821I3ej0XyyWQz0YAEiRQv+PVjjwa+Z5RFCOMSnhLdk6ydE9LIadmZ0hfZBCtbE guydx7+/OTtKDkewxZmpVTOhdoHzp6H0FKrGw2L1Zsi9ltMHn9uJ3LU07RloP8lGoJ0Gl8mguiiF t2cNluAC8puPex6GxI6zaPdtK+ie4fulhnSKM6+cJSPuNjAUtgZkcRkCnoMzps1w8ZlyWhLf664X dAHfysyXN4qVU7zaLgNeXsteXbVZ7V7ChserFeSt9GG9uqDjVYVG1h9iJ1FfEoXm0/FPF8PR0w36 3lnOjEfyhfVmDFQ4iZHgSboBWJiFA7unadJ7QPnyb8IX1dd1LqYC/51Yw6/N6SqgAFdQvy23SZXS fMZ7RzHGH1l2P9GRlIAs+idL8owqtnKHSXyV66CW3t7Vh1oWmQVaJsnuyf/9FwsQjCZ/G16ONVA9 ZdeHk2ffieDVD4iy08ZiiykcXIjnpOooukgSz+HhAncvEPFWWNtpsvZpiX1a3BQY X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of allowing requests that are not power management requests to enter the queue in runtime suspended status (RPM_SUSPENDED), make the blk_get_request() caller block. This change fixes a starvation issue: it is now guaranteed that power management requests will be executed no matter how many blk_get_request() callers are waiting. For blk-mq, instead of maintaining the q->nr_pending counter, rely on q->q_usage_counter. Call pm_runtime_mark_last_busy() every time a request finishes instead of only if the queue depth drops to zero. Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-core.c | 37 ++++++++----------------------------- block/blk-pm.c | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index fec135ae52cf..16dd3a989753 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2746,30 +2746,6 @@ void blk_account_io_done(struct request *req, u64 now) } } -#ifdef CONFIG_PM -/* - * Don't process normal requests when queue is suspended - * or in the process of suspending/resuming - */ -static bool blk_pm_allow_request(struct request *rq) -{ - switch (rq->q->rpm_status) { - case RPM_RESUMING: - case RPM_SUSPENDING: - return rq->rq_flags & RQF_PM; - case RPM_SUSPENDED: - return false; - default: - return true; - } -} -#else -static bool blk_pm_allow_request(struct request *rq) -{ - return true; -} -#endif - void blk_account_io_start(struct request *rq, bool new_io) { struct hd_struct *part; @@ -2815,11 +2791,14 @@ static struct request *elv_next_request(struct request_queue *q) while (1) { list_for_each_entry(rq, &q->queue_head, queuelist) { - if (blk_pm_allow_request(rq)) - return rq; - - if (rq->rq_flags & RQF_SOFTBARRIER) - break; +#ifdef CONFIG_PM + /* + * If a request gets queued in state RPM_SUSPENDED + * then that's a kernel bug. + */ + WARN_ON_ONCE(q->rpm_status == RPM_SUSPENDED); +#endif + return rq; } /* diff --git a/block/blk-pm.c b/block/blk-pm.c index 9b636960d285..972fbc656846 100644 --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -1,8 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include +#include "blk-mq.h" +#include "blk-mq-tag.h" /** * blk_pm_runtime_init - Block layer runtime PM initialization routine @@ -68,14 +71,40 @@ int blk_pre_runtime_suspend(struct request_queue *q) if (!q->dev) return ret; + WARN_ON_ONCE(q->rpm_status != RPM_ACTIVE); + + /* + * Increase the pm_only counter before checking whether any + * non-PM blk_queue_enter() calls are in progress to avoid that any + * new non-PM blk_queue_enter() calls succeed before the pm_only + * counter is decreased again. + */ + blk_set_pm_only(q); + ret = -EBUSY; + /* Switch q_usage_counter from per-cpu to atomic mode. */ + blk_freeze_queue_start(q); + /* + * Wait until atomic mode has been reached. Since that + * involves calling call_rcu(), it is guaranteed that later + * blk_queue_enter() calls see the pm-only state. See also + * http://lwn.net/Articles/573497/. + */ + percpu_ref_switch_to_atomic_sync(&q->q_usage_counter); + if (percpu_ref_is_zero(&q->q_usage_counter)) + ret = 0; + /* Switch q_usage_counter back to per-cpu mode. */ + blk_mq_unfreeze_queue(q); + spin_lock_irq(q->queue_lock); - if (q->nr_pending) { - ret = -EBUSY; + if (ret < 0) pm_runtime_mark_last_busy(q->dev); - } else { + else q->rpm_status = RPM_SUSPENDING; - } spin_unlock_irq(q->queue_lock); + + if (ret) + blk_clear_pm_only(q); + return ret; } EXPORT_SYMBOL(blk_pre_runtime_suspend); @@ -106,6 +135,9 @@ void blk_post_runtime_suspend(struct request_queue *q, int err) pm_runtime_mark_last_busy(q->dev); } spin_unlock_irq(q->queue_lock); + + if (err) + blk_clear_pm_only(q); } EXPORT_SYMBOL(blk_post_runtime_suspend); @@ -153,13 +185,15 @@ void blk_post_runtime_resume(struct request_queue *q, int err) spin_lock_irq(q->queue_lock); if (!err) { q->rpm_status = RPM_ACTIVE; - __blk_run_queue(q); pm_runtime_mark_last_busy(q->dev); pm_request_autosuspend(q->dev); } else { q->rpm_status = RPM_SUSPENDED; } spin_unlock_irq(q->queue_lock); + + if (!err) + blk_clear_pm_only(q); } EXPORT_SYMBOL(blk_post_runtime_resume); From patchwork Wed Sep 26 21:01:10 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: 10616827 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 AD1FD174A for ; Wed, 26 Sep 2018 21:01:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FA622B85C for ; Wed, 26 Sep 2018 21:01:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D11F2B873; Wed, 26 Sep 2018 21:01:52 +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 3C4A72B850 for ; Wed, 26 Sep 2018 21:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727142AbeI0DQj (ORCPT ); Wed, 26 Sep 2018 23:16:39 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:53071 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727124AbeI0DQj (ORCPT ); Wed, 26 Sep 2018 23:16:39 -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=zsfIoxFVROMrCuZuX6U3D92KIaOewtFEIfyIyWAqBxc=; b=l1750TW7yDMP FTZ7fUXs12tFj+9BX5dbOJLAx+ZmnGpbqagHbPzCr3JLYSPenflrXbdEqx2mvIG3rBvVasnaZvAI/ zwXK8pGa/e5vLN1/j2oSMT16HPABpAB5TyVOf8MALaM8WjUHani6zUMuxzsOsXcHnhDWrJMpD3n2D n15VRBkC7lF0st4t7c/MWXuBzxbio9NjOk8+QrgUeiK6h9aStVdf3m3g8nPtSmM+6g/928ZOkF/KI aHmnm3Ep0xd46VEa+ssT04Tpi00+rmFWcmkWRNxn+b2EPBgrg+85iEYvcz6yP4rHJppnhj2ZNua5B wnMq25MJCEJmPCjYJZKRzw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwD-000BlP-Mp; Wed, 26 Sep 2018 23:01:38 +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 8B505C085C; Wed, 26 Sep 2018 23:01:33 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v11 8/8] blk-mq: Enable support for runtime power management Date: Wed, 26 Sep 2018 14:01:10 -0700 Message-Id: <20180926210110.20362-9-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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: EX5BVjFpneJeBchSMxfU5j9Ne8O6jz441QweizneGdJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMHSXqg+1/i6wndRZnDou0t3MjnTf0b3I3aEFy BYPo6QcHX5Cpvt/psaJ6aKC9ndNRr5DxNcC3a9NPOOrpbOsc/15aEsY3o6JdH+0MvJ57YUkHffPj aOUqQrKwFZ0r5HuSZWIhmoxQGt3RhzWMa6r8xuGezlUyXrdrxt8tPfDhHmGCn3oZFShGuGVczvnn MQuy0rkcsjN5WTUa2rnvyK8KFNUcgLpncXQjTqRSupcUAdtQNIZbvzaTp2lzb6yKeJkRcUteS3C7 JQjXdMuE7CS5inlds4jtgW6NDRRWzqEH5+aovGSYm4DcPiK1RTzGCOye8p8NyvSkRHwTwTx9G1M5 EMvdGlnEQJMn5KuObFLxmLqt3Kp8qWCPA1FZmxuhCvuDChIMUBexuGo66F0oVT5ebLBeh8VM266o EX729IUf2Pr+dLgyKn9hRrl7f5fMIEgk5YE5enyccp7RH4WQio3uGUQXsmt/yNpx0PklCztQ7ciy NKvOeLJBg69UhVs/U6xGTgdl742lubk8D3PFoMK67nWQXKQwCFnQgA0sBDrZ5mVqDHVMl1DgJAAN N/5ANsJ1yB2Iv44ISCaVZLyGUM3tAWVpwuzASwXZPOiPrlfesJK/suF3acs/X22+AMezOe+pSxNj 2PETm8ZhVS/OtUteC7L/gtR/SxTxy6k0zK2Jk/vFGF7aZL3P9Pdh/hfO3aeIaBTscQtCa4mpKA50 dHa0uQcr5m7TQiFvcgJmYP1xS/Dpfj5sSQhb3cc4IkKXIhy+shfp3qXUBJH0ogh67fyHwPVhQDi3 K1CFkYIrhNT7M90zanOYHY3MT9gR73v3ZB3A4LUtds2PIVxqDVyVUR6OBgUQig1f8ciIH+8RsANu THlM8jeeJSytG/Wf88r2kBubgREubOAI1HpTo1uFObA6Ssw4Oh2LkwsmIC+tUiJAU2FJ/Wta3xQp 0jLHPrxMKzbLqiGD4YwNTvEMgsAYUF+aNC8/3bImoUNQxaBiRh+ELzQgNXgpws1XL6/EsMqND8pC zcQD+FJh68swwj4fTNFxyvNNa6ADxjxmugIOVqoVYrw= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that the blk-mq core processes power management requests (marked with RQF_PREEMPT) in other states than RPM_ACTIVE, enable runtime power management for blk-mq. Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-mq.c | 2 ++ block/blk-pm.c | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 96d501e8663c..d384ab700afd 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -33,6 +33,7 @@ #include "blk-mq.h" #include "blk-mq-debugfs.h" #include "blk-mq-tag.h" +#include "blk-pm.h" #include "blk-stat.h" #include "blk-mq-sched.h" #include "blk-rq-qos.h" @@ -475,6 +476,7 @@ static void __blk_mq_free_request(struct request *rq) struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu); const int sched_tag = rq->internal_tag; + blk_pm_mark_last_busy(rq); if (rq->tag != -1) blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag); if (sched_tag != -1) diff --git a/block/blk-pm.c b/block/blk-pm.c index 972fbc656846..f8fdae01bea2 100644 --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -30,12 +30,6 @@ */ void blk_pm_runtime_init(struct request_queue *q, struct device *dev) { - /* Don't enable runtime PM for blk-mq until it is ready */ - if (q->mq_ops) { - pm_runtime_disable(dev); - return; - } - q->dev = dev; q->rpm_status = RPM_ACTIVE; pm_runtime_set_autosuspend_delay(q->dev, -1);