block: Add part_stat_read_accum to read across field entries.
authorMichael Callahan <michaelcallahan@fb.com>
Wed, 18 Jul 2018 11:47:37 +0000 (04:47 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 18 Jul 2018 14:44:16 +0000 (08:44 -0600)
Add a part_stat_read_accum macro to genhd.h to read and sum across
field entries.  For example to sum up the number read and write
sectors completed.  In addition to being ar reasonable cleanup by
itself this will make it easier to add new stat fields in the future.

tj: Refreshed on top of v4.17.

Signed-off-by: Michael Callahan <michaelcallahan@fb.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/drbd/drbd_receiver.c
drivers/block/drbd/drbd_worker.c
drivers/md/md.c
include/linux/genhd.h

index a36a30795c436096c0856b7ae37d478a9aa28f7d..75f6b47169e65ac8141ec507a974fb3622d1b562 100644 (file)
@@ -2674,8 +2674,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
        if (c_min_rate == 0)
                return false;
 
-       curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
-                     (int)part_stat_read(&disk->part0, sectors[1]) -
+       curr_events = (int)part_stat_read_accum(&disk->part0, sectors) -
                        atomic_read(&device->rs_sect_ev);
 
        if (atomic_read(&device->ap_actlog_cnt)
index 5e793dd7adfbd096239f4d0994d2f20e24b2b596..b8f77e83d456292abac70d8f89360a3697e8e700 100644 (file)
@@ -1690,9 +1690,7 @@ void drbd_rs_controller_reset(struct drbd_device *device)
        atomic_set(&device->rs_sect_in, 0);
        atomic_set(&device->rs_sect_ev, 0);
        device->rs_in_flight = 0;
-       device->rs_last_events =
-               (int)part_stat_read(&disk->part0, sectors[0]) +
-               (int)part_stat_read(&disk->part0, sectors[1]);
+       device->rs_last_events = (int)part_stat_read_accum(&disk->part0, sectors);
 
        /* Updating the RCU protected object in place is necessary since
           this function gets called from atomic context.
index 994aed2f9dfff4135170102265523045e893ac0a..dabe36723d6019bec2513337ce6970bcec8692bc 100644 (file)
@@ -8046,8 +8046,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
        rcu_read_lock();
        rdev_for_each_rcu(rdev, mddev) {
                struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
-               curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
-                             (int)part_stat_read(&disk->part0, sectors[1]) -
+               curr_events = (int)part_stat_read_accum(&disk->part0, sectors) -
                              atomic_read(&disk->sync_io);
                /* sync IO will cause sync_io to increase before the disk_stats
                 * as sync_io is counted when a request starts, and
index 6cb8a57896682af6dd29ac67b283d147f79e71a5..19f36fa1099509042fcfbed8508c611b5ad04c63 100644 (file)
@@ -353,6 +353,10 @@ static inline void free_part_stats(struct hd_struct *part)
 
 #endif /* CONFIG_SMP */
 
+#define part_stat_read_accum(part, field)                              \
+       (part_stat_read(part, field[0]) +                               \
+        part_stat_read(part, field[1]))
+
 #define part_stat_add(cpu, part, field, addnd) do {                    \
        __part_stat_add((cpu), (part), field, addnd);                   \
        if ((part)->partno)                                             \