Commit cb07babf authored by Yu Kuai's avatar Yu Kuai
Browse files

block: support to recored bio allocation time in request

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/release-management/issues/IB4E8P


CVE: NA

--------------------------------

The time will be used later for dumping request in blk-io-hierarchy.

Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
parent f7e944b4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -340,6 +340,7 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
	flush_rq->cmd_flags |= (flags & REQ_DRV) | (flags & REQ_FAILFAST_MASK);
	flush_rq->rq_flags |= RQF_FLUSH_SEQ;
	flush_rq->end_io = flush_end_io;
	blk_rq_init_bi_alloc_time(flush_rq, first_rq);
	/*
	 * Order WRITE ->end_io and WRITE rq->ref, and its pair is the one
	 * implied in refcount_inc_not_zero() called from
+1 −0
Original line number Diff line number Diff line
@@ -552,6 +552,7 @@ int blk_rq_append_bio(struct request *rq, struct bio *bio)
		rq->biotail = bio;
		rq->__data_len += (bio)->bi_iter.bi_size;
		bio_crypt_free_ctx(bio);
		blk_rq_update_bi_alloc_time(rq, bio, NULL);
	}

	return 0;
+4 −0
Original line number Diff line number Diff line
@@ -866,6 +866,7 @@ static struct request *attempt_merge(struct request_queue *q,
	req->biotail = next->biotail;

	req->__data_len += blk_rq_bytes(next);
	blk_rq_update_bi_alloc_time(req, NULL, next);

	if (!blk_discard_mergable(req))
		elv_merge_requests(q, req, next);
@@ -996,6 +997,7 @@ static enum bio_merge_status bio_attempt_back_merge(struct request *req,
	req->biotail->bi_next = bio;
	req->biotail = bio;
	req->__data_len += bio->bi_iter.bi_size;
	blk_rq_update_bi_alloc_time(req, bio, NULL);

	bio_crypt_free_ctx(bio);

@@ -1024,6 +1026,7 @@ static enum bio_merge_status bio_attempt_front_merge(struct request *req,

	req->__sector = bio->bi_iter.bi_sector;
	req->__data_len += bio->bi_iter.bi_size;
	blk_rq_update_bi_alloc_time(req, bio, NULL);

	bio_crypt_do_front_merge(req, bio);

@@ -1048,6 +1051,7 @@ static enum bio_merge_status bio_attempt_discard_merge(struct request_queue *q,
	req->biotail = bio;
	req->__data_len += bio->bi_iter.bi_size;
	req->nr_phys_segments = segments + 1;
	blk_rq_update_bi_alloc_time(req, bio, NULL);

	blk_account_io_merge_bio(req);
	return BIO_MERGE_OK;
+34 −0
Original line number Diff line number Diff line
@@ -387,6 +387,8 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
	rq->end_io = NULL;
	rq->end_io_data = NULL;

	blk_rq_init_bi_alloc_time(rq, NULL);

	blk_crypto_rq_set_defaults(rq);
	INIT_LIST_HEAD(&rq->queuelist);
	/* tag was already set */
@@ -4948,6 +4950,38 @@ void blk_mq_cancel_work_sync(struct request_queue *q)
		cancel_delayed_work_sync(&hctx->run_work);
}

#ifdef CONFIG_BLK_BIO_ALLOC_TIME
void blk_rq_init_bi_alloc_time(struct request *rq, struct request *first_rq)
{
	rq->bi_alloc_time_ns = first_rq ? first_rq->bi_alloc_time_ns :
					   blk_time_get_ns();
}

/*
 * Used in following cases to updated request bi_alloc_time_ns:
 *
 * 1) Allocate a new @rq for @bio;
 * 2) @bio is merged to @rq, in this case @merged_rq should be NULL;
 * 3) @merged_rq is merged to @rq, in this case @bio should be NULL;
 */
void blk_rq_update_bi_alloc_time(struct request *rq, struct bio *bio,
				 struct request *merged_rq)
{
	if (bio) {
		if (rq->bi_alloc_time_ns > bio->bi_alloc_time_ns)
			rq->bi_alloc_time_ns = bio->bi_alloc_time_ns;
		return;
	}

	if (!merged_rq)
		return;

	if (rq->bi_alloc_time_ns > merged_rq->bi_alloc_time_ns)
		rq->bi_alloc_time_ns = merged_rq->bi_alloc_time_ns;
}
EXPORT_SYMBOL_GPL(blk_rq_update_bi_alloc_time);
#endif

static int __init blk_mq_init(void)
{
	int i;
+22 −0
Original line number Diff line number Diff line
@@ -190,7 +190,11 @@ struct request {
	rq_end_io_fn *end_io;
	void *end_io_data;

#ifdef CONFIG_BLK_BIO_ALLOC_TIME
	KABI_USE(1, u64 bi_alloc_time_ns)
#else
	KABI_RESERVE(1)
#endif
	KABI_RESERVE(2)
	KABI_RESERVE(3)
	KABI_RESERVE(4)
@@ -957,6 +961,23 @@ static inline bool blk_should_fake_timeout(struct request_queue *q)
	return false;
}

#ifdef CONFIG_BLK_BIO_ALLOC_TIME
void blk_rq_init_bi_alloc_time(struct request *rq, struct request *first_rq);
void blk_rq_update_bi_alloc_time(struct request *rq, struct bio *bio,
				 struct request *merged_rq);
#else /* CONFIG_BLK_BIO_ALLOC_TIME */
static inline void blk_rq_init_bi_alloc_time(struct request *rq,
					     struct request *first_rq)
{
}

static inline void blk_rq_update_bi_alloc_time(struct request *rq,
					       struct bio *bio,
					       struct request *merged_rq)
{
}
#endif

/**
 * blk_mq_rq_from_pdu - cast a PDU to a request
 * @pdu: the PDU (Protocol Data Unit) to be casted
@@ -1005,6 +1026,7 @@ static inline void blk_rq_bio_prep(struct request *rq, struct bio *bio,
	rq->__data_len = bio->bi_iter.bi_size;
	rq->bio = rq->biotail = bio;
	rq->ioprio = bio_prio(bio);
	blk_rq_update_bi_alloc_time(rq, bio, NULL);
}

void blk_mq_hctx_set_fq_lock_class(struct blk_mq_hw_ctx *hctx,