1 #ifndef FIO_DISKUTIL_H
2 #define FIO_DISKUTIL_H
3 #include "json.h"
4 #define FIO_DU_NAME_SZ		64
5 
6 extern volatile int helper_exit;
7 
8 struct disk_util_stats {
9 	uint64_t ios[2];
10 	uint64_t merges[2];
11 	uint64_t sectors[2];
12 	uint64_t ticks[2];
13 	uint64_t io_ticks;
14 	uint64_t time_in_queue;
15 	uint64_t msec;
16 };
17 
18 /*
19  * Disk utils as read in /sys/block/<dev>/stat
20  */
21 struct disk_util_stat {
22 	uint8_t name[FIO_DU_NAME_SZ];
23 	struct disk_util_stats s;
24 };
25 
26 struct disk_util_agg {
27 	uint64_t ios[2];
28 	uint64_t merges[2];
29 	uint64_t sectors[2];
30 	uint64_t ticks[2];
31 	uint64_t io_ticks;
32 	uint64_t time_in_queue;
33 	uint32_t slavecount;
34 	uint32_t pad;
35 	fio_fp64_t max_util;
36 };
37 
38 /*
39  * Per-device disk util management
40  */
41 struct disk_util {
42 	struct flist_head list;
43 	/* If this disk is a slave, hook it into the master's
44 	 * list using this head.
45 	 */
46 	struct flist_head slavelist;
47 
48 	char *name;
49 	char *sysfs_root;
50 	char path[PATH_MAX];
51 	int major, minor;
52 
53 	struct disk_util_stat dus;
54 	struct disk_util_stat last_dus;
55 
56 	struct disk_util_agg agg;
57 
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 
67 	struct timeval time;
68 
69 	struct fio_mutex *lock;
70 	unsigned long users;
71 };
72 
disk_util_mod(struct disk_util * du,int val)73 static inline void disk_util_mod(struct disk_util *du, int val)
74 {
75 	if (du) {
76 		struct flist_head *n;
77 
78 		fio_mutex_down(du->lock);
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 		}
87 		fio_mutex_up(du->lock);
88 	}
89 }
disk_util_inc(struct disk_util * du)90 static inline void disk_util_inc(struct disk_util *du)
91 {
92 	disk_util_mod(du, 1);
93 }
94 
disk_util_dec(struct disk_util * du)95 static inline void disk_util_dec(struct disk_util *du)
96 {
97 	disk_util_mod(du, -1);
98 }
99 
100 #define DISK_UTIL_MSEC	(250)
101 
102 extern struct flist_head disk_list;
103 
104 /*
105  * disk util stuff
106  */
107 #ifdef FIO_HAVE_DISK_UTIL
108 extern void print_disk_util(struct disk_util_stat *, struct disk_util_agg *, int terse);
109 extern void show_disk_util(int terse, struct json_object *parent);
110 extern void json_array_add_disk_util(struct disk_util_stat *dus,
111 		struct disk_util_agg *agg, struct json_array *parent);
112 extern void init_disk_util(struct thread_data *);
113 extern int update_io_ticks(void);
114 extern void setup_disk_util(void);
115 extern void disk_util_prune_entries(void);
116 #else
print_disk_util(struct disk_util_stat * du,struct disk_util_agg * agg,int terse)117 static inline void print_disk_util(struct disk_util_stat *du,
118 				   struct disk_util_agg *agg, int terse)
119 {
120 }
121 #define show_disk_util(terse, parent)
122 #define disk_util_prune_entries()
123 #define init_disk_util(td)
124 #define setup_disk_util()
125 #define json_array_add_disk_util(dus, agg, parent)
126 
update_io_ticks(void)127 static inline int update_io_ticks(void)
128 {
129 	return helper_exit;
130 }
131 #endif
132 
133 #endif
134