Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 1 | #ifndef FIO_DISKUTIL_H |
| 2 | #define FIO_DISKUTIL_H |
| 3 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 4 | #define FIO_DU_NAME_SZ 64 |
| 5 | |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 6 | /* |
| 7 | * Disk utils as read in /sys/block/<dev>/stat |
| 8 | */ |
| 9 | struct disk_util_stat { |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 10 | uint8_t name[FIO_DU_NAME_SZ]; |
| 11 | uint32_t ios[2]; |
| 12 | uint32_t merges[2]; |
| 13 | uint64_t sectors[2]; |
| 14 | uint32_t ticks[2]; |
| 15 | uint32_t io_ticks; |
| 16 | uint32_t time_in_queue; |
| 17 | uint64_t msec; |
| 18 | }; |
| 19 | |
| 20 | struct disk_util_agg { |
| 21 | uint32_t ios[2]; |
| 22 | uint32_t merges[2]; |
| 23 | uint64_t sectors[2]; |
| 24 | uint32_t ticks[2]; |
| 25 | uint32_t io_ticks; |
| 26 | uint32_t time_in_queue; |
| 27 | uint32_t slavecount; |
| 28 | fio_fp64_t max_util; |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * Per-device disk util management |
| 33 | */ |
| 34 | struct disk_util { |
| 35 | struct flist_head list; |
| 36 | /* If this disk is a slave, hook it into the master's |
| 37 | * list using this head. |
| 38 | */ |
| 39 | struct flist_head slavelist; |
| 40 | |
| 41 | char *name; |
| 42 | char *sysfs_root; |
| 43 | char path[256]; |
| 44 | int major, minor; |
| 45 | |
| 46 | struct disk_util_stat dus; |
| 47 | struct disk_util_stat last_dus; |
| 48 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 49 | struct disk_util_agg agg; |
| 50 | |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 51 | /* For software raids, this entry maintains pointers to the |
| 52 | * entries for the slave devices. The disk_util entries for |
| 53 | * the slaves devices should primarily be maintained through |
| 54 | * the disk_list list, i.e. for memory allocation and |
| 55 | * de-allocation, etc. Whereas this list should be used only |
| 56 | * for aggregating a software RAID's disk util figures. |
| 57 | */ |
| 58 | struct flist_head slaves; |
| 59 | |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 60 | struct timeval time; |
| 61 | |
| 62 | struct fio_mutex *lock; |
| 63 | unsigned long users; |
| 64 | }; |
| 65 | |
Jens Axboe | e99ca81 | 2009-10-01 19:44:36 +0200 | [diff] [blame] | 66 | static inline void disk_util_mod(struct disk_util *du, int val) |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 67 | { |
| 68 | if (du) { |
Jens Axboe | e99ca81 | 2009-10-01 19:44:36 +0200 | [diff] [blame] | 69 | struct flist_head *n; |
| 70 | |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 71 | fio_mutex_down(du->lock); |
Jens Axboe | e99ca81 | 2009-10-01 19:44:36 +0200 | [diff] [blame] | 72 | du->users += val; |
| 73 | |
| 74 | flist_for_each(n, &du->slavelist) { |
| 75 | struct disk_util *slave; |
| 76 | |
| 77 | slave = flist_entry(n, struct disk_util, slavelist); |
| 78 | slave->users += val; |
| 79 | } |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 80 | fio_mutex_up(du->lock); |
| 81 | } |
| 82 | } |
Jens Axboe | e99ca81 | 2009-10-01 19:44:36 +0200 | [diff] [blame] | 83 | static inline void disk_util_inc(struct disk_util *du) |
| 84 | { |
| 85 | disk_util_mod(du, 1); |
| 86 | } |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 87 | |
| 88 | static inline void disk_util_dec(struct disk_util *du) |
| 89 | { |
Jens Axboe | e99ca81 | 2009-10-01 19:44:36 +0200 | [diff] [blame] | 90 | disk_util_mod(du, -1); |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | #define DISK_UTIL_MSEC (250) |
| 94 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 95 | extern struct flist_head disk_list; |
| 96 | |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 97 | /* |
| 98 | * disk util stuff |
| 99 | */ |
| 100 | #ifdef FIO_HAVE_DISK_UTIL |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 101 | extern void print_disk_util(struct disk_util_stat *, struct disk_util_agg *, int terse); |
| 102 | extern void show_disk_util(int terse); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 103 | extern void free_disk_util(void); |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 104 | extern void init_disk_util(struct thread_data *); |
| 105 | extern void update_io_ticks(void); |
| 106 | #else |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 107 | #define print_disk_util(dus, agg, terse) |
| 108 | #define show_disk_util(terse) |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 109 | #define free_disk_util() |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 110 | #define init_disk_util(td) |
| 111 | #define update_io_ticks() |
| 112 | #endif |
| 113 | |
| 114 | #endif |