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