Commit e45c47d1 authored by Mike Snitzer's avatar Mike Snitzer Committed by Jens Axboe

block: add bio_start_io_acct_time() to control start_time

bio_start_io_acct_time() interface is like bio_start_io_acct() that
allows start_time to be passed in. This gives drivers the ability to
defer starting accounting until after IO is issued (but possibily not
entirely due to bio splitting).
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Link: https://lore.kernel.org/r/20220128155841.39644-2-snitzer@redhat.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 10825410
...@@ -1061,20 +1061,32 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end) ...@@ -1061,20 +1061,32 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
} }
static unsigned long __part_start_io_acct(struct block_device *part, static unsigned long __part_start_io_acct(struct block_device *part,
unsigned int sectors, unsigned int op) unsigned int sectors, unsigned int op,
unsigned long start_time)
{ {
const int sgrp = op_stat_group(op); const int sgrp = op_stat_group(op);
unsigned long now = READ_ONCE(jiffies);
part_stat_lock(); part_stat_lock();
update_io_ticks(part, now, false); update_io_ticks(part, start_time, false);
part_stat_inc(part, ios[sgrp]); part_stat_inc(part, ios[sgrp]);
part_stat_add(part, sectors[sgrp], sectors); part_stat_add(part, sectors[sgrp], sectors);
part_stat_local_inc(part, in_flight[op_is_write(op)]); part_stat_local_inc(part, in_flight[op_is_write(op)]);
part_stat_unlock(); part_stat_unlock();
return now; return start_time;
}
/**
* bio_start_io_acct_time - start I/O accounting for bio based drivers
* @bio: bio to start account for
* @start_time: start time that should be passed back to bio_end_io_acct().
*/
void bio_start_io_acct_time(struct bio *bio, unsigned long start_time)
{
__part_start_io_acct(bio->bi_bdev, bio_sectors(bio),
bio_op(bio), start_time);
} }
EXPORT_SYMBOL_GPL(bio_start_io_acct_time);
/** /**
* bio_start_io_acct - start I/O accounting for bio based drivers * bio_start_io_acct - start I/O accounting for bio based drivers
...@@ -1084,14 +1096,15 @@ static unsigned long __part_start_io_acct(struct block_device *part, ...@@ -1084,14 +1096,15 @@ static unsigned long __part_start_io_acct(struct block_device *part,
*/ */
unsigned long bio_start_io_acct(struct bio *bio) unsigned long bio_start_io_acct(struct bio *bio)
{ {
return __part_start_io_acct(bio->bi_bdev, bio_sectors(bio), bio_op(bio)); return __part_start_io_acct(bio->bi_bdev, bio_sectors(bio),
bio_op(bio), jiffies);
} }
EXPORT_SYMBOL_GPL(bio_start_io_acct); EXPORT_SYMBOL_GPL(bio_start_io_acct);
unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
unsigned int op) unsigned int op)
{ {
return __part_start_io_acct(disk->part0, sectors, op); return __part_start_io_acct(disk->part0, sectors, op, jiffies);
} }
EXPORT_SYMBOL(disk_start_io_acct); EXPORT_SYMBOL(disk_start_io_acct);
......
...@@ -1258,6 +1258,7 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, ...@@ -1258,6 +1258,7 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
void disk_end_io_acct(struct gendisk *disk, unsigned int op, void disk_end_io_acct(struct gendisk *disk, unsigned int op,
unsigned long start_time); unsigned long start_time);
void bio_start_io_acct_time(struct bio *bio, unsigned long start_time);
unsigned long bio_start_io_acct(struct bio *bio); unsigned long bio_start_io_acct(struct bio *bio);
void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time, void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
struct block_device *orig_bdev); struct block_device *orig_bdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment