Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
block: Data type conversion for IO accounting
Change the data type of start and end time IO accounting variables in,
block layer, from "unsigned long" to "u64". This is to enable nano-seconds
granularity, in next commit, for the devices whose latency is less than
milliseconds.

Changes from V2 to V3
=====================
1. Changed all the required variables data-type to u64 as part of this
   first patch
2. Create a new setting '2' for iostats in sysfs in next patch
3. Change the code to get the ktime values when iostat=2 in next patch

Signed-off-by: Gulam Mohamed <gulam.mohamed@oracle.com>
  • Loading branch information
gulams authored and intel-lab-lkp committed Dec 21, 2022
1 parent 0d6cb91 commit 254be08
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 37 deletions.
24 changes: 12 additions & 12 deletions block/blk-core.c
Expand Up @@ -927,13 +927,13 @@ int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob,
}
EXPORT_SYMBOL_GPL(iocb_bio_iopoll);

void update_io_ticks(struct block_device *part, unsigned long now, bool end)
void update_io_ticks(struct block_device *part, u64 now, bool end)
{
unsigned long stamp;
u64 stamp;
again:
stamp = READ_ONCE(part->bd_stamp);
if (unlikely(time_after(now, stamp))) {
if (likely(try_cmpxchg(&part->bd_stamp, &stamp, now)))
if (unlikely(time_after64(now, stamp))) {
if (likely(try_cmpxchg64(&part->bd_stamp, &stamp, now)))
__part_stat_add(part, io_ticks, end ? now - stamp : 1);
}
if (part->bd_partno) {
Expand All @@ -942,9 +942,9 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
}
}

unsigned long bdev_start_io_acct(struct block_device *bdev,
unsigned int sectors, enum req_op op,
unsigned long start_time)
u64 bdev_start_io_acct(struct block_device *bdev,
unsigned int sectors, enum req_op op,
u64 start_time)
{
const int sgrp = op_stat_group(op);

Expand All @@ -965,19 +965,19 @@ EXPORT_SYMBOL(bdev_start_io_acct);
*
* Returns the start time that should be passed back to bio_end_io_acct().
*/
unsigned long bio_start_io_acct(struct bio *bio)
u64 bio_start_io_acct(struct bio *bio)
{
return bdev_start_io_acct(bio->bi_bdev, bio_sectors(bio),
bio_op(bio), jiffies);
}
EXPORT_SYMBOL_GPL(bio_start_io_acct);

void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
unsigned long start_time)
u64 start_time)
{
const int sgrp = op_stat_group(op);
unsigned long now = READ_ONCE(jiffies);
unsigned long duration = now - start_time;
u64 now = READ_ONCE(jiffies);
u64 duration = (unsigned long)now -(unsigned long) start_time;

part_stat_lock();
update_io_ticks(bdev, now, true);
Expand All @@ -987,7 +987,7 @@ void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
}
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, u64 start_time,
struct block_device *orig_bdev)
{
bdev_end_io_acct(orig_bdev, bio_op(bio), start_time);
Expand Down
2 changes: 1 addition & 1 deletion block/blk.h
Expand Up @@ -342,7 +342,7 @@ static inline bool blk_do_io_stat(struct request *rq)
return (rq->rq_flags & RQF_IO_STAT) && !blk_rq_is_passthrough(rq);
}

void update_io_ticks(struct block_device *part, unsigned long now, bool end);
void update_io_ticks(struct block_device *part, u64 now, bool end);

