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