blob: 4f705c9bb5761a6e302598163cd1d44027d8933c [file] [log] [blame]
Jens Axboe9f8f2062007-04-02 15:08:01 +02001#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 Axboec97bd0f2009-05-27 13:11:20 +020011#include "smalloc.h"
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020012#include "diskutil.h"
Jens Axboe9f8f2062007-04-02 15:08:01 +020013
14static int last_majdev, last_mindev;
Jens Axboec97bd0f2009-05-27 13:11:20 +020015static struct disk_util *last_du;
Jens Axboe9f8f2062007-04-02 15:08:01 +020016
Jens Axboe01743ee2008-06-02 12:19:19 +020017static struct flist_head disk_list = FLIST_HEAD_INIT(disk_list);
Jens Axboe9f8f2062007-04-02 15:08:01 +020018
Jens Axboe2db4ecc2009-09-11 22:22:41 +020019static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
20 int majdev, int mindev, char *path);
21
Jens Axboec97bd0f2009-05-27 13:11:20 +020022static void disk_util_free(struct disk_util *du)
23{
24 if (du == last_du)
25 last_du = NULL;
26
Jens Axboeb8d541d2010-06-21 12:40:53 +020027 while (!flist_empty(&du->slaves)) {
28 struct disk_util *slave;
29
30 slave = flist_entry(du->slaves.next, struct disk_util, slavelist);
31 flist_del(&slave->slavelist);
32 slave->users--;
33 }
34
Jens Axboec97bd0f2009-05-27 13:11:20 +020035 fio_mutex_remove(du->lock);
36 sfree(du->name);
37 sfree(du);
38}
39
Jens Axboe9f8f2062007-04-02 15:08:01 +020040static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus)
41{
42 unsigned in_flight;
43 char line[256];
44 FILE *f;
45 char *p;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010046 int ret;
Jens Axboe9f8f2062007-04-02 15:08:01 +020047
Jens Axboecd991b92008-03-07 13:19:35 +010048 dprint(FD_DISKUTIL, "open stat file: %s\n", du->path);
49
Jens Axboe9f8f2062007-04-02 15:08:01 +020050 f = fopen(du->path, "r");
51 if (!f)
52 return 1;
53
54 p = fgets(line, sizeof(line), f);
55 if (!p) {
56 fclose(f);
57 return 1;
58 }
59
Jens Axboecd991b92008-03-07 13:19:35 +010060 dprint(FD_DISKUTIL, "%s: %s", du->path, p);
61
62 ret = sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0],
Jens Axboe5ec10ea2008-03-06 15:42:00 +010063 &dus->merges[0], &dus->sectors[0],
64 &dus->ticks[0], &dus->ios[1],
65 &dus->merges[1], &dus->sectors[1],
66 &dus->ticks[1], &in_flight,
67 &dus->io_ticks, &dus->time_in_queue);
Jens Axboe9f8f2062007-04-02 15:08:01 +020068 fclose(f);
Jens Axboecd991b92008-03-07 13:19:35 +010069 dprint(FD_DISKUTIL, "%s: stat read ok? %d\n", du->path, ret == 1);
70 return ret != 11;
Jens Axboe9f8f2062007-04-02 15:08:01 +020071}
72
73static void update_io_tick_disk(struct disk_util *du)
74{
75 struct disk_util_stat __dus, *dus, *ldus;
76 struct timeval t;
77
Jens Axboec97bd0f2009-05-27 13:11:20 +020078 if (!du->users)
79 return;
Jens Axboe90b97ac2010-06-21 12:35:02 +020080 if (get_io_ticks(du, &__dus))
81 return;
Jens Axboe9f8f2062007-04-02 15:08:01 +020082
83 dus = &du->dus;
84 ldus = &du->last_dus;
85
86 dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]);
87 dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]);
88 dus->ios[0] += (__dus.ios[0] - ldus->ios[0]);
89 dus->ios[1] += (__dus.ios[1] - ldus->ios[1]);
90 dus->merges[0] += (__dus.merges[0] - ldus->merges[0]);
91 dus->merges[1] += (__dus.merges[1] - ldus->merges[1]);
92 dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]);
93 dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]);
94 dus->io_ticks += (__dus.io_ticks - ldus->io_ticks);
95 dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue);
96
97 fio_gettime(&t, NULL);
98 du->msec += mtime_since(&du->time, &t);
99 memcpy(&du->time, &t, sizeof(t));
100 memcpy(ldus, &__dus, sizeof(__dus));
101}
102
103void update_io_ticks(void)
104{
Jens Axboe01743ee2008-06-02 12:19:19 +0200105 struct flist_head *entry;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200106 struct disk_util *du;
107
Jens Axboecd991b92008-03-07 13:19:35 +0100108 dprint(FD_DISKUTIL, "update io ticks\n");
109
Jens Axboe01743ee2008-06-02 12:19:19 +0200110 flist_for_each(entry, &disk_list) {
111 du = flist_entry(entry, struct disk_util, list);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200112 update_io_tick_disk(du);
113 }
114}
115
Jens Axboee11c4102007-04-03 16:33:04 -0700116static struct disk_util *disk_util_exists(int major, int minor)
Jens Axboe9f8f2062007-04-02 15:08:01 +0200117{
Jens Axboe01743ee2008-06-02 12:19:19 +0200118 struct flist_head *entry;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200119 struct disk_util *du;
120
Jens Axboe01743ee2008-06-02 12:19:19 +0200121 flist_for_each(entry, &disk_list) {
122 du = flist_entry(entry, struct disk_util, list);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200123
124 if (major == du->major && minor == du->minor)
Jens Axboee11c4102007-04-03 16:33:04 -0700125 return du;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200126 }
127
Jens Axboee11c4102007-04-03 16:33:04 -0700128 return NULL;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200129}
130
Shehjar Tikoo67423012008-09-30 10:35:44 +1000131static int get_device_numbers(char *file_name, int *maj, int *min)
132{
133 struct stat st;
134 int majdev, mindev;
135 char tempname[PATH_MAX], *p;
136
137 if (!lstat(file_name, &st)) {
138 if (S_ISBLK(st.st_mode)) {
139 majdev = major(st.st_rdev);
140 mindev = minor(st.st_rdev);
141 } else if (S_ISCHR(st.st_mode)) {
142 majdev = major(st.st_rdev);
143 mindev = minor(st.st_rdev);
144 if (fio_lookup_raw(st.st_rdev, &majdev, &mindev))
145 return -1;
146 } else if (S_ISFIFO(st.st_mode))
147 return -1;
148 else {
149 majdev = major(st.st_dev);
150 mindev = minor(st.st_dev);
151 }
152 } else {
153 /*
154 * must be a file, open "." in that path
155 */
156 strncpy(tempname, file_name, PATH_MAX - 1);
157 p = dirname(tempname);
158 if (stat(p, &st)) {
159 perror("disk util stat");
160 return -1;
161 }
162
163 majdev = major(st.st_dev);
164 mindev = minor(st.st_dev);
165 }
166
167 *min = mindev;
168 *maj = majdev;
169
170 return 0;
171}
172
173static int read_block_dev_entry(char *path, int *maj, int *min)
174{
175 char line[256], *p;
176 FILE *f;
177
178 f = fopen(path, "r");
179 if (!f) {
180 perror("open path");
181 return 1;
182 }
183
184 p = fgets(line, sizeof(line), f);
185 fclose(f);
186
187 if (!p)
188 return 1;
189
190 if (sscanf(p, "%u:%u", maj, min) != 2)
191 return 1;
192
193 return 0;
194}
195
Shehjar Tikoo67423012008-09-30 10:35:44 +1000196static void find_add_disk_slaves(struct thread_data *td, char *path,
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200197 struct disk_util *masterdu)
Shehjar Tikoo67423012008-09-30 10:35:44 +1000198{
199 DIR *dirhandle = NULL;
200 struct dirent *dirent = NULL;
201 char slavesdir[PATH_MAX], temppath[PATH_MAX], slavepath[PATH_MAX];
202 struct disk_util *slavedu = NULL;
203 int majdev, mindev;
204 ssize_t linklen;
205
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200206 sprintf(slavesdir, "%s/%s", path, "slaves");
Shehjar Tikoo67423012008-09-30 10:35:44 +1000207 dirhandle = opendir(slavesdir);
208 if (!dirhandle)
209 return;
210
211 while ((dirent = readdir(dirhandle)) != NULL) {
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200212 if (!strcmp(dirent->d_name, ".") ||
213 !strcmp(dirent->d_name, ".."))
Shehjar Tikoo67423012008-09-30 10:35:44 +1000214 continue;
215
216 sprintf(temppath, "%s/%s", slavesdir, dirent->d_name);
217 /* Can we always assume that the slaves device entries
218 * are links to the real directories for the slave
219 * devices?
220 */
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200221 linklen = readlink(temppath, slavepath, PATH_MAX - 0);
222 if (linklen < 0) {
Shehjar Tikoo67423012008-09-30 10:35:44 +1000223 perror("readlink() for slave device.");
224 return;
225 }
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200226 slavepath[linklen] = '\0';
Shehjar Tikoo67423012008-09-30 10:35:44 +1000227
228 sprintf(temppath, "%s/%s/dev", slavesdir, slavepath);
229 if (read_block_dev_entry(temppath, &majdev, &mindev)) {
230 perror("Error getting slave device numbers.");
231 return;
232 }
233
Alan D. Brunelleb06de822009-09-11 14:57:10 -0400234 /*
235 * See if this maj,min already exists
236 */
237 slavedu = disk_util_exists(majdev, mindev);
238 if (slavedu)
239 continue;
240
Shehjar Tikoo67423012008-09-30 10:35:44 +1000241 sprintf(temppath, "%s/%s", slavesdir, slavepath);
242 __init_per_file_disk_util(td, majdev, mindev, temppath);
243 slavedu = disk_util_exists(majdev, mindev);
244
245 /* Should probably use an assert here. slavedu should
246 * always be present at this point. */
Jens Axboeb8d541d2010-06-21 12:40:53 +0200247 if (slavedu) {
248 slavedu->users++;
Shehjar Tikoo67423012008-09-30 10:35:44 +1000249 flist_add_tail(&slavedu->slavelist, &masterdu->slaves);
Jens Axboeb8d541d2010-06-21 12:40:53 +0200250 }
Shehjar Tikoo67423012008-09-30 10:35:44 +1000251 }
252
253 closedir(dirhandle);
Shehjar Tikoo67423012008-09-30 10:35:44 +1000254}
255
Jens Axboec97bd0f2009-05-27 13:11:20 +0200256static struct disk_util *disk_util_add(struct thread_data * td, int majdev,
257 int mindev, char *path)
Jens Axboe9f8f2062007-04-02 15:08:01 +0200258{
259 struct disk_util *du, *__du;
Jens Axboe01743ee2008-06-02 12:19:19 +0200260 struct flist_head *entry;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200261
Jens Axboecd991b92008-03-07 13:19:35 +0100262 dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path);
263
Jens Axboec97bd0f2009-05-27 13:11:20 +0200264 du = smalloc(sizeof(*du));
Jens Axboe9f8f2062007-04-02 15:08:01 +0200265 memset(du, 0, sizeof(*du));
Jens Axboe01743ee2008-06-02 12:19:19 +0200266 INIT_FLIST_HEAD(&du->list);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200267 sprintf(du->path, "%s/stat", path);
Jens Axboec97bd0f2009-05-27 13:11:20 +0200268 du->name = smalloc_strdup(basename(path));
Jens Axboee11c4102007-04-03 16:33:04 -0700269 du->sysfs_root = path;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200270 du->major = majdev;
271 du->minor = mindev;
Shehjar Tikoo67423012008-09-30 10:35:44 +1000272 INIT_FLIST_HEAD(&du->slavelist);
273 INIT_FLIST_HEAD(&du->slaves);
Jens Axboec97bd0f2009-05-27 13:11:20 +0200274 du->lock = fio_mutex_init(1);
275 du->users = 0;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200276
Jens Axboe01743ee2008-06-02 12:19:19 +0200277 flist_for_each(entry, &disk_list) {
278 __du = flist_entry(entry, struct disk_util, list);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200279
Jens Axboecd991b92008-03-07 13:19:35 +0100280 dprint(FD_DISKUTIL, "found %s in list\n", __du->name);
281
Jens Axboe9f8f2062007-04-02 15:08:01 +0200282 if (!strcmp(du->name, __du->name)) {
Jens Axboec97bd0f2009-05-27 13:11:20 +0200283 disk_util_free(du);
284 return __du;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200285 }
286 }
287
Jens Axboecd991b92008-03-07 13:19:35 +0100288 dprint(FD_DISKUTIL, "add %s to list\n", du->name);
289
Jens Axboe9f8f2062007-04-02 15:08:01 +0200290 fio_gettime(&du->time, NULL);
291 get_io_ticks(du, &du->last_dus);
292
Jens Axboe01743ee2008-06-02 12:19:19 +0200293 flist_add_tail(&du->list, &disk_list);
Shehjar Tikoo67423012008-09-30 10:35:44 +1000294 find_add_disk_slaves(td, path, du);
Jens Axboec97bd0f2009-05-27 13:11:20 +0200295 return du;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200296}
297
298static int check_dev_match(int majdev, int mindev, char *path)
299{
300 int major, minor;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200301
Shehjar Tikoo67423012008-09-30 10:35:44 +1000302 if (read_block_dev_entry(path, &major, &minor))
Jens Axboe9f8f2062007-04-02 15:08:01 +0200303 return 1;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200304
Jens Axboec97bd0f2009-05-27 13:11:20 +0200305 if (majdev == major && mindev == minor)
Jens Axboe9f8f2062007-04-02 15:08:01 +0200306 return 0;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200307
Jens Axboe9f8f2062007-04-02 15:08:01 +0200308 return 1;
309}
310
Jens Axboeac0be2a2008-06-06 12:08:04 +0200311static int find_block_dir(int majdev, int mindev, char *path, int link_ok)
Jens Axboe9f8f2062007-04-02 15:08:01 +0200312{
313 struct dirent *dir;
314 struct stat st;
315 int found = 0;
316 DIR *D;
317
318 D = opendir(path);
319 if (!D)
320 return 0;
321
322 while ((dir = readdir(D)) != NULL) {
323 char full_path[256];
324
325 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
326 continue;
327
328 sprintf(full_path, "%s/%s", path, dir->d_name);
329
330 if (!strcmp(dir->d_name, "dev")) {
331 if (!check_dev_match(majdev, mindev, full_path)) {
332 found = 1;
333 break;
334 }
335 }
336
Jens Axboeac0be2a2008-06-06 12:08:04 +0200337 if (link_ok) {
338 if (stat(full_path, &st) == -1) {
339 perror("stat");
340 break;
341 }
342 } else {
343 if (lstat(full_path, &st) == -1) {
344 perror("stat");
345 break;
346 }
Jens Axboe9f8f2062007-04-02 15:08:01 +0200347 }
348
349 if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
350 continue;
351
Jens Axboeac0be2a2008-06-06 12:08:04 +0200352 found = find_block_dir(majdev, mindev, full_path, 0);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200353 if (found) {
354 strcpy(path, full_path);
355 break;
356 }
357 }
358
359 closedir(D);
360 return found;
361}
362
Jens Axboec97bd0f2009-05-27 13:11:20 +0200363static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
364 int majdev, int mindev,
365 char *path)
Jens Axboe9f8f2062007-04-02 15:08:01 +0200366{
367 struct stat st;
Shehjar Tikoo67423012008-09-30 10:35:44 +1000368 char tmp[PATH_MAX];
Jens Axboe9f8f2062007-04-02 15:08:01 +0200369 char *p;
370
Shehjar Tikoo67423012008-09-30 10:35:44 +1000371 /*
372 * If there's a ../queue/ directory there, we are inside a partition.
373 * Check if that is the case and jump back. For loop/md/dm etc we
374 * are already in the right spot.
375 */
376 sprintf(tmp, "%s/../queue", path);
377 if (!stat(tmp, &st)) {
378 p = dirname(path);
379 sprintf(tmp, "%s/queue", p);
380 if (stat(tmp, &st)) {
381 log_err("unknown sysfs layout\n");
Jens Axboec97bd0f2009-05-27 13:11:20 +0200382 return NULL;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200383 }
Shehjar Tikoo67423012008-09-30 10:35:44 +1000384 strncpy(tmp, p, PATH_MAX - 1);
385 sprintf(path, "%s", tmp);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200386 }
387
Shehjar Tikoo67423012008-09-30 10:35:44 +1000388 if (td->o.ioscheduler && !td->sysfs_root)
389 td->sysfs_root = strdup(path);
390
Jens Axboec97bd0f2009-05-27 13:11:20 +0200391 return disk_util_add(td, majdev, mindev, path);
Shehjar Tikoo67423012008-09-30 10:35:44 +1000392}
393
Jens Axboec97bd0f2009-05-27 13:11:20 +0200394static struct disk_util *init_per_file_disk_util(struct thread_data *td,
395 char *filename)
Shehjar Tikoo67423012008-09-30 10:35:44 +1000396{
397
398 char foo[PATH_MAX];
399 struct disk_util *du;
400 int mindev, majdev;
401
Jens Axboec97bd0f2009-05-27 13:11:20 +0200402 if (get_device_numbers(filename, &majdev, &mindev))
403 return NULL;
Shehjar Tikoo67423012008-09-30 10:35:44 +1000404
405 dprint(FD_DISKUTIL, "%s belongs to maj/min %d/%d\n", filename, majdev,
406 mindev);
Jens Axboecd991b92008-03-07 13:19:35 +0100407
Jens Axboee11c4102007-04-03 16:33:04 -0700408 du = disk_util_exists(majdev, mindev);
409 if (du) {
410 if (td->o.ioscheduler && !td->sysfs_root)
411 td->sysfs_root = strdup(du->sysfs_root);
412
Jens Axboec97bd0f2009-05-27 13:11:20 +0200413 return du;
Jens Axboee11c4102007-04-03 16:33:04 -0700414 }
Jens Axboe9f8f2062007-04-02 15:08:01 +0200415
416 /*
417 * for an fs without a device, we will repeatedly stat through
418 * sysfs which can take oodles of time for thousands of files. so
419 * cache the last lookup and compare with that before going through
420 * everything again.
421 */
422 if (mindev == last_mindev && majdev == last_majdev)
Jens Axboec97bd0f2009-05-27 13:11:20 +0200423 return last_du;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200424
425 last_mindev = mindev;
426 last_majdev = majdev;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100427
Jens Axboe9f8f2062007-04-02 15:08:01 +0200428 sprintf(foo, "/sys/block");
Jens Axboeac0be2a2008-06-06 12:08:04 +0200429 if (!find_block_dir(majdev, mindev, foo, 1))
Jens Axboec97bd0f2009-05-27 13:11:20 +0200430 return NULL;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200431
Jens Axboec97bd0f2009-05-27 13:11:20 +0200432 return __init_per_file_disk_util(td, majdev, mindev, foo);
Shehjar Tikoo67423012008-09-30 10:35:44 +1000433}
Jens Axboe9f8f2062007-04-02 15:08:01 +0200434
Jens Axboec97bd0f2009-05-27 13:11:20 +0200435static struct disk_util *__init_disk_util(struct thread_data *td,
436 struct fio_file *f)
Shehjar Tikoo67423012008-09-30 10:35:44 +1000437{
438 return init_per_file_disk_util(td, f->file_name);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200439}
440
441void init_disk_util(struct thread_data *td)
442{
443 struct fio_file *f;
444 unsigned int i;
445
446 if (!td->o.do_disk_util ||
447 (td->io_ops->flags & (FIO_DISKLESSIO | FIO_NODISKUTIL)))
448 return;
449
450 for_each_file(td, f, i)
Jens Axboec97bd0f2009-05-27 13:11:20 +0200451 f->du = __init_disk_util(td, f);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200452}
453
Shehjar Tikoo043b74b2008-09-30 11:11:35 +1000454static void aggregate_slaves_stats(struct disk_util *masterdu)
455{
456 struct disk_util_stat *dus;
457 struct flist_head *entry;
458 struct disk_util *slavedu;
459 double util, max_util = 0;
460 int slavecount = 0;
461
Jens Axboe5e28df32008-09-30 08:39:17 +0200462 unsigned merges[2] = { 0, };
463 unsigned ticks[2] = { 0, };
464 unsigned time_in_queue = { 0, };
465 unsigned long long sectors[2] = { 0, };
466 unsigned ios[2] = { 0, };
Shehjar Tikoo043b74b2008-09-30 11:11:35 +1000467
468 flist_for_each(entry, &masterdu->slaves) {
469 slavedu = flist_entry(entry, struct disk_util, slavelist);
470 dus = &slavedu->dus;
471 ios[0] += dus->ios[0];
472 ios[1] += dus->ios[1];
473 merges[0] += dus->merges[0];
474 merges[1] += dus->merges[1];
475 sectors[0] += dus->sectors[0];
476 sectors[1] += dus->sectors[1];
477 ticks[0] += dus->ticks[0];
478 ticks[1] += dus->ticks[1];
479 time_in_queue += dus->time_in_queue;
480 ++slavecount;
481
482 util = (double) (100 * dus->io_ticks / (double) slavedu->msec);
483 /* System utilization is the utilization of the
484 * component with the highest utilization.
485 */
486 if (util > max_util)
487 max_util = util;
488
489 }
490
491 if (max_util > 100.0)
492 max_util = 100.0;
493
494 log_info(", aggrios=%u/%u, aggrmerge=%u/%u, aggrticks=%u/%u,"
495 " aggrin_queue=%u, aggrutil=%3.2f%%",
496 ios[0]/slavecount, ios[1]/slavecount,
497 merges[0]/slavecount, merges[1]/slavecount,
498 ticks[0]/slavecount, ticks[1]/slavecount,
499 time_in_queue/slavecount, max_util);
500
501}
502
Jens Axboe9f8f2062007-04-02 15:08:01 +0200503void show_disk_util(void)
504{
505 struct disk_util_stat *dus;
Jens Axboe01743ee2008-06-02 12:19:19 +0200506 struct flist_head *entry, *next;
Jens Axboe9f8f2062007-04-02 15:08:01 +0200507 struct disk_util *du;
508 double util;
509
Jens Axboe01743ee2008-06-02 12:19:19 +0200510 if (flist_empty(&disk_list))
Jens Axboe0a839f32007-04-26 09:02:34 +0200511 return;
512
Jens Axboe9f8f2062007-04-02 15:08:01 +0200513 log_info("\nDisk stats (read/write):\n");
514
Jens Axboe01743ee2008-06-02 12:19:19 +0200515 flist_for_each(entry, &disk_list) {
516 du = flist_entry(entry, struct disk_util, list);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200517 dus = &du->dus;
518
519 util = (double) 100 * du->dus.io_ticks / (double) du->msec;
520 if (util > 100.0)
521 util = 100.0;
522
Shehjar Tikoo67423012008-09-30 10:35:44 +1000523 /* If this node is the slave of a master device, as
524 * happens in case of software RAIDs, inward-indent
525 * this stats line to reflect a master-slave
526 * relationship. Because the master device gets added
527 * before the slave devices, we can safely assume that
528 * the master's stats line has been displayed in a
529 * previous iteration of this loop.
530 */
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200531 if (!flist_empty(&du->slavelist))
Shehjar Tikoo67423012008-09-30 10:35:44 +1000532 log_info(" ");
533
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100534 log_info(" %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, "
Shehjar Tikoo043b74b2008-09-30 11:11:35 +1000535 "in_queue=%u, util=%3.2f%%", du->name,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100536 dus->ios[0], dus->ios[1],
537 dus->merges[0], dus->merges[1],
538 dus->ticks[0], dus->ticks[1],
539 dus->time_in_queue, util);
Shehjar Tikoo043b74b2008-09-30 11:11:35 +1000540
541 /* If the device has slaves, aggregate the stats for
542 * those slave devices also.
543 */
Jens Axboe2db4ecc2009-09-11 22:22:41 +0200544 if (!flist_empty(&du->slaves))
Shehjar Tikoo043b74b2008-09-30 11:11:35 +1000545 aggregate_slaves_stats(du);
546
547 log_info("\n");
Jens Axboe9f8f2062007-04-02 15:08:01 +0200548 }
549
550 /*
551 * now free the list
552 */
Jens Axboe01743ee2008-06-02 12:19:19 +0200553 flist_for_each_safe(entry, next, &disk_list) {
554 flist_del(entry);
555 du = flist_entry(entry, struct disk_util, list);
Jens Axboec97bd0f2009-05-27 13:11:20 +0200556 disk_util_free(du);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200557 }
558}