aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGu Zheng <guz.fnst@cn.fujitsu.com>2014-11-23 22:05:22 -0500
committerJens Axboe <axboe@fb.com>2014-11-24 10:04:44 -0500
commit394ffa503bc40e32d7f54a9b817264e81ce131b4 (patch)
tree551aa110ea3ef7519d7a5ea444ac9c9640de4234
parentb657d7e632e0bc40e5e231332be39d69b2f1a0bb (diff)
blk: introduce generic io stat accounting help function
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>
-rw-r--r--block/bio.c28
-rw-r--r--include/linux/bio.h5
2 files changed, 33 insertions, 0 deletions
diff --git a/block/bio.c b/block/bio.c
index 3e6e1986a5b2..3d4a072375ef 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1739,6 +1739,34 @@ void bio_check_pages_dirty(struct bio *bio)
1739 } 1739 }
1740} 1740}
1741 1741
1742void generic_start_io_acct(int rw, unsigned long sectors,
1743 struct hd_struct *part)
1744{
1745 int cpu = part_stat_lock();
1746
1747 part_round_stats(cpu, part);
1748 part_stat_inc(cpu, part, ios[rw]);
1749 part_stat_add(cpu, part, sectors[rw], sectors);
1750 part_inc_in_flight(part, rw);
1751
1752 part_stat_unlock();
1753}
1754EXPORT_SYMBOL(generic_start_io_acct);
1755
1756void generic_end_io_acct(int rw, struct hd_struct *part,
1757 unsigned long start_time)
1758{
1759 unsigned long duration = jiffies - start_time;
1760 int cpu = part_stat_lock();
1761
1762 part_stat_add(cpu, part, ticks[rw], duration);
1763 part_round_stats(cpu, part);
1764 part_dec_in_flight(part, rw);
1765
1766 part_stat_unlock();
1767}
1768EXPORT_SYMBOL(generic_end_io_acct);
1769
1742#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1770#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
1743void bio_flush_dcache_pages(struct bio *bi) 1771void bio_flush_dcache_pages(struct bio *bi)
1744{ 1772{
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7347f486ceca..efead0b532c4 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -443,6 +443,11 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
443extern void bio_set_pages_dirty(struct bio *bio); 443extern void bio_set_pages_dirty(struct bio *bio);
444extern void bio_check_pages_dirty(struct bio *bio); 444extern void bio_check_pages_dirty(struct bio *bio);
445 445
446void generic_start_io_acct(int rw, unsigned long sectors,
447 struct hd_struct *part);
448void generic_end_io_acct(int rw, struct hd_struct *part,
449 unsigned long start_time);
450
446#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 451#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
447# error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform" 452# error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
448#endif 453#endif