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