From patchwork Thu Nov 8 15:42:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10674541 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 D69731709 for ; Thu, 8 Nov 2018 15:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C75C22E02E for ; Thu, 8 Nov 2018 15:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBDBC2E011; Thu, 8 Nov 2018 15:42:24 +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 F3E482E031 for ; Thu, 8 Nov 2018 15:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbeKIBS1 (ORCPT ); Thu, 8 Nov 2018 20:18:27 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:36359 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726417AbeKIBS0 (ORCPT ); Thu, 8 Nov 2018 20:18:26 -0500 Received: by mail-io1-f67.google.com with SMTP id o19-v6so14926118iod.3 for ; Thu, 08 Nov 2018 07:42:22 -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=fggFrnxuNbZZrZBJIDY7kcu87DvbSRdgGYyQsrUkOJk=; b=0ahyHVcKO73f1lsIO8KTUGAXiRvRte1AFglDsI/bVdlBOc8LuWTXg3ZiRvYhKTtcPN Wupw0ZSX8TStrRgT+kxiXiBb4DcFFYqiMbMO80RvabjPREKMbN+k5HpJmOUI3QVrlbAD LrrZkyCOEtMk2R+GhALam5X03NKw47OESVCf3SQxSoVUQtQ1p5y3FqEXr/yKgvsbIZEH 5D7v9teJE9amuGs1FynkejP8ruvXeQhVHzoPjJpOSUUS9+DvTXmQ4yfj/FR0aJdSgvHE GucjV49lRVAF59eYnsLuW9EMcYSnXfC0ZO86S/ENTX/eJKwZmnibnxrBGaWPc/ZLu13+ oCLQ== 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=fggFrnxuNbZZrZBJIDY7kcu87DvbSRdgGYyQsrUkOJk=; b=drY9YMN5YcIjeUn+B3/iNTf6hVcKDlG62nlwSj5Ys4lV1vuQSw6FJj5k2BBDIQJqyX axDIXQ8a0aWtp43DcHH1ZFrBDsydl7kF9Opz52cFeRrio9YdrE3mhtdGYsnR8iGqZsf1 4ELsbVukAwtuEjD7UX0tN/6zZWPBn+Oq7CzTMowPHVeVMIKt/HvIdYFhGiRBKumivFvN qdNOMgUppJ0b4Ts6KTl/IYIKZ5TAAV/tcN+KpC6fmuVk51Tye2nsQzFjD5S6k2EQ5xaN IgWSH5DU0VfjMgT/uD59exe3QGxHeNvSKMIgEU1bA35PZVmWA2G77d5uMLRpAzgDtcQK 0HHQ== X-Gm-Message-State: AGRZ1gLmd1TYTVMEe2FzN8SpAqlW3TQxaVRETjrm6JpkTsWBjEfLBmlt M/oF6HilnsZj5wWpSljDFGR+S6lHq0c= X-Google-Smtp-Source: AJdET5cOVBflUK91ikjoznTTVRzoQs+VJcZSNpKsip5HKAJ3LOSuwJAtlzHc3Gmn2rbD3YX24rFO4g== X-Received: by 2002:a6b:1582:: with SMTP id 124-v6mr3890050iov.204.1541691741617; Thu, 08 Nov 2018 07:42:21 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 07:42:20 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe , Mike Snitzer Subject: [PATCH 1/2] blk-mq-tag: change busy_iter_fn to return whether to continue or not Date: Thu, 8 Nov 2018 08:42:15 -0700 Message-Id: <20181108154216.23853-2-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 We have this functionality in sbitmap, but we don't export it in blk-mq for users of the tags busy iteration. This can be useful for stopping the iteration, if the caller doesn't need to find more requests. Cc: Mike Snitzer Signed-off-by: Jens Axboe Reviewed-by: Mike Snitzer --- block/blk-mq-debugfs.c | 4 +++- block/blk-mq-tag.c | 4 ++-- block/blk-mq.c | 16 +++++++++++----- include/linux/blk-mq.h | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index cde19be36135..4f61632af6f4 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -424,13 +424,15 @@ struct show_busy_params { * Note: the state of a request may change while this function is in progress, * e.g. due to a concurrent blk_mq_finish_request() call. */ -static void hctx_show_busy_rq(struct request *rq, void *data, bool reserved) +static bool hctx_show_busy_rq(struct request *rq, void *data, bool reserved) { const struct show_busy_params *params = data; if (rq->mq_hctx == params->hctx) __blk_mq_debugfs_rq_show(params->m, list_entry_rq(&rq->queuelist)); + + return true; } static int hctx_busy_show(void *data, struct seq_file *m) diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index fb836d818b80..097e9a67d5f5 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -236,7 +236,7 @@ static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data) * test and set the bit before assigning ->rqs[]. */ if (rq && rq->q == hctx->queue) - iter_data->fn(hctx, rq, iter_data->data, reserved); + return iter_data->fn(hctx, rq, iter_data->data, reserved); return true; } @@ -289,7 +289,7 @@ static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data) */ rq = tags->rqs[bitnr]; if (rq && blk_mq_request_started(rq)) - iter_data->fn(rq, iter_data->data, reserved); + return iter_data->fn(rq, iter_data->data, reserved); return true; } diff --git a/block/blk-mq.c b/block/blk-mq.c index 45c92b8d4795..4a622c832b31 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -94,7 +94,7 @@ struct mq_inflight { unsigned int *inflight; }; -static void blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, +static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, struct request *rq, void *priv, bool reserved) { @@ -109,6 +109,8 @@ static void blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, mi->inflight[0]++; if (mi->part->partno) mi->inflight[1]++; + + return true; } void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part, @@ -120,7 +122,7 @@ void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part, blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi); } -static void blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx, +static bool blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx, struct request *rq, void *priv, bool reserved) { @@ -128,6 +130,8 @@ static void blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx, if (rq->part == mi->part) mi->inflight[rq_data_dir(rq)]++; + + return true; } void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part, @@ -821,7 +825,7 @@ static bool blk_mq_req_expired(struct request *rq, unsigned long *next) return false; } -static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, +static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, struct request *rq, void *priv, bool reserved) { unsigned long *next = priv; @@ -831,7 +835,7 @@ static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, * so we're not unnecessarilly synchronizing across CPUs. */ if (!blk_mq_req_expired(rq, next)) - return; + return true; /* * We have reason to believe the request may be expired. Take a @@ -843,7 +847,7 @@ static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, * timeout handler to posting a natural completion. */ if (!refcount_inc_not_zero(&rq->ref)) - return; + return true; /* * The request is now locked and cannot be reallocated underneath the @@ -855,6 +859,8 @@ static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, blk_mq_rq_timed_out(rq, reserved); if (refcount_dec_and_test(&rq->ref)) __blk_mq_free_request(rq); + + return true; } static void blk_mq_timeout_work(struct work_struct *work) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 9f5e93f40857..ff497dfcbbf9 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -129,9 +129,9 @@ typedef int (init_request_fn)(struct blk_mq_tag_set *set, struct request *, typedef void (exit_request_fn)(struct blk_mq_tag_set *set, struct request *, unsigned int); -typedef void (busy_iter_fn)(struct blk_mq_hw_ctx *, struct request *, void *, +typedef bool (busy_iter_fn)(struct blk_mq_hw_ctx *, struct request *, void *, bool); -typedef void (busy_tag_iter_fn)(struct request *, void *, bool); +typedef bool (busy_tag_iter_fn)(struct request *, void *, bool); typedef int (poll_fn)(struct blk_mq_hw_ctx *, unsigned int); typedef int (map_queues_fn)(struct blk_mq_tag_set *set); typedef bool (busy_fn)(struct request_queue *);