From patchwork Thu Nov 8 16:06:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10674563 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 B65FE15E9 for ; Thu, 8 Nov 2018 16:06:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A161E2DC32 for ; Thu, 8 Nov 2018 16:06:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9446D2DC51; Thu, 8 Nov 2018 16:06:21 +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 3B79E2DC32 for ; Thu, 8 Nov 2018 16:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727722AbeKIBma (ORCPT ); Thu, 8 Nov 2018 20:42:30 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:40361 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbeKIBma (ORCPT ); Thu, 8 Nov 2018 20:42:30 -0500 Received: by mail-it1-f196.google.com with SMTP id e11so2398699itl.5 for ; Thu, 08 Nov 2018 08:06:20 -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=FOBD7MiQYSdHnmk/MbIyUVsuIizwHq7cbuxxKCnojTE=; b=dPtuWGWLqiyhT3S9pdvxWqpoMxpV4RywqJu9zs/kd51EBeAV/XvWmrektKdU3Ldkaq dz/OdvkjZLMkPHfAqtSwByadEzkgXns4I86j8QQ0SMVjcehK8KKybGYSkUYPFqy2xo23 lDB14UH2ygmJcp0d2HHYpuiZU6pXAgqgVxeUomQ7C6EFOOq9DIXDHHXq06mirN5aPuxY EoQiBufHzIWwMB+3fEH1nkw3nB+ZP613SX2uvqySXm8rjtfUsPG7+5B+NQD7+kLgRJC1 NAsIdZG67IFNmErngWNIZEAR1mcBz4yhaes9nE2yAcMoYiqbtGu8CUJU66cXhN3xbG38 wgZQ== 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=FOBD7MiQYSdHnmk/MbIyUVsuIizwHq7cbuxxKCnojTE=; b=UAeAfOwvR51W/yPRr3MwxgNg7gt0Yd0gwZ5CR4TAHusN2k3v58kTpR4k7t5/ibrGXD 0hn+M8xy0uossQTde3YhpOo0VnHzJ34315tPfLEoI1YszuVRTOdGUg5NjNLpOziLBqwP nDKd13HZKsf/0/v4uz7PoY8Ar05qMcTRNWMqrvvEB0X61YUlBuEGg2DXUivTc+s6eyfP oGJogfR8Hmf0Ox68HI0W7s+OsfIU10ln30rd6iVOmibiMjBEgq3voIpKx0pEahdr/Eij FDIM+/D5dBKdj3TiSV5ZpQ7/pYY1lELbBns0hqrHOo7oGwrWArL1wu5Jn9vuHRTj3xCx sKIw== X-Gm-Message-State: AGRZ1gK9U8ki253ounNtC75TgKYKpsqiBsx9IA/0JNzmm3YGA/eef8HA lWSXpiYUn+z9wpF31EnSguoMbQS+EoE= X-Google-Smtp-Source: AJdET5dRnAmsgT4PML7jzR77AuW97L6OjIVedIfK2q07p8PGvC2AgbWwf1Novf+aRPS4GEFX7I2O3A== X-Received: by 2002:a24:258d:: with SMTP id g135-v6mr1777857itg.54.1541693179175; Thu, 08 Nov 2018 08:06:19 -0800 (PST) Received: from x1.thefacebook.com ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id g8-v6sm1821959iof.11.2018.11.08.08.06.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 08:06:17 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/2] blk-mq: provide a helper to check if a queue is busy Date: Thu, 8 Nov 2018 09:06:09 -0700 Message-Id: <20181108160609.27568-4-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181108160609.27568-1-axboe@kernel.dk> References: <20181108160609.27568-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. Reviewed-by: Mike Snitzer Signed-off-by: Jens Axboe Reviewed-by: Bart Van Assche --- block/blk-mq.c | 26 ++++++++++++++++++++++++++ include/linux/blk-mq.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 4a622c832b31..65243c40ac7c 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -790,6 +790,32 @@ 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) +{ + /* + * If we find a request, we know the queue is busy. Return false + * to stop the iteration. + */ + if (rq->q == hctx->queue) { + bool *busy = (bool *) priv; + + *busy = true; + return false; + } + + 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),