diff options
author | Gu Zheng <guz.fnst@cn.fujitsu.com> | 2014-11-24 04:05:22 +0100 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-11-24 16:04:44 +0100 |
commit | 394ffa503bc40e32d7f54a9b817264e81ce131b4 (patch) | |
tree | 551aa110ea3ef7519d7a5ea444ac9c9640de4234 /block/bio.c | |
parent | blk-mq: handle the single queue case in blk_mq_hctx_next_cpu (diff) | |
download | linux-394ffa503bc40e32d7f54a9b817264e81ce131b4.tar.xz linux-394ffa503bc40e32d7f54a9b817264e81ce131b4.zip |
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>
Diffstat (limited to 'block/bio.c')
-rw-r--r-- | block/bio.c | 28 |
1 files changed, 28 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) } } +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) { |