From: Josef Bacik <[email protected]>

In order to track things like bw we need to know the number of bytes
done per device.  Add a io_bytes field to the struct request and
populate this at start time.  Add a field to the blk_rq_stat to hold
this information so that consumers of the blk_rq_stat stuff can use it.

Signed-off-by: Josef Bacik <[email protected]>
---
 block/blk-iolatency.c     |  2 +-
 block/blk-mq.c            |  4 +---
 block/blk-stat.c          | 14 ++++++++------
 block/blk-stat.h          |  2 +-
 block/blk-throttle.c      |  3 ++-
 include/linux/blk_types.h |  1 +
 include/linux/blkdev.h    |  5 ++---
 7 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
index d22e61bced86..51cb82c07912 100644
--- a/block/blk-iolatency.c
+++ b/block/blk-iolatency.c
@@ -219,7 +219,7 @@ static inline void latency_stat_record_time(struct 
iolatency_grp *iolat,
                        stat->ps.missed++;
                stat->ps.total++;
        } else
-               blk_rq_stat_add(&stat->rqs, req_time);
+               blk_rq_stat_add(&stat->rqs, req_time, 0);
        put_cpu_ptr(stat);
 }
 
diff --git a/block/blk-mq.c b/block/blk-mq.c
index ce0f5f4ede70..8a59bc0410a6 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -679,9 +679,7 @@ void blk_mq_start_request(struct request *rq)
 
        if (test_bit(QUEUE_FLAG_STATS, &q->queue_flags)) {
                rq->io_start_time_ns = ktime_get_ns();
-#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
-               rq->throtl_size = blk_rq_sectors(rq);
-#endif
+               rq->io_bytes = blk_rq_bytes(rq);
                rq->rq_flags |= RQF_STATS;
                rq_qos_issue(q, rq);
        }
diff --git a/block/blk-stat.c b/block/blk-stat.c
index 1529f22044bd..0c6942f8b141 100644
--- a/block/blk-stat.c
+++ b/block/blk-stat.c
@@ -22,7 +22,7 @@ void blk_rq_stat_init(struct blk_rq_stat *stat)
 {
        stat->min = -1ULL;
        stat->max = stat->nr_samples = stat->mean = 0;
-       stat->time = 0;
+       stat->size = stat->time = 0;
 }
 
 /* src is a per-cpu stat, mean isn't initialized */
@@ -38,13 +38,15 @@ void blk_rq_stat_sum(struct blk_rq_stat *dst, struct 
blk_rq_stat *src)
                                dst->nr_samples + src->nr_samples);
 
        dst->nr_samples += src->nr_samples;
+       dst->size += src->size;
 }
 
-void blk_rq_stat_add(struct blk_rq_stat *stat, u64 value)
+void blk_rq_stat_add(struct blk_rq_stat *stat, u64 time, u64 size)
 {
-       stat->min = min(stat->min, value);
-       stat->max = max(stat->max, value);
-       stat->time += value;
+       stat->min = min(stat->min, time);
+       stat->max = max(stat->max, time);
+       stat->time += time;
+       stat->size += size;
        stat->nr_samples++;
 }
 
@@ -70,7 +72,7 @@ void blk_stat_add(struct request *rq, u64 now)
                        continue;
 
                stat = &get_cpu_ptr(cb->cpu_stat)[bucket];
-               blk_rq_stat_add(stat, value);
+               blk_rq_stat_add(stat, value, rq->io_bytes);
                put_cpu_ptr(cb->cpu_stat);
        }
        rcu_read_unlock();
diff --git a/block/blk-stat.h b/block/blk-stat.h
index 17b47a86eefb..ea893c4a9af1 100644
--- a/block/blk-stat.h
+++ b/block/blk-stat.h
@@ -164,7 +164,7 @@ static inline void blk_stat_activate_msecs(struct 
blk_stat_callback *cb,
        mod_timer(&cb->timer, jiffies + msecs_to_jiffies(msecs));
 }
 
-void blk_rq_stat_add(struct blk_rq_stat *, u64);
+void blk_rq_stat_add(struct blk_rq_stat *, u64, u64);
 void blk_rq_stat_sum(struct blk_rq_stat *, struct blk_rq_stat *);
 void blk_rq_stat_init(struct blk_rq_stat *);
 
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 1b97a73d2fb1..b07e5feda553 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -2248,8 +2248,9 @@ void blk_throtl_stat_add(struct request *rq, u64 time_ns)
 {
        struct request_queue *q = rq->q;
        struct throtl_data *td = q->td;
+       sector_t size = rq->io_bytes >> SECTOR_SHIFT;
 
-       throtl_track_latency(td, rq->throtl_size, req_op(rq), time_ns >> 10);
+       throtl_track_latency(td, size, req_op(rq), time_ns >> 10);
 }
 
 void blk_throtl_bio_endio(struct bio *bio)
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 6406430c517a..b85b27eb52b4 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -443,6 +443,7 @@ struct blk_rq_stat {
        u64 max;
        u32 nr_samples;
        u64 time;
+       u64 size;
 };
 
 #endif /* __LINUX_BLK_TYPES_H */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 592669bcc536..2716f239b56d 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -198,13 +198,12 @@ struct request {
        u64 start_time_ns;
        /* Time that I/O was submitted to the device. */
        u64 io_start_time_ns;
+       /* Bytes submitted to the device. */
+       unsigned int io_bytes;
 
 #ifdef CONFIG_BLK_WBT
        unsigned short wbt_flags;
 #endif
-#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
-       unsigned short throtl_size;
-#endif
 
        /*
         * Number of scatter-gather DMA addr+len pairs after
-- 
2.17.1

Reply via email to