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