History

block: add disk/bio-based accounting helpers

Add two new helpers to simplify I/O accounting for bio based drivers. Currently these drivers use the generic_start_io_acct and generic_end_io_acct helpers which have very cumbersome calling conventions, don't actually return the time they started accounting, and try to deal with accounting for partitions, which can't happen for bio based drivers. The new helpers will be used to subsequently replace uses of the old helpers. The main API is the bio based wrappes in blkdev.h, but for zram which wants to account rw_page based I/O lower level routines are provided as well.

Christoph Hellwig committed 6 years ago

Commit 956d5101 parent c81b49d2 files · +62 −0Browse files

Unified · Split

2 files
  1. block/blk-core.c +34 −0
  2. include/linux/blkdev.h +28 −0
block/blk-core.c+34−0
@@ -1432,6 +1432,40 @@ void blk_account_io_start(struct request *rq, bool new_io) · 1431 unmodified lines
1432 part_stat_unlock();1432 part_stat_unlock();
1433}1433}
1434 1434
1435unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
1436 unsigned int op)
1437{
1438 struct hd_struct *part = &disk->part0;
1439 const int sgrp = op_stat_group(op);
1440 unsigned long now = READ_ONCE(jiffies);
1441
1442 part_stat_lock();
1443 update_io_ticks(part, now, false);
1444 part_stat_inc(part, ios[sgrp]);
1445 part_stat_add(part, sectors[sgrp], sectors);
1446 part_stat_local_inc(part, in_flight[op_is_write(op)]);
1447 part_stat_unlock();
1448
1449 return now;
1450}
1451EXPORT_SYMBOL(disk_start_io_acct);
1452
1453void disk_end_io_acct(struct gendisk *disk, unsigned int op,
1454 unsigned long start_time)
1455{
1456 struct hd_struct *part = &disk->part0;
1457 const int sgrp = op_stat_group(op);
1458 unsigned long now = READ_ONCE(jiffies);
1459 unsigned long duration = now - start_time;
1460
1461 part_stat_lock();
1462 update_io_ticks(part, now, true);
1463 part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration));
1464 part_stat_local_dec(part, in_flight[op_is_write(op)]);
1465 part_stat_unlock();
1466}
1467EXPORT_SYMBOL(disk_end_io_acct);
1468
1435/*1469/*
1436 * Steal bios from a request and add them to a bio list.1470 * Steal bios from a request and add them to a bio list.
1437 * The request must not have been partially completed before.1471 * The request must not have been partially completed before.
include/linux/blkdev.h+28−0
@@ -1892,4 +1892,32 @@ static inline void blk_wake_io_task(struct task_struct *waiter) · 1891 unmodified lines
1892 wake_up_process(waiter);1892 wake_up_process(waiter);
1893}1893}
1894 1894
1895unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
1896 unsigned int op);
1897void disk_end_io_acct(struct gendisk *disk, unsigned int op,
1898 unsigned long start_time);
1899
1900#ifdef CONFIG_BLOCK
1901/**
1902 * bio_start_io_acct - start I/O accounting for bio based drivers
1903 * @bio: bio to start account for
1904 *
1905 * Returns the start time that should be passed back to bio_end_io_acct().
1906 */
1907static inline unsigned long bio_start_io_acct(struct bio *bio)
1908{
1909 return disk_start_io_acct(bio->bi_disk, bio_sectors(bio), bio_op(bio));
1910}
1911
1912/**
1913 * bio_end_io_acct - end I/O accounting for bio based drivers
1914 * @bio: bio to end account for
1915 * @start: start time returned by bio_start_io_acct()
1916 */
1917static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
1918{
1919 return disk_end_io_acct(bio->bi_disk, bio_op(bio), start_time);
1920}
1921#endif /* CONFIG_BLOCK */
1922
1895#endif1923#endif