From patchwork Wed Jul 11 16:29:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10520189 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 2B47E600CA for ; Wed, 11 Jul 2018 16:30:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E62928BDC for ; Wed, 11 Jul 2018 16:30:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12A9D295CC; Wed, 11 Jul 2018 16:30:04 +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 E9746295A5 for ; Wed, 11 Jul 2018 16:30:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387855AbeGKQfH (ORCPT ); Wed, 11 Jul 2018 12:35:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58784 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726609AbeGKQfH (ORCPT ); Wed, 11 Jul 2018 12:35:07 -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 29B3E14B38F; Wed, 11 Jul 2018 16:30:00 +0000 (UTC) Received: from localhost (ovpn-12-22.pek2.redhat.com [10.72.12.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEC70111AF36; Wed, 11 Jul 2018 16:29:49 +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 , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH RFC 2/4] blk-mq: introduce blk_mq_pm_queue_idle() Date: Thu, 12 Jul 2018 00:29:04 +0800 Message-Id: <20180711162906.14271-3-ming.lei@redhat.com> In-Reply-To: <20180711162906.14271-1-ming.lei@redhat.com> References: <20180711162906.14271-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.1]); Wed, 11 Jul 2018 16:30:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 11 Jul 2018 16:30:00 +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 This helper will be used to decide if this block device can be put into runtime suspend. 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: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Signed-off-by: Ming Lei --- block/blk-mq.c | 22 ++++++++++++++++++++++ block/blk-mq.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 73a43b81b17d..3a78fed87959 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -58,6 +58,28 @@ static int blk_mq_poll_stats_bkt(const struct request *rq) return bucket; } +static void blk_mq_pm_check_idle(struct blk_mq_hw_ctx *hctx, + struct request *rq, void *priv, bool reserved) +{ + unsigned long *cnt = priv; + + if (!(rq->rq_flags & RQF_PM)) + (*cnt)++; +} + +bool blk_mq_pm_queue_idle(struct request_queue *q) +{ + unsigned long idle_cnt; + + if (!blk_mq_support_runtime_pm(q)) + return false; + + idle_cnt = 0; + blk_mq_queue_tag_busy_iter(q, blk_mq_pm_check_idle, &idle_cnt); + + return idle_cnt == 0; +} + /* * Check if any of the ctx's have pending work in this hardware queue */ diff --git a/block/blk-mq.h b/block/blk-mq.h index bc2b24735ed4..b64f6f69176a 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -88,6 +88,9 @@ extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx); void blk_mq_release(struct request_queue *q); +/* blk-mq pm helpers */ +bool blk_mq_pm_queue_idle(struct request_queue *q); + /** * blk_mq_rq_state() - read the current MQ_RQ_* state of a request * @rq: target request.