Commit 5f0614a5 authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

block: change exported IO accounting interface from gendisk to bdev

Export IO accounting interfaces in terms of block_device now that
gendisk has become more internal to block core.

Rename __part_{start,end}_io_acct's first argument from part to bdev.
Rename __part_{start,end}_io_acct to bdev_{start,end}_io_acct and
export them.  Remove disk_{start,end}_io_acct and update caller (zram)
to use bdev_{start,end}_io_acct.

DM can now be updated to use bdev_{start,end}_io_acct.
Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
Link: https://lore.kernel.org/r/20220418022733.56168-2-snitzer@kernel.orgSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent c22198e7
...@@ -1022,21 +1022,22 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end) ...@@ -1022,21 +1022,22 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
} }
} }
static unsigned long __part_start_io_acct(struct block_device *part, unsigned long bdev_start_io_acct(struct block_device *bdev,
unsigned int sectors, unsigned int op, unsigned int sectors, unsigned int op,
unsigned long start_time) unsigned long start_time)
{ {
const int sgrp = op_stat_group(op); const int sgrp = op_stat_group(op);
part_stat_lock(); part_stat_lock();
update_io_ticks(part, start_time, false); update_io_ticks(bdev, start_time, false);
part_stat_inc(part, ios[sgrp]); part_stat_inc(bdev, ios[sgrp]);
part_stat_add(part, sectors[sgrp], sectors); part_stat_add(bdev, sectors[sgrp], sectors);
part_stat_local_inc(part, in_flight[op_is_write(op)]); part_stat_local_inc(bdev, in_flight[op_is_write(op)]);
part_stat_unlock(); part_stat_unlock();
return start_time; return start_time;
} }
EXPORT_SYMBOL(bdev_start_io_acct);
/** /**
* bio_start_io_acct_time - start I/O accounting for bio based drivers * bio_start_io_acct_time - start I/O accounting for bio based drivers
...@@ -1045,8 +1046,8 @@ static unsigned long __part_start_io_acct(struct block_device *part, ...@@ -1045,8 +1046,8 @@ static unsigned long __part_start_io_acct(struct block_device *part,
*/ */
void bio_start_io_acct_time(struct bio *bio, unsigned long start_time) void bio_start_io_acct_time(struct bio *bio, unsigned long start_time)
{ {
__part_start_io_acct(bio->bi_bdev, bio_sectors(bio), bdev_start_io_acct(bio->bi_bdev, bio_sectors(bio),
bio_op(bio), start_time); bio_op(bio), start_time);
} }
EXPORT_SYMBOL_GPL(bio_start_io_acct_time); EXPORT_SYMBOL_GPL(bio_start_io_acct_time);
...@@ -1058,46 +1059,33 @@ EXPORT_SYMBOL_GPL(bio_start_io_acct_time); ...@@ -1058,46 +1059,33 @@ EXPORT_SYMBOL_GPL(bio_start_io_acct_time);
*/ */
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), return bdev_start_io_acct(bio->bi_bdev, bio_sectors(bio),
bio_op(bio), jiffies); 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, void bdev_end_io_acct(struct block_device *bdev, unsigned int op,
unsigned int op) unsigned long start_time)
{
return __part_start_io_acct(disk->part0, sectors, op, jiffies);
}
EXPORT_SYMBOL(disk_start_io_acct);
static void __part_end_io_acct(struct block_device *part, 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); unsigned long now = READ_ONCE(jiffies);
unsigned long duration = now - start_time; unsigned long duration = now - start_time;
part_stat_lock(); part_stat_lock();
update_io_ticks(part, now, true); update_io_ticks(bdev, now, true);
part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration)); part_stat_add(bdev, nsecs[sgrp], jiffies_to_nsecs(duration));
part_stat_local_dec(part, in_flight[op_is_write(op)]); part_stat_local_dec(bdev, in_flight[op_is_write(op)]);
part_stat_unlock(); part_stat_unlock();
} }
EXPORT_SYMBOL(bdev_end_io_acct);
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)
{ {
__part_end_io_acct(orig_bdev, bio_op(bio), start_time); bdev_end_io_acct(orig_bdev, bio_op(bio), start_time);
} }
EXPORT_SYMBOL_GPL(bio_end_io_acct_remapped); EXPORT_SYMBOL_GPL(bio_end_io_acct_remapped);
void disk_end_io_acct(struct gendisk *disk, unsigned int op,
unsigned long start_time)
{
__part_end_io_acct(disk->part0, op, start_time);
}
EXPORT_SYMBOL(disk_end_io_acct);
/** /**
* blk_lld_busy - Check if underlying low-level drivers of a device are busy * blk_lld_busy - Check if underlying low-level drivers of a device are busy
* @q : the queue of the device being checked * @q : the queue of the device being checked
......
...@@ -1675,9 +1675,10 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector, ...@@ -1675,9 +1675,10 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
bv.bv_len = PAGE_SIZE; bv.bv_len = PAGE_SIZE;
bv.bv_offset = 0; bv.bv_offset = 0;
start_time = disk_start_io_acct(bdev->bd_disk, SECTORS_PER_PAGE, op); start_time = bdev_start_io_acct(bdev->bd_disk->part0,
SECTORS_PER_PAGE, op, jiffies);
ret = zram_bvec_rw(zram, &bv, index, offset, op, NULL); ret = zram_bvec_rw(zram, &bv, index, offset, op, NULL);
disk_end_io_acct(bdev->bd_disk, op, start_time); bdev_end_io_acct(bdev->bd_disk->part0, op, start_time);
out: out:
/* /*
* If I/O fails, just return error(ie, non-zero) without * If I/O fails, just return error(ie, non-zero) without
......
...@@ -1463,9 +1463,10 @@ static inline void blk_wake_io_task(struct task_struct *waiter) ...@@ -1463,9 +1463,10 @@ static inline void blk_wake_io_task(struct task_struct *waiter)
wake_up_process(waiter); wake_up_process(waiter);
} }
unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, unsigned long bdev_start_io_acct(struct block_device *bdev,
unsigned int op); unsigned int sectors, unsigned int op,
void disk_end_io_acct(struct gendisk *disk, unsigned int op, unsigned long start_time);
void bdev_end_io_acct(struct block_device *bdev, unsigned int op,
unsigned long start_time); unsigned long start_time);
void bio_start_io_acct_time(struct bio *bio, unsigned long start_time); void bio_start_io_acct_time(struct bio *bio, unsigned long start_time);
......
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