OSDN Git Service

BACKPORT: block: use ktime_get_ns() instead of sched_clock() for cfq
authorOmar Sandoval <osandov@fb.com>
Wed, 9 May 2018 09:08:51 +0000 (02:08 -0700)
committer0ranko0P <ranko0p@outlook.com>
Wed, 4 Dec 2019 17:16:46 +0000 (01:16 +0800)
cfq and bfq have some internal fields that use sched_clock() which can
trivially use ktime_get_ns() instead. Their timestamp fields in struct
request can also use ktime_get_ns(), which resolves the 8 year old
comment added by commit 28f4197e5d47 ("block: disable preemption before
using sched_clock()").

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(cherry-picked from 84c7afcebed913c93d50f116b046b7f0d8ec0cdc)
[nc: only backport cfq changes]
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
block/cfq-iosched.c
include/linux/blkdev.h

index e52157f..c94f3f6 100644 (file)
@@ -207,9 +207,9 @@ struct cfqg_stats {
        /* total time with empty current active q with other requests queued */
        struct blkg_stat                empty_time;
        /* fields after this shouldn't be cleared on stat reset */
-       uint64_t                        start_group_wait_time;
-       uint64_t                        start_idle_time;
-       uint64_t                        start_empty_time;
+       u64                             start_group_wait_time;
+       u64                             start_idle_time;
+       u64                             start_empty_time;
        uint16_t                        flags;
 #endif /* CONFIG_DEBUG_BLK_CGROUP */
 #endif /* CONFIG_CFQ_GROUP_IOSCHED */
@@ -490,13 +490,13 @@ CFQG_FLAG_FNS(empty)
 /* This should be called with the queue_lock held. */
 static void cfqg_stats_update_group_wait_time(struct cfqg_stats *stats)
 {
-       unsigned long long now;
+       u64 now;
 
        if (!cfqg_stats_waiting(stats))
                return;
 
-       now = sched_clock();
-       if (time_after64(now, stats->start_group_wait_time))
+       now = ktime_get_ns();
+       if (now > stats->start_group_wait_time)
                blkg_stat_add(&stats->group_wait_time,
                              now - stats->start_group_wait_time);
        cfqg_stats_clear_waiting(stats);
@@ -512,20 +512,20 @@ static void cfqg_stats_set_start_group_wait_time(struct cfq_group *cfqg,
                return;
        if (cfqg == curr_cfqg)
                return;
-       stats->start_group_wait_time = sched_clock();
+       stats->start_group_wait_time = ktime_get_ns();
        cfqg_stats_mark_waiting(stats);
 }
 
 /* This should be called with the queue_lock held. */
 static void cfqg_stats_end_empty_time(struct cfqg_stats *stats)
 {
-       unsigned long long now;
+       u64 now;
 
        if (!cfqg_stats_empty(stats))
                return;
 
-       now = sched_clock();
-       if (time_after64(now, stats->start_empty_time))
+       now = ktime_get_ns();
+       if (now > stats->start_empty_time)
                blkg_stat_add(&stats->empty_time,
                              now - stats->start_empty_time);
        cfqg_stats_clear_empty(stats);
@@ -551,7 +551,7 @@ static void cfqg_stats_set_start_empty_time(struct cfq_group *cfqg)
        if (cfqg_stats_empty(stats))
                return;
 
-       stats->start_empty_time = sched_clock();
+       stats->start_empty_time = ktime_get_ns();
        cfqg_stats_mark_empty(stats);
 }
 
@@ -560,9 +560,9 @@ static void cfqg_stats_update_idle_time(struct cfq_group *cfqg)
        struct cfqg_stats *stats = &cfqg->stats;
 
        if (cfqg_stats_idling(stats)) {
-               unsigned long long now = sched_clock();
+               u64 now = ktime_get_ns();
 
-               if (time_after64(now, stats->start_idle_time))
+               if (now > stats->start_idle_time)
                        blkg_stat_add(&stats->idle_time,
                                      now - stats->start_idle_time);
                cfqg_stats_clear_idling(stats);
@@ -575,7 +575,7 @@ static void cfqg_stats_set_start_idle_time(struct cfq_group *cfqg)
 
        BUG_ON(cfqg_stats_idling(stats));
 
-       stats->start_idle_time = sched_clock();
+       stats->start_idle_time = ktime_get_ns();
        cfqg_stats_mark_idling(stats);
 }
 
@@ -700,16 +700,17 @@ static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg, int rw)
 }
 
 static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
-                       uint64_t start_time, uint64_t io_start_time, int rw)
+                       u64 start_time_ns, u64 io_start_time_ns, int rw)
 {
        struct cfqg_stats *stats = &cfqg->stats;
-       unsigned long long now = sched_clock();
+       u64 now = ktime_get_ns();
 
-       if (time_after64(now, io_start_time))
-               blkg_rwstat_add(&stats->service_time, rw, now - io_start_time);
-       if (time_after64(io_start_time, start_time))
+       if (now > io_start_time_ns)
+               blkg_rwstat_add(&stats->service_time, rw,
+                               now - io_start_time_ns);
+       if (io_start_time_ns > start_time_ns)
                blkg_rwstat_add(&stats->wait_time, rw,
-                               io_start_time - start_time);
+                               io_start_time_ns - start_time_ns);
 }
 
 /* @stats = 0 */
@@ -793,7 +794,7 @@ static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
 static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg, int rw) { }
 static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg, int rw) { }
 static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
-                       uint64_t start_time, uint64_t io_start_time, int rw) { }
+                       u64 start_time_ns, u64 io_start_time_ns, int rw) { }
 
 #endif /* CONFIG_CFQ_GROUP_IOSCHED */
 
index 77c3973..e2544d7 100644 (file)
@@ -1429,42 +1429,33 @@ int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long dela
 int kblockd_schedule_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
 
 #ifdef CONFIG_BLK_CGROUP
-/*
- * This should not be using sched_clock(). A real patch is in progress
- * to fix this up, until that is in place we need to disable preemption
- * around sched_clock() in this function and set_io_start_time_ns().
- */
 static inline void set_start_time_ns(struct request *req)
 {
-       preempt_disable();
-       req->start_time_ns = sched_clock();
-       preempt_enable();
+       req->start_time_ns = ktime_get_ns();
 }
 
 static inline void set_io_start_time_ns(struct request *req)
 {
-       preempt_disable();
-       req->io_start_time_ns = sched_clock();
-       preempt_enable();
+       req->io_start_time_ns = ktime_get_ns();
 }
 
-static inline uint64_t rq_start_time_ns(struct request *req)
+static inline u64 rq_start_time_ns(struct request *req)
 {
         return req->start_time_ns;
 }
 
-static inline uint64_t rq_io_start_time_ns(struct request *req)
+static inline u64 rq_io_start_time_ns(struct request *req)
 {
         return req->io_start_time_ns;
 }
 #else
 static inline void set_start_time_ns(struct request *req) {}
 static inline void set_io_start_time_ns(struct request *req) {}
-static inline uint64_t rq_start_time_ns(struct request *req)
+static inline u64 rq_start_time_ns(struct request *req)
 {
        return 0;
 }
-static inline uint64_t rq_io_start_time_ns(struct request *req)
+static inline u64 rq_io_start_time_ns(struct request *req)
 {
        return 0;
 }