Commit 49fee5a6 authored by Jens Axboe's avatar Jens Axboe Committed by Yu Kuai
Browse files

block: add blk_time_get_ns() and blk_time_get() helpers

mainline inclusion
from mainline-v6.9-rc1
commit 08420cf70cfb32eed2a0abfeb5c54c5651bd0c99
category: feature
bugzilla: https://gitee.com/openeuler/release-management/issues/IB4E8P
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=08420cf70cfb32eed2a0abfeb5c54c5651bd0c99



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

Convert any user of ktime_get_ns() to use blk_time_get_ns(), and
ktime_get() to blk_time_get(), so we have a unified API for querying the
current time in nanoseconds or as ktime.

No functional changes intended, this patch just wraps ktime_get_ns()
and ktime_get() with a block helper.

Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Conflicts:
	block/blk-cgroup.c
[commit a65983d9 ("sched/psi: Introduce fine grained stall time collect
for cgroup reclaim") changes context in blkcg_maybe_throttle_blkg().]
	block/blk-io-hierarchy/stats.c
[Also change ktime_get_ns() from self-innovate patch.]
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
parent 49b57a69
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ static void bfqg_stats_update_group_wait_time(struct bfqg_stats *stats)
	if (!bfqg_stats_waiting(stats))
		return;

	now = ktime_get_ns();
	now = blk_time_get_ns();
	if (now > stats->start_group_wait_time)
		bfq_stat_add(&stats->group_wait_time,
			      now - stats->start_group_wait_time);
@@ -144,7 +144,7 @@ static void bfqg_stats_set_start_group_wait_time(struct bfq_group *bfqg,
		return;
	if (bfqg == curr_bfqg)
		return;
	stats->start_group_wait_time = ktime_get_ns();
	stats->start_group_wait_time = blk_time_get_ns();
	bfqg_stats_mark_waiting(stats);
}

@@ -156,7 +156,7 @@ static void bfqg_stats_end_empty_time(struct bfqg_stats *stats)
	if (!bfqg_stats_empty(stats))
		return;

	now = ktime_get_ns();
	now = blk_time_get_ns();
	if (now > stats->start_empty_time)
		bfq_stat_add(&stats->empty_time,
			      now - stats->start_empty_time);
@@ -183,7 +183,7 @@ void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg)
	if (bfqg_stats_empty(stats))
		return;

	stats->start_empty_time = ktime_get_ns();
	stats->start_empty_time = blk_time_get_ns();
	bfqg_stats_mark_empty(stats);
}

@@ -192,7 +192,7 @@ void bfqg_stats_update_idle_time(struct bfq_group *bfqg)
	struct bfqg_stats *stats = &bfqg->stats;

	if (bfqg_stats_idling(stats)) {
		u64 now = ktime_get_ns();
		u64 now = blk_time_get_ns();

		if (now > stats->start_idle_time)
			bfq_stat_add(&stats->idle_time,
@@ -205,7 +205,7 @@ void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg)
{
	struct bfqg_stats *stats = &bfqg->stats;

	stats->start_idle_time = ktime_get_ns();
	stats->start_idle_time = blk_time_get_ns();
	bfqg_stats_mark_idling(stats);
}

@@ -242,7 +242,7 @@ void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
				  u64 io_start_time_ns, blk_opf_t opf)
{
	struct bfqg_stats *stats = &bfqg->stats;
	u64 now = ktime_get_ns();
	u64 now = blk_time_get_ns();

	if (now > io_start_time_ns)
		blkg_rwstat_add(&stats->service_time, opf,
+14 −14
Original line number Diff line number Diff line
@@ -1005,7 +1005,7 @@ static struct request *bfq_check_fifo(struct bfq_queue *bfqq,

	rq = rq_entry_fifo(bfqq->fifo.next);

	if (rq == last || ktime_get_ns() < rq->fifo_time)
	if (rq == last || blk_time_get_ns() < rq->fifo_time)
		return NULL;

	bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq);
@@ -1829,7 +1829,7 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
		 * bfq_bfqq_update_budg_for_activation for
		 * details on the usage of the next variable.
		 */
		arrived_in_time =  ktime_get_ns() <=
		arrived_in_time =  blk_time_get_ns() <=
			bfqq->ttime.last_end_request +
			bfqd->bfq_slice_idle * 3;
	unsigned int act_idx = bfq_actuator_index(bfqd, rq->bio);
@@ -2208,7 +2208,7 @@ static void bfq_add_request(struct request *rq)
	struct request *next_rq, *prev;
	unsigned int old_wr_coeff = bfqq->wr_coeff;
	bool interactive = false;
	u64 now_ns = ktime_get_ns();
	u64 now_ns = blk_time_get_ns();

	bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq));
	bfqq->queued[rq_is_sync(rq)]++;
