Skip to content

Commit e45c47d

Browse files
snitmaxboe
authored andcommitted
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: Christoph Hellwig <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1082541 commit e45c47d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

block/blk-core.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,20 +1061,32 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
10611061
}
10621062

10631063
static unsigned long __part_start_io_acct(struct block_device *part,
1064-
unsigned int sectors, unsigned int op)
1064+
unsigned int sectors, unsigned int op,
1065+
unsigned long start_time)
10651066
{
10661067
const int sgrp = op_stat_group(op);
1067-
unsigned long now = READ_ONCE(jiffies);
10681068

10691069
part_stat_lock();
1070-
update_io_ticks(part, now, false);
1070+
update_io_ticks(part, start_time, false);
10711071
part_stat_inc(part, ios[sgrp]);
10721072
part_stat_add(part, sectors[sgrp], sectors);
10731073
part_stat_local_inc(part, in_flight[op_is_write(op)]);
10741074
part_stat_unlock();
10751075

1076-
return now;
1076+
return start_time;
1077+
}
1078+
1079+
/**
1080+
* bio_start_io_acct_time - start I/O accounting for bio based drivers
1081+
* @bio: bio to start account for
1082+
* @start_time: start time that should be passed back to bio_end_io_acct().
1083+
*/
1084+
void bio_start_io_acct_time(struct bio *bio, unsigned long start_time)
1085+
{
1086+
__part_start_io_acct(bio->bi_bdev, bio_sectors(bio),
1087+
bio_op(bio), start_time);
10771088
}
1089+
EXPORT_SYMBOL_GPL(bio_start_io_acct_time);
10781090

10791091
/**
10801092
* 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,
10841096
*/
10851097
unsigned long bio_start_io_acct(struct bio *bio)
10861098
{
1087-
return __part_start_io_acct(bio->bi_bdev, bio_sectors(bio), bio_op(bio));
1099+
return __part_start_io_acct(bio->bi_bdev, bio_sectors(bio),
1100+
bio_op(bio), jiffies);
10881101
}
10891102
EXPORT_SYMBOL_GPL(bio_start_io_acct);
10901103

10911104
unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
10921105
unsigned int op)
10931106
{
1094-
return __part_start_io_acct(disk->part0, sectors, op);
1107+
return __part_start_io_acct(disk->part0, sectors, op, jiffies);
10951108
}
10961109
EXPORT_SYMBOL(disk_start_io_acct);
10971110

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,7 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
12581258
void disk_end_io_acct(struct gendisk *disk, unsigned int op,
12591259
unsigned long start_time);
12601260

1261+
void bio_start_io_acct_time(struct bio *bio, unsigned long start_time);
12611262
unsigned long bio_start_io_acct(struct bio *bio);
12621263
void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
12631264
struct block_device *orig_bdev);

0 commit comments

Comments
 (0)