static inline void req_set_nomerge(struct request_queue *q, struct request *req)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_int.h
Expand Up @@ -236,7 +236,7 @@ struct drbd_request {
struct list_head req_pending_local;

/* for generic IO accounting */
unsigned long start_jif;
u64 start_jif;

/* for DRBD internal statistics */

Expand Down
4 changes: 2 additions & 2 deletions drivers/block/zram/zram_drv.c
Expand Up @@ -2007,7 +2007,7 @@ static void __zram_make_request(struct zram *zram, struct bio *bio)
u32 index;
struct bio_vec bvec;
struct bvec_iter iter;
unsigned long start_time;
u64 start_time;

index = bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;
offset = (bio->bi_iter.bi_sector &
Expand Down Expand Up @@ -2088,7 +2088,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
u32 index;
struct zram *zram;
struct bio_vec bv;
unsigned long start_time;
u64 start_time;

if (PageTransHuge(page))
return -ENOTSUPP;
Expand Down
10 changes: 5 additions & 5 deletions drivers/md/bcache/request.c
Expand Up @@ -476,7 +476,7 @@ struct search {
unsigned int cache_missed:1;

struct block_device *orig_bdev;
unsigned long start_time;
u64 start_time;

struct btree_op op;
struct data_insert_op iop;
Expand Down Expand Up @@ -714,7 +714,7 @@ static void search_free(struct closure *cl)

static inline struct search *search_alloc(struct bio *bio,
struct bcache_device *d, struct block_device *orig_bdev,
unsigned long start_time)
u64 start_time)
{
struct search *s;

Expand Down Expand Up @@ -1065,7 +1065,7 @@ static void cached_dev_nodata(struct closure *cl)

struct detached_dev_io_private {
struct bcache_device *d;
unsigned long start_time;
u64 start_time;
bio_end_io_t *bi_end_io;
void *bi_private;
struct block_device *orig_bdev;
Expand Down Expand Up @@ -1094,7 +1094,7 @@ static void detached_dev_end_io(struct bio *bio)
}

static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
struct block_device *orig_bdev, unsigned long start_time)
struct block_device *orig_bdev, u64 start_time)
{
struct detached_dev_io_private *ddip;
struct cached_dev *dc = container_of(d, struct cached_dev, disk);
Expand Down Expand Up @@ -1173,7 +1173,7 @@ void cached_dev_submit_bio(struct bio *bio)
struct block_device *orig_bdev = bio->bi_bdev;
struct bcache_device *d = orig_bdev->bd_disk->private_data;
struct cached_dev *dc = container_of(d, struct cached_dev, disk);
unsigned long start_time;
u64 start_time;
int rw = bio_data_dir(bio);

if (unlikely((d->c && test_bit(CACHE_SET_IO_DISABLE, &d->c->flags)) ||
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/dm-core.h
Expand Up @@ -284,7 +284,7 @@ struct dm_io {
unsigned short magic;
blk_short_t flags;
spinlock_t lock;
unsigned long start_time;
u64 start_time;
void *data;
struct dm_io *next;
struct dm_stats_aux stats_aux;
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/dm.c
Expand Up @@ -494,7 +494,7 @@ static bool bio_is_flush_with_data(struct bio *bio)
static void dm_io_acct(struct dm_io *io, bool end)
{
struct dm_stats_aux *stats_aux = &io->stats_aux;
unsigned long start_time = io->start_time;
u64 start_time = io->start_time;
struct mapped_device *md = io->md;
struct bio *bio = io->orig_bio;
unsigned int sectors;
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/md.h
Expand Up @@ -711,7 +711,7 @@ struct md_thread {

struct md_io_acct {
struct bio *orig_bio;
unsigned long start_time;
u64 start_time;
struct bio bio_clone;
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/md/raid1.h
Expand Up @@ -157,7 +157,7 @@ struct r1bio {
sector_t sector;
int sectors;
unsigned long state;
unsigned long start_time;
u64 start_time;
struct mddev *mddev;
/*
* original bio going to /dev/mdx
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/raid10.h
Expand Up @@ -123,7 +123,7 @@ struct r10bio {
sector_t sector; /* virtual sector number */
int sectors;
unsigned long state;
unsigned long start_time;
u64 start_time;
struct mddev *mddev;
/*
* original bio going to /dev/mdx
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/raid5.c
Expand Up @@ -5474,7 +5474,7 @@ static void raid5_align_endio(struct bio *bi)
struct r5conf *conf;
struct md_rdev *rdev;
blk_status_t error = bi->bi_status;
unsigned long start_time = md_io_acct->start_time;
u64 start_time = md_io_acct->start_time;

bio_put(bi);

Expand Down
2 changes: 1 addition & 1 deletion drivers/nvdimm/btt.c
Expand Up @@ -1442,7 +1442,7 @@ static void btt_submit_bio(struct bio *bio)
struct bio_integrity_payload *bip = bio_integrity(bio);
struct btt *btt = bio->bi_bdev->bd_disk->private_data;
struct bvec_iter iter;
unsigned long start;
u64 start;
struct bio_vec bvec;
int err = 0;
bool do_acct;
Expand Down
2 changes: 1 addition & 1 deletion drivers/nvdimm/pmem.c
Expand Up @@ -202,7 +202,7 @@ static void pmem_submit_bio(struct bio *bio)
int ret = 0;
blk_status_t rc = 0;
bool do_acct;
unsigned long start;
u64 start;
struct bio_vec bvec;
struct bvec_iter iter;
struct pmem_device *pmem = bio->bi_bdev->bd_disk->private_data;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/blk_types.h
Expand Up @@ -41,7 +41,7 @@ struct block_device {
sector_t bd_start_sect;
sector_t bd_nr_sectors;
struct disk_stats __percpu *bd_stats;
unsigned long bd_stamp;
u64 bd_stamp;
bool bd_read_only; /* read-only policy */
dev_t bd_dev;
atomic_t bd_openers;
Expand Down
12 changes: 6 additions & 6 deletions include/linux/blkdev.h
Expand Up @@ -1433,22 +1433,22 @@ static inline void blk_wake_io_task(struct task_struct *waiter)
wake_up_process(waiter);
}

unsigned long bdev_start_io_acct(struct block_device *bdev,
u64 bdev_start_io_acct(struct block_device *bdev,
unsigned int sectors, enum req_op op,
unsigned long start_time);
u64 start_time);
void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
unsigned long start_time);
u64 start_time);

unsigned long bio_start_io_acct(struct bio *bio);
void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
u64 bio_start_io_acct(struct bio *bio);
void bio_end_io_acct_remapped(struct bio *bio, u64 start_time,
struct block_device *orig_bdev);

/**
* bio_end_io_acct - end I/O accounting for bio based drivers
* @bio: bio to end account for
* @start_time: start time returned by bio_start_io_acct()
*/
static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
static inline void bio_end_io_acct(struct bio *bio, u64 start_time)
{
return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev);
}
Expand Down
2 changes: 1 addition & 1 deletion include/linux/part_stat.h
Expand Up @@ -10,7 +10,7 @@ struct disk_stats {
unsigned long sectors[NR_STAT_GROUPS];
unsigned long ios[NR_STAT_GROUPS];
unsigned long merges[NR_STAT_GROUPS];
unsigned long io_ticks;
u64 io_ticks;
local_t in_flight[2];
};

Expand Down

0 comments on commit 254be08

Please sign in to comment.