2020-03-25 23:48:42 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _LINUX_PART_STAT_H
|
|
|
|
#define _LINUX_PART_STAT_H
|
|
|
|
|
2022-01-24 17:39:13 +08:00
|
|
|
#include <linux/blkdev.h>
|
2021-09-20 20:33:25 +08:00
|
|
|
#include <asm/local.h>
|
2020-03-25 23:48:42 +08:00
|
|
|
|
2020-05-27 13:24:14 +08:00
|
|
|
struct disk_stats {
|
|
|
|
u64 nsecs[NR_STAT_GROUPS];
|
|
|
|
unsigned long sectors[NR_STAT_GROUPS];
|
|
|
|
unsigned long ios[NR_STAT_GROUPS];
|
|
|
|
unsigned long merges[NR_STAT_GROUPS];
|
|
|
|
unsigned long io_ticks;
|
|
|
|
local_t in_flight[2];
|
|
|
|
};
|
|
|
|
|
2020-03-25 23:48:42 +08:00
|
|
|
/*
|
|
|
|
* Macros to operate on percpu disk statistics:
|
|
|
|
*
|
2020-05-27 13:24:14 +08:00
|
|
|
* {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters and should
|
|
|
|
* be called between disk_stat_lock() and disk_stat_unlock().
|
2020-03-25 23:48:42 +08:00
|
|
|
*
|
|
|
|
* part_stat_read() can be called at any time.
|
|
|
|
*/
|
2020-05-27 13:24:17 +08:00
|
|
|
#define part_stat_lock() preempt_disable()
|
|
|
|
#define part_stat_unlock() preempt_enable()
|
2020-03-25 23:48:42 +08:00
|
|
|
|
|
|
|
#define part_stat_get_cpu(part, field, cpu) \
|
2020-11-24 16:36:54 +08:00
|
|
|
(per_cpu_ptr((part)->bd_stats, (cpu))->field)
|
2020-03-25 23:48:42 +08:00
|
|
|
|
|
|
|
#define part_stat_get(part, field) \
|
|
|
|
part_stat_get_cpu(part, field, smp_processor_id())
|
|
|
|
|
|
|
|
#define part_stat_read(part, field) \
|
|
|
|
({ \
|
2020-11-24 16:36:54 +08:00
|
|
|
typeof((part)->bd_stats->field) res = 0; \
|
2020-03-25 23:48:42 +08:00
|
|
|
unsigned int _cpu; \
|
|
|
|
for_each_possible_cpu(_cpu) \
|
2020-11-24 16:36:54 +08:00
|
|
|
res += per_cpu_ptr((part)->bd_stats, _cpu)->field; \
|
2020-03-25 23:48:42 +08:00
|
|
|
res; \
|
|
|
|
})
|
|
|
|
|
2020-11-24 16:36:54 +08:00
|
|
|
static inline void part_stat_set_all(struct block_device *part, int value)
|
2020-03-25 23:48:42 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_possible_cpu(i)
|
2020-11-24 16:36:54 +08:00
|
|
|
memset(per_cpu_ptr(part->bd_stats, i), value,
|
2020-03-25 23:48:42 +08:00
|
|
|
sizeof(struct disk_stats));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define part_stat_read_accum(part, field) \
|
|
|
|
(part_stat_read(part, field[STAT_READ]) + \
|
|
|
|
part_stat_read(part, field[STAT_WRITE]) + \
|
|
|
|
part_stat_read(part, field[STAT_DISCARD]))
|
|
|
|
|
|
|
|
#define __part_stat_add(part, field, addnd) \
|
2020-11-24 16:36:54 +08:00
|
|
|
__this_cpu_add((part)->bd_stats->field, addnd)
|
2020-03-25 23:48:42 +08:00
|
|
|
|
|
|
|
#define part_stat_add(part, field, addnd) do { \
|
|
|
|
__part_stat_add((part), field, addnd); \
|
2020-11-24 16:36:54 +08:00
|
|
|
if ((part)->bd_partno) \
|
|
|
|
__part_stat_add(bdev_whole(part), field, addnd); \
|
2020-03-25 23:48:42 +08:00
|
|
|
} while (0)
|
|
|
|
|
2020-11-24 16:34:00 +08:00
|
|
|
#define part_stat_dec(part, field) \
|
|
|
|
part_stat_add(part, field, -1)
|
|
|
|
#define part_stat_inc(part, field) \
|
|
|
|
part_stat_add(part, field, 1)
|
|
|
|
#define part_stat_sub(part, field, subnd) \
|
|
|
|
part_stat_add(part, field, -subnd)
|
2020-03-25 23:48:42 +08:00
|
|
|
|
2020-11-24 16:34:00 +08:00
|
|
|
#define part_stat_local_dec(part, field) \
|
|
|
|
local_dec(&(part_stat_get(part, field)))
|
|
|
|
#define part_stat_local_inc(part, field) \
|
|
|
|
local_inc(&(part_stat_get(part, field)))
|
|
|
|
#define part_stat_local_read(part, field) \
|
|
|
|
local_read(&(part_stat_get(part, field)))
|
|
|
|
#define part_stat_local_read_cpu(part, field, cpu) \
|
|
|
|
local_read(&(part_stat_get_cpu(part, field, cpu)))
|
2020-03-25 23:48:42 +08:00
|
|
|
|
|
|
|
#endif /* _LINUX_PART_STAT_H */
|