1 #ifndef FIO_DISKUTIL_H
2 #define FIO_DISKUTIL_H
3 #define FIO_DU_NAME_SZ		64
4 
5 #include "helper_thread.h"
6 #include "fio_sem.h"
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 *sysfs_root;
49 	char path[PATH_MAX];
50 	int major, minor;
51 
52 	struct disk_util_stat dus;
53 	struct disk_util_stat last_dus;
54 
55 	struct disk_util_agg agg;
56 
57 	/* For software raids, this entry maintains pointers to the
58 	 * entries for the slave devices. The disk_util entries for
59 	 * the slaves devices should primarily be maintained through
60 	 * the disk_list list, i.e. for memory allocation and
61 	 * de-allocation, etc. Whereas this list should be used only
62 	 * for aggregating a software RAID's disk util figures.
63 	 */
64 	struct flist_head slaves;
65 
66 	struct timespec time;
67 
68 	struct fio_sem *lock;
69 	unsigned long users;
70 };
71 
disk_util_mod(struct disk_util * du,int val)72 static inline void disk_util_mod(struct disk_util *du, int val)
73 {
74 	if (du) {
75 		struct flist_head *n;
76 
77 		fio_sem_down(du->lock);
78 		du->users += val;
79 
80 		flist_for_each(n, &du->slavelist) {
81 			struct disk_util *slave;
82 
83 			slave = flist_entry(n, struct disk_util, slavelist);
84 			slave->users += val;
85 		}
86 		fio_sem_up(du->lock);
87 	}
88 }
disk_util_inc(struct disk_util * du)89 static inline void disk_util_inc(struct disk_util *du)
90 {
91 	disk_util_mod(du, 1);
92 }
93 
disk_util_dec(struct disk_util * du)94 static inline void disk_util_dec(struct disk_util *du)
95 {
96 	disk_util_mod(du, -1);
97 }
98 
99 #define DISK_UTIL_MSEC	(250)
100 
101 extern struct flist_head disk_list;
102 
103 /*
104  * disk util stuff
105  */
106 #ifdef FIO_HAVE_DISK_UTIL
107 extern void init_disk_util(struct thread_data *);
108 extern int update_io_ticks(void);
109 extern void setup_disk_util(void);
110 extern void disk_util_prune_entries(void);
111 #else
112 /* keep this as a function to avoid a warning in handle_du() */
113 #define disk_util_prune_entries()
114 #define init_disk_util(td)
115 #define setup_disk_util()
116 
update_io_ticks(void)117 static inline int update_io_ticks(void)
118 {
119 	return helper_should_exit();
120 }
121 #endif
122 
123 #endif
124