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