Merge branch 'dev' of https://github.com/smartxworks/fio
[fio.git] / diskutil.h
CommitLineData
7c9b1bce
JA
1#ifndef FIO_DISKUTIL_H
2#define FIO_DISKUTIL_H
cc372b17 3#include "json.h"
d09a64a0
JA
4#define FIO_DU_NAME_SZ 64
5
e2bb0e58 6#include "helper_thread.h"
971caeb1 7#include "fio_sem.h"
27357187 8
a3b4cf7d 9struct disk_util_stats {
504bc961
JA
10 uint64_t ios[2];
11 uint64_t merges[2];
d09a64a0 12 uint64_t sectors[2];
504bc961
JA
13 uint64_t ticks[2];
14 uint64_t io_ticks;
15 uint64_t time_in_queue;
d09a64a0
JA
16 uint64_t msec;
17};
18
a3b4cf7d
JA
19/*
20 * Disk utils as read in /sys/block/<dev>/stat
21 */
22struct disk_util_stat {
23 uint8_t name[FIO_DU_NAME_SZ];
24 struct disk_util_stats s;
25};
26
d09a64a0 27struct disk_util_agg {
504bc961
JA
28 uint64_t ios[2];
29 uint64_t merges[2];
d09a64a0 30 uint64_t sectors[2];
504bc961
JA
31 uint64_t ticks[2];
32 uint64_t io_ticks;
33 uint64_t time_in_queue;
d09a64a0 34 uint32_t slavecount;
504bc961 35 uint32_t pad;
d09a64a0 36 fio_fp64_t max_util;
7c9b1bce
JA
37};
38
39/*
40 * Per-device disk util management
41 */
42struct disk_util {
43 struct flist_head list;
44 /* If this disk is a slave, hook it into the master's
45 * list using this head.
46 */
47 struct flist_head slavelist;
48
7c9b1bce 49 char *sysfs_root;
4b919f77 50 char path[PATH_MAX];
7c9b1bce
JA
51 int major, minor;
52
53 struct disk_util_stat dus;
54 struct disk_util_stat last_dus;
55
d09a64a0
JA
56 struct disk_util_agg agg;
57
7c9b1bce
JA
58 /* For software raids, this entry maintains pointers to the
59 * entries for the slave devices. The disk_util entries for
60 * the slaves devices should primarily be maintained through
61 * the disk_list list, i.e. for memory allocation and
62 * de-allocation, etc. Whereas this list should be used only
63 * for aggregating a software RAID's disk util figures.
64 */
65 struct flist_head slaves;
66
8b6a404c 67 struct timespec time;
7c9b1bce 68
971caeb1 69 struct fio_sem *lock;
7c9b1bce
JA
70 unsigned long users;
71};
72
e99ca81d 73static inline void disk_util_mod(struct disk_util *du, int val)
7c9b1bce
JA
74{
75 if (du) {
e99ca81d
JA
76 struct flist_head *n;
77
971caeb1 78 fio_sem_down(du->lock);
e99ca81d
JA
79 du->users += val;
80
81 flist_for_each(n, &du->slavelist) {
82 struct disk_util *slave;
83
84 slave = flist_entry(n, struct disk_util, slavelist);
85 slave->users += val;
86 }
971caeb1 87 fio_sem_up(du->lock);
7c9b1bce
JA
88 }
89}
e99ca81d
JA
90static inline void disk_util_inc(struct disk_util *du)
91{
92 disk_util_mod(du, 1);
93}
7c9b1bce
JA
94
95static inline void disk_util_dec(struct disk_util *du)
96{
e99ca81d 97 disk_util_mod(du, -1);
7c9b1bce
JA
98}
99
100#define DISK_UTIL_MSEC (250)
101
d09a64a0
JA
102extern struct flist_head disk_list;
103
7c9b1bce
JA
104/*
105 * disk util stuff
106 */
107#ifdef FIO_HAVE_DISK_UTIL
a666cab8
JA
108extern void print_disk_util(struct disk_util_stat *, struct disk_util_agg *, int terse, struct buf_output *);
109extern void show_disk_util(int terse, struct json_object *parent, struct buf_output *);
952b05e0
CF
110extern void json_array_add_disk_util(struct disk_util_stat *dus,
111 struct disk_util_agg *agg, struct json_array *parent);
7c9b1bce 112extern void init_disk_util(struct thread_data *);
9ec7779f
JA
113extern int update_io_ticks(void);
114extern void setup_disk_util(void);
27357187 115extern void disk_util_prune_entries(void);
7c9b1bce 116#else
9aa6aa64 117/* keep this as a function to avoid a warning in handle_du() */
941bda94 118static inline void print_disk_util(struct disk_util_stat *du,
a666cab8
JA
119 struct disk_util_agg *agg, int terse,
120 struct buf_output *out)
941bda94
JA
121{
122}
a666cab8 123#define show_disk_util(terse, parent, out)
27357187 124#define disk_util_prune_entries()
7c9b1bce 125#define init_disk_util(td)
9ec7779f 126#define setup_disk_util()
952b05e0
CF
127#define json_array_add_disk_util(dus, agg, parent)
128
9ec7779f
JA
129static inline int update_io_ticks(void)
130{
e2bb0e58 131 return helper_should_exit();
9ec7779f 132}
7c9b1bce
JA
133#endif
134
135#endif