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