blk: introduce generic io stat accounting help function
authorGu Zheng <guz.fnst@cn.fujitsu.com>
Mon, 24 Nov 2014 03:05:22 +0000 (11:05 +0800)
committerJens Axboe <axboe@fb.com>
Mon, 24 Nov 2014 15:04:44 +0000 (08:04 -0700)
Many block drivers accounting io stat based on bio (e.g. NVMe...),
the blk_account_io_start/end() which is based on request
does not make sense to them, so here we introduce the similar help
function named generic_start/end_io_acct base on raw sectors, and it can
simplify some driver's open io accounting code.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
block/bio.c
include/linux/bio.h

index 3e6e1986a5b2c0c217532b816dc911cd544e3e11..3d4a072375efdc8bbf5fd4e7fd17b0f57a97f00f 100644 (file)
@@ -1739,6 +1739,34 @@ void bio_check_pages_dirty(struct bio *bio)
        }
 }
 
+void generic_start_io_acct(int rw, unsigned long sectors,
+                          struct hd_struct *part)
+{
+       int cpu = part_stat_lock();
+
+       part_round_stats(cpu, part);
+       part_stat_inc(cpu, part, ios[rw]);
+       part_stat_add(cpu, part, sectors[rw], sectors);
+       part_inc_in_flight(part, rw);
+
+       part_stat_unlock();
+}
+EXPORT_SYMBOL(generic_start_io_acct);
+
+void generic_end_io_acct(int rw, struct hd_struct *part,
+                        unsigned long start_time)
+{
+       unsigned long duration = jiffies - start_time;
+       int cpu = part_stat_lock();
+
+       part_stat_add(cpu, part, ticks[rw], duration);
+       part_round_stats(cpu, part);
+       part_dec_in_flight(part, rw);
+
+       part_stat_unlock();
+}
+EXPORT_SYMBOL(generic_end_io_acct);
+
 #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
 void bio_flush_dcache_pages(struct bio *bi)
 {
index 7347f486ceca4ff9e64989c5ae5d6578524c0d8f..efead0b532c4723017da0339750285c38bee1ce6 100644 (file)
@@ -443,6 +443,11 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
 extern void bio_set_pages_dirty(struct bio *bio);
 extern void bio_check_pages_dirty(struct bio *bio);
 
+void generic_start_io_acct(int rw, unsigned long sectors,
+                          struct hd_struct *part);
+void generic_end_io_acct(int rw, struct hd_struct *part,
+                        unsigned long start_time);
+
 #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
 # error        "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
 #endif
This page took 0.02692 seconds and 5 git commands to generate.