Indeed tool iostat's await is not good enough, which is somewhat sketchy and could not show request's latency on device driver's side. Here we add a new counter to track io request's d2c time, also with this patch, we can extend iostat to show this value easily. Signed-off-by: Xiaoguang Wang <xiaoguang.wang@xxxxxxxxxxxxxxxxx> --- block/blk-core.c | 3 +++ block/genhd.c | 7 +++++-- block/partition-generic.c | 8 ++++++-- include/linux/genhd.h | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index ee1b35fe8572..b0449ec80a7d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1257,6 +1257,9 @@ void blk_account_io_done(struct request *req, u64 now) update_io_ticks(part, jiffies); part_stat_inc(part, ios[sgrp]); part_stat_add(part, nsecs[sgrp], now - req->start_time_ns); + if (req->io_start_time_ns) + part_stat_add(part, d2c_nsecs[sgrp], + now - req->io_start_time_ns); part_stat_add(part, time_in_queue, nsecs_to_jiffies64(now - req->start_time_ns)); part_dec_in_flight(req->q, part, rq_data_dir(req)); diff --git a/block/genhd.c b/block/genhd.c index 24654e1d83e6..727bc1de1a74 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1377,7 +1377,7 @@ static int diskstats_show(struct seq_file *seqf, void *v) "%lu %lu %lu %u " "%lu %lu %lu %u " "%u %u %u " - "%lu %lu %lu %u\n", + "%lu %lu %lu %u %u %u %u\n", MAJOR(part_devt(hd)), MINOR(part_devt(hd)), disk_name(gp, hd->partno, buf), part_stat_read(hd, ios[STAT_READ]), @@ -1394,7 +1394,10 @@ static int diskstats_show(struct seq_file *seqf, void *v) part_stat_read(hd, ios[STAT_DISCARD]), part_stat_read(hd, merges[STAT_DISCARD]), part_stat_read(hd, sectors[STAT_DISCARD]), - (unsigned int)part_stat_read_msecs(hd, STAT_DISCARD) + (unsigned int)part_stat_read_msecs(hd, STAT_DISCARD), + (unsigned int)part_stat_read_d2c_msecs(hd, STAT_READ), + (unsigned int)part_stat_read_d2c_msecs(hd, STAT_WRITE), + (unsigned int)part_stat_read_d2c_msecs(hd, STAT_DISCARD) ); } disk_part_iter_exit(&piter); diff --git a/block/partition-generic.c b/block/partition-generic.c index aee643ce13d1..0635a46a31dd 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -127,7 +127,7 @@ ssize_t part_stat_show(struct device *dev, "%8lu %8lu %8llu %8u " "%8lu %8lu %8llu %8u " "%8u %8u %8u " - "%8lu %8lu %8llu %8u" + "%8lu %8lu %8llu %8u %8u %8u %8u %8u" "\n", part_stat_read(p, ios[STAT_READ]), part_stat_read(p, merges[STAT_READ]), @@ -143,7 +143,11 @@ ssize_t part_stat_show(struct device *dev, part_stat_read(p, ios[STAT_DISCARD]), part_stat_read(p, merges[STAT_DISCARD]), (unsigned long long)part_stat_read(p, sectors[STAT_DISCARD]), - (unsigned int)part_stat_read_msecs(p, STAT_DISCARD)); + (unsigned int)part_stat_read_msecs(p, STAT_DISCARD), + (unsigned int)part_stat_read_msecs(p, STAT_DISCARD), + (unsigned int)part_stat_read_d2c_msecs(p, STAT_READ), + (unsigned int)part_stat_read_d2c_msecs(p, STAT_WRITE), + (unsigned int)part_stat_read_d2c_msecs(p, STAT_DISCARD)); } ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr, diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 8b5330dd5ac0..f80ba947cac2 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -85,6 +85,7 @@ struct partition { struct disk_stats { u64 nsecs[NR_STAT_GROUPS]; + u64 d2c_nsecs[NR_STAT_GROUPS]; unsigned long sectors[NR_STAT_GROUPS]; unsigned long ios[NR_STAT_GROUPS]; unsigned long merges[NR_STAT_GROUPS]; @@ -367,6 +368,9 @@ static inline void free_part_stats(struct hd_struct *part) #define part_stat_read_msecs(part, which) \ div_u64(part_stat_read(part, nsecs[which]), NSEC_PER_MSEC) +#define part_stat_read_d2c_msecs(part, which) \ + div_u64(part_stat_read(part, d2c_nsecs[which]), NSEC_PER_MSEC) + #define part_stat_read_accum(part, field) \ (part_stat_read(part, field[STAT_READ]) + \ part_stat_read(part, field[STAT_WRITE]) + \ -- 2.17.2