From d02cca18e0d6363b3547b7bfd9c95e8d20db9b11 Mon Sep 17 00:00:00 2001 From: Hongnan Li Date: Mon, 6 Jul 2020 13:28:49 +0800 Subject: [PATCH] blk-iolatency: only call ktime_get() if needed to #29139300 commit 6e2fa4dd683a22a7697e7ff51dad499406094d28 upstream ktime_to_ns(ktime_get()), which is expensive, does not need to be called if blk_iolatency_enabled() return false in blkcg_iolatency_done_bio(). Postponing ktime_to_ns(ktime_get()) execution reduces the CPU usage when blk_iolatency is disabled. Signed-off-by: Hongnan Li Signed-off-by: Jens Axboe Acked-by: Xiaoguang Wang Signed-off-by: Joseph Qi --- block/blk-iolatency.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c index 2102744d3963..2d89cd856028 100644 --- a/block/blk-iolatency.c +++ b/block/blk-iolatency.c @@ -559,7 +559,7 @@ static void blkcg_iolatency_done_bio(struct rq_qos *rqos, struct bio *bio) struct rq_wait *rqw; struct iolatency_grp *iolat; u64 window_start; - u64 now = ktime_to_ns(ktime_get()); + u64 now; bool issue_as_root = bio_issue_as_root_blkg(bio); bool enabled = false; int inflight = 0; @@ -576,6 +576,7 @@ static void blkcg_iolatency_done_bio(struct rq_qos *rqos, struct bio *bio) if (!enabled) return; + now = ktime_to_ns(ktime_get()); while (blkg && blkg->parent) { iolat = blkg_to_lat(blkg); if (!iolat) { -- GitLab