From patchwork Thu Nov 8 15:42:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10674543 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 1183314BD for ; Thu, 8 Nov 2018 15:42:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 015872E033 for ; Thu, 8 Nov 2018 15:42:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E95252E03F; Thu, 8 Nov 2018 15:42:25 +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,DKIM_SIGNED, DKIM_VALID,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 7F1F22DF5F for ; Thu, 8 Nov 2018 15:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727005AbeKIBS2 (ORCPT ); Thu, 8 Nov 2018 20:18:28 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:33444 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726417AbeKIBS2 (ORCPT ); Thu, 8 Nov 2018 20:18:28 -0500 Received: by mail-io1-f65.google.com with SMTP id f12-v6so14956699iog.0 for ; Thu, 08 Nov 2018 07:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Vjsnj4iye7Yy9ynWuvMBYnZa5W68EXsl0YHGdK8STFU=; b=QDrj6c0eWdtQD6+niom8ohOYyctrUX+zrnFTSnd2wUZHuMp4qHuTmfZWqa0yF53LlV cz2FfizpB4lbI0yDJquUEPZY36JC5MaHY9FlzB+ICpGL/cPd/8viKzmAvb7xsIx2q/ww zvvPvSqZw+M5EWwFp0bgvnk0kvYy+BGlr7lfuR88804Ptb0fZmJKsXF9swArWoQUmnbq nacvNl316D47apefNAFHMZYXicBrXsTrjuyTHmVnat20tl2RVthYykqkOUYBvdWwU8es ueWI5/37agFl+shiR0VwUpUiservgBiA1iImP0pKluNfM7+tlW9Q4GJ/smFq3MtT1KL0 niAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Vjsnj4iye7Yy9ynWuvMBYnZa5W68EXsl0YHGdK8STFU=; b=mdXtCja3QW86DSDtKA4BYKsVk4hzpd3LQoA/merTwyMSm5Piw4d1o9IsI9axgBl8EV A7o1vrZMOgy+3ZTmfOM1ms1s7aN6DBA3So2O67fihCDWopNBjZWf+z5DiDrGmpzoyCby NnnG5v2t5I/h95Z6/3qIeKZpbrGwSyEl1VAnVIsHXtVrvHBCb5iBOKpvFZ7xRbWdLJtO TLCpnfdDzrRoEiDDmX28C7RnbbkNjrLEXG3eeSVBYwTFZg4YuHvPkbLDcXfvvct5DgWM WV6zVm0bvSaAyHxRuNy2qWsmhKUtzVandao1F11mzV1HGx4lL5ld6/EjdjhfzHXJb8od 1e9w== X-Gm-Message-State: AGRZ1gIfW5ktGDi9aT/WVbYV7NxZwu7RGdSmlx1pK7Dz/Qx/5+IyBaCR DAz/e/2kp4eiyFfwgEMBcKBmDj0avko= X-Google-Smtp-Source: AJdET5f6WxNlSduFWKBhSKn8LdiNDUtCyLTBWAmv+2otGUiEVC/NsDojpcz3DicCekr+6Xz1kLf8gQ== X-Received: by 2002:a6b:c94e:: with SMTP id z75-v6mr4155649iof.159.1541691743181; Thu, 08 Nov 2018 07:42:23 -0800 (PST) Received: from x1.thefacebook.com ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id i8-v6sm1391185iom.47.2018.11.08.07.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 07:42:22 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe , Mike Snitzer Subject: [PATCH 2/2] blk-mq: provide a helper to check if a queue is busy Date: Thu, 8 Nov 2018 08:42:16 -0700 Message-Id: <20181108154216.23853-3-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181108154216.23853-1-axboe@kernel.dk> References: <20181108154216.23853-1-axboe@kernel.dk> 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 Returns true if the queue currently has requests pending, false if not. DM can use this to replace the atomic_inc/dec they do per device to see if a device is busy. Cc: Mike Snitzer Signed-off-by: Jens Axboe Reviewed-by: Mike Snitzer --- block/blk-mq.c | 22 ++++++++++++++++++++++ include/linux/blk-mq.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 4a622c832b31..848adcc51c43 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -790,6 +790,28 @@ struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag) } EXPORT_SYMBOL(blk_mq_tag_to_rq); +static bool blk_mq_check_busy(struct blk_mq_hw_ctx *hctx, struct request *rq, + void *priv, bool reserved) +{ + bool *busy = (bool *) priv; + + /* + * If we find a request, we know the queue is busy. Return false + * to stop the iteration. + */ + *busy = true; + return false; +} + +bool blk_mq_queue_busy(struct request_queue *q) +{ + bool busy = false; + + blk_mq_queue_tag_busy_iter(q, blk_mq_check_busy, &busy); + return busy; +} +EXPORT_SYMBOL_GPL(blk_mq_queue_busy); + static void blk_mq_rq_timed_out(struct request *req, bool reserved) { req->rq_flags |= RQF_TIMED_OUT; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index ff497dfcbbf9..929e8abc5535 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -250,6 +250,8 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule); void blk_mq_free_request(struct request *rq); bool blk_mq_can_queue(struct blk_mq_hw_ctx *); +bool blk_mq_queue_busy(struct request_queue *q); + enum { /* return when out of requests */ BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 << 0),