Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1077377ybx; Tue, 5 Nov 2019 09:56:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyB1xprz+soe0frxzg8ZmcFzwpp7gEYyuJba5ffy2N/T8jnu8wqVVhxHhxuQMRvBJx2uHcJ X-Received: by 2002:a50:ac2c:: with SMTP id v41mr36508113edc.11.1572976601350; Tue, 05 Nov 2019 09:56:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572976601; cv=none; d=google.com; s=arc-20160816; b=lmli0fi4monMk/UYLxUJOyuizdgjohpaOk4ajJ6woUTQSogKQBie7iTjJSPo3usEA9 qkzTPvCSHn2XU/fPKCPfHLMIzdli8B6sBtXRNFQwxjyh2/eWdYT7VF3I7j0/E+kd1PaF sg/5lITQim+lLbd0Z6ZhMtI4WuIoMT90VKe4acIStss7jShxjS0Ye4m+xu9A2xhhFyOI 0yvf6aPOiHgVCQGjY50fy2shOPlby4mP9QfGoyLjGN+TazOq6JGGsTYF4Iflc7ozqiOt 5yAdKTCkoyHRznH2fq4xPLFdEiItLeMXGDlhAQeZ575ZruZF869gG5Xalj+ZfruJUHL2 g1Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=GFSoostlBdwJeknp5P4TrEx7yxvB3u7wnTuTfGsXbh4=; b=kQANDvm4aM0skoAPxlUyIi9W3CLnAcbC0wjGT96oFORHKSFMra/pC+873WoIpZ3as3 1qvAmwM+NZO/DTLldyAMqSow8tF9n57kNm+ROp8u+xBfhzjyeDSCr68e1lnAi75BjgW/ 5lzkSFkwTnKYA/hT51BwYFIxWp8pnCOITNHmBjIRzluVvPkF195zFyQX4mpwNBYlFGHj d4FUTT8nxAGFmWAqpea71eWxpJh2I33G1WDv5FPXqWDPF5dfKFaw9YaIawpEDWOVCbR6 Bvs5mHtPxb8g1idiicKeiXD6egKwj2ZtV0H1J2lJb+9wvMSOfb67LUuyccoZo9jPCq+J E7bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y14si9965246edu.250.2019.11.05.09.56.18; Tue, 05 Nov 2019 09:56:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390557AbfKERzp (ORCPT + 99 others); Tue, 5 Nov 2019 12:55:45 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:50866 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390398AbfKERzp (ORCPT ); Tue, 5 Nov 2019 12:55:45 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 6A2B528F76D From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: axboe@kernel.dk, kernel@collabora.com, krisman@collabora.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v3] blk-mq: Document functions for sending request Date: Tue, 5 Nov 2019 14:53:37 -0300 Message-Id: <20191105175337.20426-1-andrealmeid@collabora.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add and improve documentation for function regarding creating and sending IO requests to the hardware. Signed-off-by: André Almeida --- Hello, I did my best to describe all variations of *_run_hw_queue, although their names and functionally are really similar. I would be happy to get feedback about those functions descriptions. Those comments were tested with: ./scripts/kernel-doc -none block/blk-mq.c Which did not returned any warning or error. Thanks, André Changes since v2: - Update blk_mq_run_hw_queue() from bool to void type Changes since v1: - Add documentation for blk_mq_start_request() --- block/blk-mq.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 5c9adcaa27ac..ba7ffd47fb98 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -647,6 +647,14 @@ bool blk_mq_complete_request(struct request *rq) } EXPORT_SYMBOL(blk_mq_complete_request); +/** + * blk_mq_start_request - Start processing a request + * @rq: Pointer to request to be started + * + * Function used by device drivers to notify the block layer that a request + * is going to be processed now, so blk layer can do proper initializations + * such as starting the timeout timer. + */ void blk_mq_start_request(struct request *rq) { struct request_queue *q = rq->q; @@ -1333,6 +1341,12 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, return (queued + errors) != 0; } +/** + * __blk_mq_run_hw_queue - Run a hardware queue. + * @hctx: Pointer to the hardware queue to run. + * + * Send pending requests to the hardware. + */ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx) { int srcu_idx; @@ -1430,6 +1444,15 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx) return next_cpu; } +/** + * __blk_mq_delay_run_hw_queue - Run (or schedule to run) a hardware queue. + * @hctx: Pointer to the hardware queue to run. + * @async: If we want to run the queue asynchronously. + * @msecs: Microseconds of delay to wait before running the queue. + * + * If !@async, try to run the queue now. Else, run the queue asynchronously and + * with a delay of @msecs. + */ static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async, unsigned long msecs) { @@ -1451,12 +1474,28 @@ static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async, msecs_to_jiffies(msecs)); } +/** + * blk_mq_delay_run_hw_queue - Run a hardware queue asynchronously. + * @hctx: Pointer to the hardware queue to run. + * @msecs: Microseconds of delay to wait before running the queue. + * + * Run a hardware queue asynchronously with a delay of @msecs. + */ void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs) { __blk_mq_delay_run_hw_queue(hctx, true, msecs); } EXPORT_SYMBOL(blk_mq_delay_run_hw_queue); +/** + * blk_mq_run_hw_queue - Start to run a hardware queue. + * @hctx: Pointer to the hardware queue to run. + * @async: If we want to run the queue asynchronously. + * + * Check if the request queue is not in a quiesced state and if there are + * pending requests to be sent. If this is true, run the queue to send requests + * to hardware. + */ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async) { int srcu_idx; @@ -1480,6 +1519,11 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async) } EXPORT_SYMBOL(blk_mq_run_hw_queue); +/** + * blk_mq_run_hw_queue - Run all hardware queues in a request queue. + * @q: Pointer to the request queue to run. + * @async: If we want to run the queue asynchronously. + */ void blk_mq_run_hw_queues(struct request_queue *q, bool async) { struct blk_mq_hw_ctx *hctx; @@ -1631,7 +1675,11 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, blk_mq_hctx_mark_pending(hctx, ctx); } -/* +/** + * blk_mq_request_bypass_insert - Insert a request at dispatch list. + * @rq: Pointer to request to be inserted. + * @run_queue: If we should run the hardware queue after inserting the request. + * * Should only be used carefully, when the caller knows we want to * bypass a potential IO scheduler on the target device. */ @@ -1834,6 +1882,17 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, return BLK_STS_OK; } +/** + * blk_mq_try_issue_directly - Try to send a request directly to device driver. + * @hctx: Pointer of the associated hardware queue. + * @rq: Pointer to request to be sent. + * @cookie: Request queue cookie. + * + * If the device has enough resources to accept a new request now, send the + * request directly to device driver. Else, insert at hctx->dispatch queue, so + * we can try send it another time in the future. Requests inserted at this + * queue have higher priority. + */ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, struct request *rq, blk_qc_t *cookie) { @@ -1911,6 +1970,22 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq) } } +/** + * blk_mq_make_request - Create and send a request to block device. + * @q: Request queue pointer. + * @bio: Bio pointer. + * + * Builds up a request structure from @q and @bio and send to the device. The + * request may not be queued directly to hardware if: + * * This request can be merged with another one + * * We want to place request at plug queue for possible future merging + * * There is an IO scheduler active at this queue + * + * It will not queue the request if there is an error with the bio, or at the + * request creation. + * + * Returns: Request queue cookie. + */ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) { const int is_sync = op_is_sync(bio->bi_opf); @@ -1956,7 +2031,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) plug = blk_mq_plug(q, bio); if (unlikely(is_flush_fua)) { - /* bypass scheduler for flush rq */ + /* Bypass scheduler for flush requests */ blk_insert_flush(rq); blk_mq_run_hw_queue(data.hctx, true); } else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs || @@ -1984,6 +2059,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) blk_add_rq_to_plug(plug, rq); } else if (q->elevator) { + /* Insert the request at the IO scheduler queue */ blk_mq_sched_insert_request(rq, false, true, true); } else if (plug && !blk_queue_nomerges(q)) { /* @@ -2010,8 +2086,13 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) } } else if ((q->nr_hw_queues > 1 && is_sync) || !data.hctx->dispatch_busy) { + /* + * There is no scheduler and we can try to send directly + * to the hardware. + */ blk_mq_try_issue_directly(data.hctx, rq, &cookie); } else { + /* Default case. */ blk_mq_sched_insert_request(rq, false, true, true); } -- 2.23.0