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