From patchwork Fri Jul 13 08:06:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10522743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DB4E602B3 for ; Fri, 13 Jul 2018 08:06:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11ED22941E for ; Fri, 13 Jul 2018 08:06:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 068E32990C; Fri, 13 Jul 2018 08:06:31 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 944A329A36 for ; Fri, 13 Jul 2018 08:06:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731946AbeGMIUA (ORCPT ); Fri, 13 Jul 2018 04:20:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729790AbeGMIUA (ORCPT ); Fri, 13 Jul 2018 04:20:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EECD40122C8; Fri, 13 Jul 2018 08:06:27 +0000 (UTC) Received: from localhost (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id E745910FFE4D; Fri, 13 Jul 2018 08:06:16 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Ming Lei , "Rafael J. Wysocki" , Alan Stern , linux-pm@vger.kernel.org, Greg Kroah-Hartman , Christoph Hellwig , Bart Van Assche , Hannes Reinecke , Johannes Thumshirn , Adrian Hunter , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH RFC V2 1/3] block: put runtime PM code into common helpers Date: Fri, 13 Jul 2018 16:06:00 +0800 Message-Id: <20180713080602.31602-2-ming.lei@redhat.com> In-Reply-To: <20180713080602.31602-1-ming.lei@redhat.com> References: <20180713080602.31602-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 13 Jul 2018 08:06:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 13 Jul 2018 08:06:27 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So that the following patch can reuse these helpers for supporting runtime PM on blk-mq. No function change. Cc: "Rafael J. Wysocki" Cc: Alan Stern Cc: linux-pm@vger.kernel.org Cc: Greg Kroah-Hartman Cc: Christoph Hellwig Cc: Bart Van Assche Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Adrian Hunter Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Signed-off-by: Ming Lei --- block/blk-core.c | 71 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index c4b57d8806fe..1087a58590f1 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -3746,6 +3746,50 @@ void blk_finish_plug(struct blk_plug *plug) EXPORT_SYMBOL(blk_finish_plug); #ifdef CONFIG_PM +static int __blk_pre_runtime_suspend(struct request_queue *q, bool active) +{ + int ret; + + if (active) { + ret = -EBUSY; + pm_runtime_mark_last_busy(q->dev); + } else { + ret = 0; + q->rpm_status = RPM_SUSPENDING; + } + + return ret; +} + +static void __blk_post_runtime_suspend(struct request_queue *q, int err) +{ + if (!err) { + q->rpm_status = RPM_SUSPENDED; + } else { + q->rpm_status = RPM_ACTIVE; + pm_runtime_mark_last_busy(q->dev); + } +} + +static void __blk_post_runtime_resume(struct request_queue *q, int err) +{ + 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; + } +} + +static void __blk_set_runtime_active(struct request_queue *q) +{ + q->rpm_status = RPM_ACTIVE; + pm_runtime_mark_last_busy(q->dev); + pm_request_autosuspend(q->dev); +} + /** * blk_pm_runtime_init - Block layer runtime PM initialization routine * @q: the queue of the device @@ -3809,12 +3853,7 @@ int blk_pre_runtime_suspend(struct request_queue *q) 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; - } + ret = __blk_pre_runtime_suspend(q, q->nr_pending); spin_unlock_irq(q->queue_lock); return ret; } @@ -3839,12 +3878,7 @@ void blk_post_runtime_suspend(struct request_queue *q, int err) 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); - } + __blk_post_runtime_suspend(q, err); spin_unlock_irq(q->queue_lock); } EXPORT_SYMBOL(blk_post_runtime_suspend); @@ -3891,14 +3925,7 @@ void blk_post_runtime_resume(struct request_queue *q, int err) 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; - } + __blk_post_runtime_resume(q, err); spin_unlock_irq(q->queue_lock); } EXPORT_SYMBOL(blk_post_runtime_resume); @@ -3920,9 +3947,7 @@ EXPORT_SYMBOL(blk_post_runtime_resume); 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); + __blk_set_runtime_active(q); spin_unlock_irq(q->queue_lock); } EXPORT_SYMBOL(blk_set_runtime_active);