Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <sys/time.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <dirent.h> |
| 7 | #include <libgen.h> |
| 8 | #include <math.h> |
| 9 | |
| 10 | #include "fio.h" |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 11 | #include "smalloc.h" |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 12 | #include "diskutil.h" |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 13 | |
| 14 | static int last_majdev, last_mindev; |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 15 | static struct disk_util *last_du; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 16 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 17 | static struct fio_mutex *disk_util_mutex; |
| 18 | static int disk_util_exit; |
| 19 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 20 | FLIST_HEAD(disk_list); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 21 | |
Jens Axboe | 2db4ecc | 2009-09-11 22:22:41 +0200 | [diff] [blame] | 22 | static struct disk_util *__init_per_file_disk_util(struct thread_data *td, |
| 23 | int majdev, int mindev, char *path); |
| 24 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 25 | static void disk_util_free(struct disk_util *du) |
| 26 | { |
| 27 | if (du == last_du) |
| 28 | last_du = NULL; |
| 29 | |
Jens Axboe | b8d541d | 2010-06-21 12:40:53 +0200 | [diff] [blame] | 30 | while (!flist_empty(&du->slaves)) { |
| 31 | struct disk_util *slave; |
| 32 | |
| 33 | slave = flist_entry(du->slaves.next, struct disk_util, slavelist); |
| 34 | flist_del(&slave->slavelist); |
| 35 | slave->users--; |
| 36 | } |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 37 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 38 | fio_mutex_remove(du->lock); |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 39 | sfree(du); |
| 40 | } |
| 41 | |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 42 | static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) |
| 43 | { |
| 44 | unsigned in_flight; |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 45 | unsigned long long sectors[2]; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 46 | char line[256]; |
| 47 | FILE *f; |
| 48 | char *p; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 49 | int ret; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 50 | |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 51 | dprint(FD_DISKUTIL, "open stat file: %s\n", du->path); |
| 52 | |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 53 | f = fopen(du->path, "r"); |
| 54 | if (!f) |
| 55 | return 1; |
| 56 | |
| 57 | p = fgets(line, sizeof(line), f); |
| 58 | if (!p) { |
| 59 | fclose(f); |
| 60 | return 1; |
| 61 | } |
| 62 | |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 63 | dprint(FD_DISKUTIL, "%s: %s", du->path, p); |
| 64 | |
| 65 | ret = sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0], |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 66 | &dus->merges[0], §ors[0], |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 67 | &dus->ticks[0], &dus->ios[1], |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 68 | &dus->merges[1], §ors[1], |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 69 | &dus->ticks[1], &in_flight, |
| 70 | &dus->io_ticks, &dus->time_in_queue); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 71 | fclose(f); |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 72 | dprint(FD_DISKUTIL, "%s: stat read ok? %d\n", du->path, ret == 1); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 73 | dus->sectors[0] = sectors[0]; |
| 74 | dus->sectors[1] = sectors[1]; |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 75 | return ret != 11; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static void update_io_tick_disk(struct disk_util *du) |
| 79 | { |
| 80 | struct disk_util_stat __dus, *dus, *ldus; |
| 81 | struct timeval t; |
| 82 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 83 | if (!du->users) |
| 84 | return; |
Jens Axboe | 90b97ac | 2010-06-21 12:35:02 +0200 | [diff] [blame] | 85 | if (get_io_ticks(du, &__dus)) |
| 86 | return; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 87 | |
| 88 | dus = &du->dus; |
| 89 | ldus = &du->last_dus; |
| 90 | |
| 91 | dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]); |
| 92 | dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]); |
| 93 | dus->ios[0] += (__dus.ios[0] - ldus->ios[0]); |
| 94 | dus->ios[1] += (__dus.ios[1] - ldus->ios[1]); |
| 95 | dus->merges[0] += (__dus.merges[0] - ldus->merges[0]); |
| 96 | dus->merges[1] += (__dus.merges[1] - ldus->merges[1]); |
| 97 | dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]); |
| 98 | dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]); |
| 99 | dus->io_ticks += (__dus.io_ticks - ldus->io_ticks); |
| 100 | dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue); |
| 101 | |
| 102 | fio_gettime(&t, NULL); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 103 | dus->msec += mtime_since(&du->time, &t); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 104 | memcpy(&du->time, &t, sizeof(t)); |
| 105 | memcpy(ldus, &__dus, sizeof(__dus)); |
| 106 | } |
| 107 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 108 | int update_io_ticks(void) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 109 | { |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 110 | struct flist_head *entry; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 111 | struct disk_util *du; |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 112 | int ret = 0; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 113 | |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 114 | dprint(FD_DISKUTIL, "update io ticks\n"); |
| 115 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 116 | fio_mutex_down(disk_util_mutex); |
| 117 | |
| 118 | if (!disk_util_exit) { |
| 119 | flist_for_each(entry, &disk_list) { |
| 120 | du = flist_entry(entry, struct disk_util, list); |
| 121 | update_io_tick_disk(du); |
| 122 | } |
| 123 | } else |
| 124 | ret = 1; |
| 125 | |
| 126 | fio_mutex_up(disk_util_mutex); |
| 127 | return ret; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Jens Axboe | e11c410 | 2007-04-03 16:33:04 -0700 | [diff] [blame] | 130 | static struct disk_util *disk_util_exists(int major, int minor) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 131 | { |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 132 | struct flist_head *entry; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 133 | struct disk_util *du; |
| 134 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 135 | fio_mutex_down(disk_util_mutex); |
| 136 | |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 137 | flist_for_each(entry, &disk_list) { |
| 138 | du = flist_entry(entry, struct disk_util, list); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 139 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 140 | if (major == du->major && minor == du->minor) { |
| 141 | fio_mutex_up(disk_util_mutex); |
Jens Axboe | e11c410 | 2007-04-03 16:33:04 -0700 | [diff] [blame] | 142 | return du; |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 143 | } |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 146 | fio_mutex_up(disk_util_mutex); |
Jens Axboe | e11c410 | 2007-04-03 16:33:04 -0700 | [diff] [blame] | 147 | return NULL; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 148 | } |
| 149 | |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 150 | static int get_device_numbers(char *file_name, int *maj, int *min) |
| 151 | { |
| 152 | struct stat st; |
| 153 | int majdev, mindev; |
| 154 | char tempname[PATH_MAX], *p; |
| 155 | |
| 156 | if (!lstat(file_name, &st)) { |
| 157 | if (S_ISBLK(st.st_mode)) { |
| 158 | majdev = major(st.st_rdev); |
| 159 | mindev = minor(st.st_rdev); |
| 160 | } else if (S_ISCHR(st.st_mode)) { |
| 161 | majdev = major(st.st_rdev); |
| 162 | mindev = minor(st.st_rdev); |
| 163 | if (fio_lookup_raw(st.st_rdev, &majdev, &mindev)) |
| 164 | return -1; |
| 165 | } else if (S_ISFIFO(st.st_mode)) |
| 166 | return -1; |
| 167 | else { |
| 168 | majdev = major(st.st_dev); |
| 169 | mindev = minor(st.st_dev); |
| 170 | } |
| 171 | } else { |
| 172 | /* |
| 173 | * must be a file, open "." in that path |
| 174 | */ |
| 175 | strncpy(tempname, file_name, PATH_MAX - 1); |
| 176 | p = dirname(tempname); |
| 177 | if (stat(p, &st)) { |
| 178 | perror("disk util stat"); |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | majdev = major(st.st_dev); |
| 183 | mindev = minor(st.st_dev); |
| 184 | } |
| 185 | |
| 186 | *min = mindev; |
| 187 | *maj = majdev; |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static int read_block_dev_entry(char *path, int *maj, int *min) |
| 193 | { |
| 194 | char line[256], *p; |
| 195 | FILE *f; |
| 196 | |
| 197 | f = fopen(path, "r"); |
| 198 | if (!f) { |
| 199 | perror("open path"); |
| 200 | return 1; |
| 201 | } |
| 202 | |
| 203 | p = fgets(line, sizeof(line), f); |
| 204 | fclose(f); |
| 205 | |
| 206 | if (!p) |
| 207 | return 1; |
| 208 | |
| 209 | if (sscanf(p, "%u:%u", maj, min) != 2) |
| 210 | return 1; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 215 | static void find_add_disk_slaves(struct thread_data *td, char *path, |
Jens Axboe | 2db4ecc | 2009-09-11 22:22:41 +0200 | [diff] [blame] | 216 | struct disk_util *masterdu) |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 217 | { |
| 218 | DIR *dirhandle = NULL; |
| 219 | struct dirent *dirent = NULL; |
| 220 | char slavesdir[PATH_MAX], temppath[PATH_MAX], slavepath[PATH_MAX]; |
| 221 | struct disk_util *slavedu = NULL; |
| 222 | int majdev, mindev; |
| 223 | ssize_t linklen; |
| 224 | |
Jens Axboe | 2db4ecc | 2009-09-11 22:22:41 +0200 | [diff] [blame] | 225 | sprintf(slavesdir, "%s/%s", path, "slaves"); |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 226 | dirhandle = opendir(slavesdir); |
| 227 | if (!dirhandle) |
| 228 | return; |
| 229 | |
| 230 | while ((dirent = readdir(dirhandle)) != NULL) { |
Jens Axboe | 2db4ecc | 2009-09-11 22:22:41 +0200 | [diff] [blame] | 231 | if (!strcmp(dirent->d_name, ".") || |
| 232 | !strcmp(dirent->d_name, "..")) |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 233 | continue; |
| 234 | |
Bruce Cran | b9fd788 | 2012-02-20 17:01:46 +0000 | [diff] [blame] | 235 | sprintf(temppath, "%s%s%s", slavesdir, FIO_OS_PATH_SEPARATOR, dirent->d_name); |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 236 | /* Can we always assume that the slaves device entries |
| 237 | * are links to the real directories for the slave |
| 238 | * devices? |
| 239 | */ |
Jens Axboe | 2db4ecc | 2009-09-11 22:22:41 +0200 | [diff] [blame] | 240 | linklen = readlink(temppath, slavepath, PATH_MAX - 0); |
| 241 | if (linklen < 0) { |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 242 | perror("readlink() for slave device."); |
| 243 | return; |
| 244 | } |
Jens Axboe | 2db4ecc | 2009-09-11 22:22:41 +0200 | [diff] [blame] | 245 | slavepath[linklen] = '\0'; |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 246 | |
| 247 | sprintf(temppath, "%s/%s/dev", slavesdir, slavepath); |
| 248 | if (read_block_dev_entry(temppath, &majdev, &mindev)) { |
| 249 | perror("Error getting slave device numbers."); |
| 250 | return; |
| 251 | } |
| 252 | |
Alan D. Brunelle | b06de82 | 2009-09-11 14:57:10 -0400 | [diff] [blame] | 253 | /* |
| 254 | * See if this maj,min already exists |
| 255 | */ |
| 256 | slavedu = disk_util_exists(majdev, mindev); |
| 257 | if (slavedu) |
| 258 | continue; |
| 259 | |
Bruce Cran | b9fd788 | 2012-02-20 17:01:46 +0000 | [diff] [blame] | 260 | sprintf(temppath, "%s%s%s", slavesdir, FIO_OS_PATH_SEPARATOR, slavepath); |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 261 | __init_per_file_disk_util(td, majdev, mindev, temppath); |
| 262 | slavedu = disk_util_exists(majdev, mindev); |
| 263 | |
| 264 | /* Should probably use an assert here. slavedu should |
| 265 | * always be present at this point. */ |
Jens Axboe | b8d541d | 2010-06-21 12:40:53 +0200 | [diff] [blame] | 266 | if (slavedu) { |
| 267 | slavedu->users++; |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 268 | flist_add_tail(&slavedu->slavelist, &masterdu->slaves); |
Jens Axboe | b8d541d | 2010-06-21 12:40:53 +0200 | [diff] [blame] | 269 | } |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | closedir(dirhandle); |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 273 | } |
| 274 | |
Jens Axboe | b8fefc2 | 2011-09-08 13:08:05 +0200 | [diff] [blame] | 275 | static struct disk_util *disk_util_add(struct thread_data *td, int majdev, |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 276 | int mindev, char *path) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 277 | { |
| 278 | struct disk_util *du, *__du; |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 279 | struct flist_head *entry; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 280 | |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 281 | dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path); |
| 282 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 283 | du = smalloc(sizeof(*du)); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 284 | memset(du, 0, sizeof(*du)); |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 285 | INIT_FLIST_HEAD(&du->list); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 286 | sprintf(du->path, "%s/stat", path); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 287 | strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ); |
Jens Axboe | e11c410 | 2007-04-03 16:33:04 -0700 | [diff] [blame] | 288 | du->sysfs_root = path; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 289 | du->major = majdev; |
| 290 | du->minor = mindev; |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 291 | INIT_FLIST_HEAD(&du->slavelist); |
| 292 | INIT_FLIST_HEAD(&du->slaves); |
Jens Axboe | 521da52 | 2012-08-02 11:21:36 +0200 | [diff] [blame] | 293 | du->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 294 | du->users = 0; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 295 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 296 | fio_mutex_down(disk_util_mutex); |
| 297 | |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 298 | flist_for_each(entry, &disk_list) { |
| 299 | __du = flist_entry(entry, struct disk_util, list); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 300 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 301 | dprint(FD_DISKUTIL, "found %s in list\n", __du->dus.name); |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 302 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 303 | if (!strcmp((char *) du->dus.name, (char *) __du->dus.name)) { |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 304 | disk_util_free(du); |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 305 | fio_mutex_up(disk_util_mutex); |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 306 | return __du; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 310 | dprint(FD_DISKUTIL, "add %s to list\n", du->dus.name); |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 311 | |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 312 | fio_gettime(&du->time, NULL); |
| 313 | get_io_ticks(du, &du->last_dus); |
| 314 | |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 315 | flist_add_tail(&du->list, &disk_list); |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 316 | fio_mutex_up(disk_util_mutex); |
| 317 | |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 318 | find_add_disk_slaves(td, path, du); |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 319 | return du; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static int check_dev_match(int majdev, int mindev, char *path) |
| 323 | { |
| 324 | int major, minor; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 325 | |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 326 | if (read_block_dev_entry(path, &major, &minor)) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 327 | return 1; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 328 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 329 | if (majdev == major && mindev == minor) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 330 | return 0; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 331 | |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 332 | return 1; |
| 333 | } |
| 334 | |
Jens Axboe | ac0be2a | 2008-06-06 12:08:04 +0200 | [diff] [blame] | 335 | static int find_block_dir(int majdev, int mindev, char *path, int link_ok) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 336 | { |
| 337 | struct dirent *dir; |
| 338 | struct stat st; |
| 339 | int found = 0; |
| 340 | DIR *D; |
| 341 | |
| 342 | D = opendir(path); |
| 343 | if (!D) |
| 344 | return 0; |
| 345 | |
| 346 | while ((dir = readdir(D)) != NULL) { |
| 347 | char full_path[256]; |
| 348 | |
| 349 | if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) |
| 350 | continue; |
| 351 | |
Bruce Cran | b9fd788 | 2012-02-20 17:01:46 +0000 | [diff] [blame] | 352 | sprintf(full_path, "%s%s%s", path, FIO_OS_PATH_SEPARATOR, dir->d_name); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 353 | |
| 354 | if (!strcmp(dir->d_name, "dev")) { |
| 355 | if (!check_dev_match(majdev, mindev, full_path)) { |
| 356 | found = 1; |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | |
Jens Axboe | ac0be2a | 2008-06-06 12:08:04 +0200 | [diff] [blame] | 361 | if (link_ok) { |
| 362 | if (stat(full_path, &st) == -1) { |
| 363 | perror("stat"); |
| 364 | break; |
| 365 | } |
| 366 | } else { |
| 367 | if (lstat(full_path, &st) == -1) { |
| 368 | perror("stat"); |
| 369 | break; |
| 370 | } |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) |
| 374 | continue; |
| 375 | |
Jens Axboe | ac0be2a | 2008-06-06 12:08:04 +0200 | [diff] [blame] | 376 | found = find_block_dir(majdev, mindev, full_path, 0); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 377 | if (found) { |
| 378 | strcpy(path, full_path); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | closedir(D); |
| 384 | return found; |
| 385 | } |
| 386 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 387 | static struct disk_util *__init_per_file_disk_util(struct thread_data *td, |
| 388 | int majdev, int mindev, |
| 389 | char *path) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 390 | { |
| 391 | struct stat st; |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 392 | char tmp[PATH_MAX]; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 393 | char *p; |
| 394 | |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 395 | /* |
| 396 | * If there's a ../queue/ directory there, we are inside a partition. |
| 397 | * Check if that is the case and jump back. For loop/md/dm etc we |
| 398 | * are already in the right spot. |
| 399 | */ |
| 400 | sprintf(tmp, "%s/../queue", path); |
| 401 | if (!stat(tmp, &st)) { |
| 402 | p = dirname(path); |
| 403 | sprintf(tmp, "%s/queue", p); |
| 404 | if (stat(tmp, &st)) { |
| 405 | log_err("unknown sysfs layout\n"); |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 406 | return NULL; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 407 | } |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 408 | strncpy(tmp, p, PATH_MAX - 1); |
| 409 | sprintf(path, "%s", tmp); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 412 | if (td->o.ioscheduler && !td->sysfs_root) |
| 413 | td->sysfs_root = strdup(path); |
| 414 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 415 | return disk_util_add(td, majdev, mindev, path); |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 416 | } |
| 417 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 418 | static struct disk_util *init_per_file_disk_util(struct thread_data *td, |
| 419 | char *filename) |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 420 | { |
| 421 | |
| 422 | char foo[PATH_MAX]; |
| 423 | struct disk_util *du; |
| 424 | int mindev, majdev; |
| 425 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 426 | if (get_device_numbers(filename, &majdev, &mindev)) |
| 427 | return NULL; |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 428 | |
| 429 | dprint(FD_DISKUTIL, "%s belongs to maj/min %d/%d\n", filename, majdev, |
| 430 | mindev); |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 431 | |
Jens Axboe | e11c410 | 2007-04-03 16:33:04 -0700 | [diff] [blame] | 432 | du = disk_util_exists(majdev, mindev); |
| 433 | if (du) { |
| 434 | if (td->o.ioscheduler && !td->sysfs_root) |
| 435 | td->sysfs_root = strdup(du->sysfs_root); |
| 436 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 437 | return du; |
Jens Axboe | e11c410 | 2007-04-03 16:33:04 -0700 | [diff] [blame] | 438 | } |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 439 | |
| 440 | /* |
| 441 | * for an fs without a device, we will repeatedly stat through |
| 442 | * sysfs which can take oodles of time for thousands of files. so |
| 443 | * cache the last lookup and compare with that before going through |
| 444 | * everything again. |
| 445 | */ |
| 446 | if (mindev == last_mindev && majdev == last_majdev) |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 447 | return last_du; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 448 | |
| 449 | last_mindev = mindev; |
| 450 | last_majdev = majdev; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 451 | |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 452 | sprintf(foo, "/sys/block"); |
Jens Axboe | ac0be2a | 2008-06-06 12:08:04 +0200 | [diff] [blame] | 453 | if (!find_block_dir(majdev, mindev, foo, 1)) |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 454 | return NULL; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 455 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 456 | return __init_per_file_disk_util(td, majdev, mindev, foo); |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 457 | } |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 458 | |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 459 | static struct disk_util *__init_disk_util(struct thread_data *td, |
| 460 | struct fio_file *f) |
Shehjar Tikoo | 6742301 | 2008-09-30 10:35:44 +1000 | [diff] [blame] | 461 | { |
| 462 | return init_per_file_disk_util(td, f->file_name); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void init_disk_util(struct thread_data *td) |
| 466 | { |
| 467 | struct fio_file *f; |
| 468 | unsigned int i; |
| 469 | |
| 470 | if (!td->o.do_disk_util || |
| 471 | (td->io_ops->flags & (FIO_DISKLESSIO | FIO_NODISKUTIL))) |
| 472 | return; |
| 473 | |
| 474 | for_each_file(td, f, i) |
Jens Axboe | c97bd0f | 2009-05-27 13:11:20 +0200 | [diff] [blame] | 475 | f->du = __init_disk_util(td, f); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 478 | static void show_agg_stats(struct disk_util_agg *agg, int terse) |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 479 | { |
| 480 | if (!agg->slavecount) |
| 481 | return; |
| 482 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 483 | if (!terse) { |
| 484 | log_info(", aggrios=%u/%u, aggrmerge=%u/%u, aggrticks=%u/%u," |
| 485 | " aggrin_queue=%u, aggrutil=%3.2f%%", |
| 486 | agg->ios[0] / agg->slavecount, |
| 487 | agg->ios[1] / agg->slavecount, |
| 488 | agg->merges[0] / agg->slavecount, |
| 489 | agg->merges[1] / agg->slavecount, |
| 490 | agg->ticks[0] / agg->slavecount, |
| 491 | agg->ticks[1] / agg->slavecount, |
| 492 | agg->time_in_queue / agg->slavecount, |
| 493 | agg->max_util.u.f); |
| 494 | } else { |
Jens Axboe | 97b007e | 2012-02-10 19:21:50 +0100 | [diff] [blame] | 495 | log_info(";slaves;%u;%u;%u;%u;%u;%u;%u;%3.2f%%", |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 496 | agg->ios[0] / agg->slavecount, |
| 497 | agg->ios[1] / agg->slavecount, |
| 498 | agg->merges[0] / agg->slavecount, |
| 499 | agg->merges[1] / agg->slavecount, |
| 500 | agg->ticks[0] / agg->slavecount, |
| 501 | agg->ticks[1] / agg->slavecount, |
| 502 | agg->time_in_queue / agg->slavecount, |
| 503 | agg->max_util.u.f); |
| 504 | } |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 507 | static void aggregate_slaves_stats(struct disk_util *masterdu) |
| 508 | { |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 509 | struct disk_util_agg *agg = &masterdu->agg; |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 510 | struct disk_util_stat *dus; |
| 511 | struct flist_head *entry; |
| 512 | struct disk_util *slavedu; |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 513 | double util; |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 514 | |
| 515 | flist_for_each(entry, &masterdu->slaves) { |
| 516 | slavedu = flist_entry(entry, struct disk_util, slavelist); |
| 517 | dus = &slavedu->dus; |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 518 | agg->ios[0] += dus->ios[0]; |
| 519 | agg->ios[1] += dus->ios[1]; |
| 520 | agg->merges[0] += dus->merges[0]; |
| 521 | agg->merges[1] += dus->merges[1]; |
| 522 | agg->sectors[0] += dus->sectors[0]; |
| 523 | agg->sectors[1] += dus->sectors[1]; |
| 524 | agg->ticks[0] += dus->ticks[0]; |
| 525 | agg->ticks[1] += dus->ticks[1]; |
| 526 | agg->time_in_queue += dus->time_in_queue; |
| 527 | agg->slavecount++; |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 528 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 529 | util = (double) (100 * dus->io_ticks / (double) slavedu->dus.msec); |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 530 | /* System utilization is the utilization of the |
| 531 | * component with the highest utilization. |
| 532 | */ |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 533 | if (util > agg->max_util.u.f) |
| 534 | agg->max_util.u.f = util; |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 535 | |
| 536 | } |
| 537 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 538 | if (agg->max_util.u.f > 100.0) |
| 539 | agg->max_util.u.f = 100.0; |
| 540 | } |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 541 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 542 | void free_disk_util(void) |
| 543 | { |
| 544 | struct disk_util *du; |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 545 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 546 | disk_util_exit = 1; |
| 547 | wait_for_disk_thread_exit(); |
| 548 | |
| 549 | fio_mutex_down(disk_util_mutex); |
| 550 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 551 | while (!flist_empty(&disk_list)) { |
| 552 | du = flist_entry(disk_list.next, struct disk_util, list); |
| 553 | flist_del(&du->list); |
| 554 | disk_util_free(du); |
| 555 | } |
| 556 | |
| 557 | last_majdev = last_mindev = -1; |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 558 | fio_mutex_up(disk_util_mutex); |
| 559 | fio_mutex_remove(disk_util_mutex); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 562 | void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg, |
| 563 | int terse) |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 564 | { |
Jens Axboe | 6914f59 | 2012-02-03 12:06:19 +0100 | [diff] [blame] | 565 | double util = 0; |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 566 | |
Jens Axboe | 6914f59 | 2012-02-03 12:06:19 +0100 | [diff] [blame] | 567 | if (dus->msec) |
| 568 | util = (double) 100 * dus->io_ticks / (double) dus->msec; |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 569 | if (util > 100.0) |
| 570 | util = 100.0; |
| 571 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 572 | if (!terse) { |
Jens Axboe | f1d6455 | 2012-02-10 19:30:23 +0100 | [diff] [blame] | 573 | if (agg->slavecount) |
| 574 | log_info(" "); |
| 575 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 576 | log_info(" %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, " |
| 577 | "in_queue=%u, util=%3.2f%%", dus->name, |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 578 | dus->ios[0], dus->ios[1], |
| 579 | dus->merges[0], dus->merges[1], |
| 580 | dus->ticks[0], dus->ticks[1], |
| 581 | dus->time_in_queue, util); |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 582 | } else { |
Jens Axboe | 3d7cd9b | 2011-10-18 08:31:01 +0200 | [diff] [blame] | 583 | log_info(";%s;%u;%u;%u;%u;%u;%u;%u;%3.2f%%", |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 584 | dus->name, dus->ios[0], dus->ios[1], |
| 585 | dus->merges[0], dus->merges[1], |
| 586 | dus->ticks[0], dus->ticks[1], |
| 587 | dus->time_in_queue, util); |
| 588 | } |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 589 | |
| 590 | /* |
| 591 | * If the device has slaves, aggregate the stats for |
| 592 | * those slave devices also. |
| 593 | */ |
Jens Axboe | f1d6455 | 2012-02-10 19:30:23 +0100 | [diff] [blame] | 594 | show_agg_stats(agg, terse); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 595 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 596 | if (!terse) |
| 597 | log_info("\n"); |
Shehjar Tikoo | 043b74b | 2008-09-30 11:11:35 +1000 | [diff] [blame] | 598 | } |
| 599 | |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 600 | static void print_disk_util_json(struct disk_util *du, struct json_array *array) |
| 601 | { |
| 602 | double util = 0; |
| 603 | struct disk_util_stat *dus = &du->dus; |
| 604 | struct disk_util_agg *agg = &du->agg; |
| 605 | struct json_object *obj; |
| 606 | |
| 607 | obj = json_create_object(); |
| 608 | json_array_add_value_object(array, obj); |
| 609 | |
| 610 | if (dus->msec) |
| 611 | util = (double) 100 * dus->io_ticks / (double) dus->msec; |
| 612 | if (util > 100.0) |
| 613 | util = 100.0; |
| 614 | |
| 615 | |
| 616 | json_object_add_value_string(obj, "name", dus->name); |
| 617 | json_object_add_value_int(obj, "read_ios", dus->ios[0]); |
| 618 | json_object_add_value_int(obj, "write_ios", dus->ios[1]); |
| 619 | json_object_add_value_int(obj, "read_merges", dus->merges[0]); |
| 620 | json_object_add_value_int(obj, "write_merges", dus->merges[1]); |
| 621 | json_object_add_value_int(obj, "read_ticks", dus->ticks[0]); |
| 622 | json_object_add_value_int(obj, "write_ticks", dus->ticks[1]); |
| 623 | json_object_add_value_int(obj, "in_queue", dus->time_in_queue); |
| 624 | json_object_add_value_float(obj, "util", util); |
| 625 | |
| 626 | /* |
| 627 | * If the device has slaves, aggregate the stats for |
| 628 | * those slave devices also. |
| 629 | */ |
| 630 | if (!agg->slavecount) |
| 631 | return; |
| 632 | json_object_add_value_int(obj, "aggr_read_ios", |
| 633 | agg->ios[0] / agg->slavecount); |
| 634 | json_object_add_value_int(obj, "aggr_write_ios", |
| 635 | agg->ios[1] / agg->slavecount); |
| 636 | json_object_add_value_int(obj, "aggr_read_merges", |
| 637 | agg->merges[0] / agg->slavecount); |
| 638 | json_object_add_value_int(obj, "aggr_write_merge", |
| 639 | agg->merges[1] / agg->slavecount); |
| 640 | json_object_add_value_int(obj, "aggr_read_ticks", |
| 641 | agg->ticks[0] / agg->slavecount); |
| 642 | json_object_add_value_int(obj, "aggr_write_ticks", |
| 643 | agg->ticks[1] / agg->slavecount); |
| 644 | json_object_add_value_int(obj, "aggr_in_queue", |
| 645 | agg->time_in_queue / agg->slavecount); |
| 646 | json_object_add_value_float(obj, "aggr_util", agg->max_util.u.f); |
| 647 | } |
| 648 | |
| 649 | void show_disk_util(int terse, struct json_object *parent) |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 650 | { |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 651 | struct flist_head *entry; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 652 | struct disk_util *du; |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 653 | struct json_array *array = NULL; |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 654 | |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 655 | fio_mutex_down(disk_util_mutex); |
| 656 | |
| 657 | if (flist_empty(&disk_list)) { |
| 658 | fio_mutex_up(disk_util_mutex); |
Jens Axboe | 0a839f3 | 2007-04-26 09:02:34 +0200 | [diff] [blame] | 659 | return; |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 660 | } |
Jens Axboe | 0a839f3 | 2007-04-26 09:02:34 +0200 | [diff] [blame] | 661 | |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 662 | if (!terse) |
| 663 | log_info("\nDisk stats (read/write):\n"); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 664 | |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 665 | if (terse && terse_version == 4) { |
| 666 | array = json_create_array(); |
| 667 | json_object_add_value_array(parent, "disk_util", array); |
| 668 | } |
| 669 | |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 670 | flist_for_each(entry, &disk_list) { |
| 671 | du = flist_entry(entry, struct disk_util, list); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 672 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 673 | aggregate_slaves_stats(du); |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 674 | if (terse && terse_version == 4) |
| 675 | print_disk_util_json(du, array); |
| 676 | else |
| 677 | print_disk_util(&du->dus, &du->agg, terse); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 678 | } |
Jens Axboe | 9ec7779 | 2012-08-02 08:27:41 +0200 | [diff] [blame] | 679 | |
| 680 | fio_mutex_up(disk_util_mutex); |
| 681 | } |
| 682 | |
| 683 | void setup_disk_util(void) |
| 684 | { |
Jens Axboe | 521da52 | 2012-08-02 11:21:36 +0200 | [diff] [blame] | 685 | disk_util_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED); |
Jens Axboe | 9f8f206 | 2007-04-02 15:08:01 +0200 | [diff] [blame] | 686 | } |