From fa23f5521d4fcd9dd838e8a65e336507beb1e703 Mon Sep 17 00:00:00 2001 From: Mikulas Patocka Date: Tue, 30 Jul 2019 14:52:09 +0800 Subject: [PATCH] block: switch to per-cpu in-flight counters mainline inclusion from mainline-5.0-rc1 commit 1226b8dd0e91331cfab500f305b2c264445a0392 category: bugfix bugzilla: 18695 CVE: NA --------------------------- Now when part_round_stats is gone, we can switch to per-cpu in-flight counters. We use the local-atomic type local_t, so that if part_inc_in_flight or part_dec_in_flight is reentrantly called from an interrupt, the value will be correct. The other counters could be corrupted due to reentrant interrupt, but the corruption only results in slight counter skew - the in_flight counter must be exact, so it needs local_t. Conflicts: include/linux/genhd.h Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Jens Axboe Signed-off-by: Zhihao Cheng Reviewed-by: Zhang Xiaoxu Signed-off-by: Yang Yingliang --- include/linux/genhd.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 325ef33d6481..be6fe1ea7bd5 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -308,6 +308,12 @@ extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, #define part_stat_lock() ({ rcu_read_lock(); get_cpu(); }) #define part_stat_unlock() do { put_cpu(); rcu_read_unlock(); } while (0) +#define part_stat_get_cpu(part, field, cpu) \ + (per_cpu_ptr((part)->dkstats, (cpu))->field) + +#define part_stat_get(part, field) \ + part_stat_get_cpu(part, field, smp_processor_id()) + #define __part_stat_add(cpu, part, field, addnd) \ (per_cpu_ptr((part)->dkstats, (cpu))->field += (addnd)) @@ -346,6 +352,8 @@ static inline void free_part_stats(struct hd_struct *part) #define part_stat_lock() ({ rcu_read_lock(); 0; }) #define part_stat_unlock() rcu_read_unlock() +#define part_stat_get(part, field) ((part)->dkstats.field) + #define __part_stat_add(cpu, part, field, addnd) \ ((part)->dkstats.field += addnd) -- GitLab