1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_PART_STAT_H
3 #define _LINUX_PART_STAT_H
5 #include <linux/genhd.h>
8 u64 nsecs[NR_STAT_GROUPS];
9 unsigned long sectors[NR_STAT_GROUPS];
10 unsigned long ios[NR_STAT_GROUPS];
11 unsigned long merges[NR_STAT_GROUPS];
12 unsigned long io_ticks;
17 * Macros to operate on percpu disk statistics:
19 * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters and should
20 * be called between disk_stat_lock() and disk_stat_unlock().
22 * part_stat_read() can be called at any time.
24 #define part_stat_lock() preempt_disable()
25 #define part_stat_unlock() preempt_enable()
27 #define part_stat_get_cpu(part, field, cpu) \
28 (per_cpu_ptr((part)->bd_stats, (cpu))->field)
30 #define part_stat_get(part, field) \
31 part_stat_get_cpu(part, field, smp_processor_id())
33 #define part_stat_read(part, field) \
35 typeof((part)->bd_stats->field) res = 0; \
37 for_each_possible_cpu(_cpu) \
38 res += per_cpu_ptr((part)->bd_stats, _cpu)->field; \
42 static inline void part_stat_set_all(struct block_device *part, int value)
46 for_each_possible_cpu(i)
47 memset(per_cpu_ptr(part->bd_stats, i), value,
48 sizeof(struct disk_stats));
51 #define part_stat_read_accum(part, field) \
52 (part_stat_read(part, field[STAT_READ]) + \
53 part_stat_read(part, field[STAT_WRITE]) + \
54 part_stat_read(part, field[STAT_DISCARD]))
56 #define __part_stat_add(part, field, addnd) \
57 __this_cpu_add((part)->bd_stats->field, addnd)
59 #define part_stat_add(part, field, addnd) do { \
60 __part_stat_add((part), field, addnd); \
61 if ((part)->bd_partno) \
62 __part_stat_add(bdev_whole(part), field, addnd); \
65 #define part_stat_dec(part, field) \
66 part_stat_add(part, field, -1)
67 #define part_stat_inc(part, field) \
68 part_stat_add(part, field, 1)
69 #define part_stat_sub(part, field, subnd) \
70 part_stat_add(part, field, -subnd)
72 #define part_stat_local_dec(part, field) \
73 local_dec(&(part_stat_get(part, field)))
74 #define part_stat_local_inc(part, field) \
75 local_inc(&(part_stat_get(part, field)))
76 #define part_stat_local_read(part, field) \
77 local_read(&(part_stat_get(part, field)))
78 #define part_stat_local_read_cpu(part, field, cpu) \
79 local_read(&(part_stat_get_cpu(part, field, cpu)))
81 #endif /* _LINUX_PART_STAT_H */