Skip to content

Commit 394ffa5

Browse files
Gu Zhengaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b657d7e commit 394ffa5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

block/bio.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,34 @@ void bio_check_pages_dirty(struct bio *bio)
17391739
}
17401740
}
17411741

1742+
void 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+
}
1754+
EXPORT_SYMBOL(generic_start_io_acct);
1755+
1756+
void 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+
}
1768+
EXPORT_SYMBOL(generic_end_io_acct);
1769+
17421770
#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
17431771
void bio_flush_dcache_pages(struct bio *bi)
17441772
{

include/linux/bio.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
443443
extern void bio_set_pages_dirty(struct bio *bio);
444444
extern void bio_check_pages_dirty(struct bio *bio);
445445

446+
void generic_start_io_acct(int rw, unsigned long sectors,
447+
struct hd_struct *part);
448+
void generic_end_io_acct(int rw, struct hd_struct *part,
449+
unsigned long start_time);
450+
446451
#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
447452
# error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
448453
#endif

0 commit comments

Comments
 (0)