diff mbox series

[2/5] block: keep track of per-device io sizes in stats

Message ID 20190426002050.15499-3-Jes.Sorensen@gmail.com (mailing list archive)
State New, archived
Headers show
Series RFC blk-mq device stats | expand

Commit Message

Jes Sorensen April 26, 2019, 12:20 a.m. UTC
From: Josef Bacik <josef@toxicpanda.com>

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 <josef@toxicpanda.com>
---
 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 mbox series

Patch

diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
index 507212d75ee2..8e547958cc1b 100644
--- a/block/blk-iolatency.c
+++ b/block/blk-iolatency.c
@@ -218,7 +218,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 65f628652b1e..e8cd2028745a 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -677,9 +677,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 8a40ac719ba7..d718983bed5c 100644
--- a/block/blk-stat.c
+++ b/block/blk-stat.c
@@ -21,7 +21,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 */
@@ -37,13 +37,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++;
 }
 
@@ -69,7 +71,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 df24baf455c2..eb64361bc2a5 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -447,6 +447,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 317ab30d2904..a2291b1d1cb0 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