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