@@ -2262,7 +2262,7 @@ static void bfq_add_request(struct request *rq)
		      bfqd->rqs_injected && bfqd->tot_rq_in_driver > 0)) &&
		    time_is_before_eq_jiffies(bfqq->decrease_time_jif +
					      msecs_to_jiffies(10))) {
			bfqd->last_empty_occupied_ns = ktime_get_ns();
			bfqd->last_empty_occupied_ns = blk_time_get_ns();
			/*
			 * Start the state machine for measuring the
			 * total service time of rq: setting
@@ -3296,7 +3296,7 @@ static void bfq_set_budget_timeout(struct bfq_data *bfqd,
	else
		timeout_coeff = bfqq->entity.weight / bfqq->entity.orig_weight;

	bfqd->last_budget_start = ktime_get();
	bfqd->last_budget_start = blk_time_get();

	bfqq->budget_timeout = jiffies +
		bfqd->bfq_timeout * timeout_coeff;
@@ -3396,7 +3396,7 @@ static void bfq_arm_slice_timer(struct bfq_data *bfqd)
	else if (bfqq->wr_coeff > 1)
		sl = max_t(u32, sl, 20ULL * NSEC_PER_MSEC);

	bfqd->last_idling_start = ktime_get();
	bfqd->last_idling_start = blk_time_get();
	bfqd->last_idling_start_jiffies = jiffies;

	hrtimer_start(&bfqd->idle_slice_timer, ns_to_ktime(sl),
@@ -3435,7 +3435,7 @@ static void bfq_reset_rate_computation(struct bfq_data *bfqd,
				       struct request *rq)
{
	if (rq != NULL) { /* new rq dispatch now, reset accordingly */
		bfqd->last_dispatch = bfqd->first_dispatch = ktime_get_ns();
		bfqd->last_dispatch = bfqd->first_dispatch = blk_time_get_ns();
		bfqd->peak_rate_samples = 1;
		bfqd->sequential_samples = 0;
		bfqd->tot_sectors_dispatched = bfqd->last_rq_max_size =
@@ -3592,7 +3592,7 @@ static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq)
 */
static void bfq_update_peak_rate(struct bfq_data *bfqd, struct request *rq)
{
	u64 now_ns = ktime_get_ns();
	u64 now_ns = blk_time_get_ns();

	if (bfqd->peak_rate_samples == 0) { /* first dispatch */
		bfq_log(bfqd, "update_peak_rate: goto reset, samples %d",
@@ -4164,7 +4164,7 @@ static bool bfq_bfqq_is_slow(struct bfq_data *bfqd, struct bfq_queue *bfqq,
	if (compensate)
		delta_ktime = bfqd->last_idling_start;
	else
		delta_ktime = ktime_get();
		delta_ktime = blk_time_get();
	delta_ktime = ktime_sub(delta_ktime, bfqd->last_budget_start);
	delta_usecs = ktime_to_us(delta_ktime);

@@ -5593,7 +5593,7 @@ static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
			  struct bfq_io_cq *bic, pid_t pid, int is_sync,
			  unsigned int act_idx)
{
	u64 now_ns = ktime_get_ns();
	u64 now_ns = blk_time_get_ns();

	bfqq->actuator_idx = act_idx;
	RB_CLEAR_NODE(&bfqq->entity.rb_node);
@@ -5903,7 +5903,7 @@ static void bfq_update_io_thinktime(struct bfq_data *bfqd,
	 */
	if (bfqq->dispatched || bfq_bfqq_busy(bfqq))
		return;
	elapsed = ktime_get_ns() - bfqq->ttime.last_end_request;
	elapsed = blk_time_get_ns() - bfqq->ttime.last_end_request;
	elapsed = min_t(u64, elapsed, 2ULL * bfqd->bfq_slice_idle);

	ttime->ttime_samples = (7*ttime->ttime_samples + 256) / 8;
@@ -6195,7 +6195,7 @@ static bool __bfq_insert_request(struct bfq_data *bfqd, struct request *rq)
	bfq_add_request(rq);
	idle_timer_disabled = waiting && !bfq_bfqq_wait_request(bfqq);

	rq->fifo_time = ktime_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)];
	rq->fifo_time = blk_time_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)];
	list_add_tail(&rq->queuelist, &bfqq->fifo);

	bfq_rq_enqueued(bfqd, bfqq, rq);
@@ -6371,7 +6371,7 @@ static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd)
		bfq_weights_tree_remove(bfqq);
	}

	now_ns = ktime_get_ns();
	now_ns = blk_time_get_ns();

	bfqq->ttime.last_end_request = now_ns;

@@ -6586,7 +6586,7 @@ static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd)
static void bfq_update_inject_limit(struct bfq_data *bfqd,
				    struct bfq_queue *bfqq)
{
	u64 tot_time_ns = ktime_get_ns() - bfqd->last_empty_occupied_ns;
	u64 tot_time_ns = blk_time_get_ns() - bfqd->last_empty_occupied_ns;
	unsigned int old_limit = bfqq->inject_limit;

	if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) {
+1 −1
Original line number Diff line number Diff line
@@ -1891,7 +1891,7 @@ static void blkcg_maybe_throttle_blkg(struct blkcg_gq *blkg, bool use_memdelay)
{
	unsigned long pflags = 0;
	bool clamp;
	u64 now = ktime_to_ns(ktime_get());
	u64 now = blk_time_get_ns();
	u64 exp;
	u64 delay_nsec = 0;
	int tok;
+1 −1
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ static void blk_account_io_flush(struct request *rq)
	part_stat_lock();
	part_stat_inc(part, ios[STAT_FLUSH]);
	part_stat_add(part, nsecs[STAT_FLUSH],
		      ktime_get_ns() - rq->start_time_ns);
		      blk_time_get_ns() - rq->start_time_ns);
	part_stat_unlock();
}

+2 −2
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ void bio_hierarchy_start_io_acct(struct bio *bio, enum stage_group stage)

	hstage = q->io_hierarchy_stats->hstage[stage];
	io_hierarchy_inc(hstage->hstats, dispatched, hierarchy_op(bio));
	bio->hierarchy_time = ktime_get_ns();
	bio->hierarchy_time = blk_time_get_ns();
}

void bio_hierarchy_end_io_acct(struct bio *bio, enum stage_group stage,
@@ -208,7 +208,7 @@ void bio_hierarchy_end_io_acct(struct bio *bio, enum stage_group stage,
void bio_list_hierarchy_end_io_acct(struct bio_list *list,
				    enum stage_group stage)
{
	u64 time = ktime_get_ns();
	u64 time = blk_time_get_ns();
	struct bio *bio;

	bio_list_for_each(bio, list)
Loading