X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=diskutil.c;h=3168b59d3b73dbf9e92d6d75963c49e7fa1f20e2;hp=3cbd6fc3b04e1d2f7dba60375dcf1c5d65683583;hb=3d7cd9b4c2570548bebfae4871c3ca068c5a29fe;hpb=17127517a3ccff19993e36ec3f7bc15044898f2c diff --git a/diskutil.c b/diskutil.c index 3cbd6fc3..3168b59d 100644 --- a/diskutil.c +++ b/diskutil.c @@ -9,25 +9,37 @@ #include "fio.h" #include "smalloc.h" +#include "diskutil.h" static int last_majdev, last_mindev; static struct disk_util *last_du; -static struct flist_head disk_list = FLIST_HEAD_INIT(disk_list); +FLIST_HEAD(disk_list); + +static struct disk_util *__init_per_file_disk_util(struct thread_data *td, + int majdev, int mindev, char *path); static void disk_util_free(struct disk_util *du) { if (du == last_du) last_du = NULL; + while (!flist_empty(&du->slaves)) { + struct disk_util *slave; + + slave = flist_entry(du->slaves.next, struct disk_util, slavelist); + flist_del(&slave->slavelist); + slave->users--; + } + fio_mutex_remove(du->lock); - sfree(du->name); sfree(du); } static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) { unsigned in_flight; + unsigned long long sectors[2]; char line[256]; FILE *f; char *p; @@ -48,13 +60,15 @@ static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) dprint(FD_DISKUTIL, "%s: %s", du->path, p); ret = sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0], - &dus->merges[0], &dus->sectors[0], + &dus->merges[0], §ors[0], &dus->ticks[0], &dus->ios[1], - &dus->merges[1], &dus->sectors[1], + &dus->merges[1], §ors[1], &dus->ticks[1], &in_flight, &dus->io_ticks, &dus->time_in_queue); fclose(f); dprint(FD_DISKUTIL, "%s: stat read ok? %d\n", du->path, ret == 1); + dus->sectors[0] = sectors[0]; + dus->sectors[1] = sectors[1]; return ret != 11; } @@ -63,10 +77,10 @@ static void update_io_tick_disk(struct disk_util *du) struct disk_util_stat __dus, *dus, *ldus; struct timeval t; - if (get_io_ticks(du, &__dus)) - return; if (!du->users) return; + if (get_io_ticks(du, &__dus)) + return; dus = &du->dus; ldus = &du->last_dus; @@ -83,7 +97,7 @@ static void update_io_tick_disk(struct disk_util *du) dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue); fio_gettime(&t, NULL); - du->msec += mtime_since(&du->time, &t); + dus->msec += mtime_since(&du->time, &t); memcpy(&du->time, &t, sizeof(t)); memcpy(ldus, &__dus, sizeof(__dus)); } @@ -181,11 +195,8 @@ static int read_block_dev_entry(char *path, int *maj, int *min) return 0; } -static struct disk_util *__init_per_file_disk_util(struct thread_data *td, - int majdev, int mindev, char * path); - static void find_add_disk_slaves(struct thread_data *td, char *path, - struct disk_util *masterdu) + struct disk_util *masterdu) { DIR *dirhandle = NULL; struct dirent *dirent = NULL; @@ -194,13 +205,14 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, int majdev, mindev; ssize_t linklen; - sprintf(slavesdir, "%s/%s",path, "slaves"); + sprintf(slavesdir, "%s/%s", path, "slaves"); dirhandle = opendir(slavesdir); if (!dirhandle) return; while ((dirent = readdir(dirhandle)) != NULL) { - if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) + if (!strcmp(dirent->d_name, ".") || + !strcmp(dirent->d_name, "..")) continue; sprintf(temppath, "%s/%s", slavesdir, dirent->d_name); @@ -208,11 +220,12 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, * are links to the real directories for the slave * devices? */ - if ((linklen = readlink(temppath, slavepath, PATH_MAX-1)) < 0) { + linklen = readlink(temppath, slavepath, PATH_MAX - 0); + if (linklen < 0) { perror("readlink() for slave device."); return; } - slavepath[linklen]='\0'; + slavepath[linklen] = '\0'; sprintf(temppath, "%s/%s/dev", slavesdir, slavepath); if (read_block_dev_entry(temppath, &majdev, &mindev)) { @@ -220,21 +233,29 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, return; } + /* + * See if this maj,min already exists + */ + slavedu = disk_util_exists(majdev, mindev); + if (slavedu) + continue; + sprintf(temppath, "%s/%s", slavesdir, slavepath); __init_per_file_disk_util(td, majdev, mindev, temppath); slavedu = disk_util_exists(majdev, mindev); /* Should probably use an assert here. slavedu should * always be present at this point. */ - if (slavedu) + if (slavedu) { + slavedu->users++; flist_add_tail(&slavedu->slavelist, &masterdu->slaves); + } } closedir(dirhandle); - return; } -static struct disk_util *disk_util_add(struct thread_data * td, int majdev, +static struct disk_util *disk_util_add(struct thread_data *td, int majdev, int mindev, char *path) { struct disk_util *du, *__du; @@ -246,7 +267,7 @@ static struct disk_util *disk_util_add(struct thread_data * td, int majdev, memset(du, 0, sizeof(*du)); INIT_FLIST_HEAD(&du->list); sprintf(du->path, "%s/stat", path); - du->name = smalloc_strdup(basename(path)); + strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ); du->sysfs_root = path; du->major = majdev; du->minor = mindev; @@ -258,15 +279,15 @@ static struct disk_util *disk_util_add(struct thread_data * td, int majdev, flist_for_each(entry, &disk_list) { __du = flist_entry(entry, struct disk_util, list); - dprint(FD_DISKUTIL, "found %s in list\n", __du->name); + dprint(FD_DISKUTIL, "found %s in list\n", __du->dus.name); - if (!strcmp(du->name, __du->name)) { + if (!strcmp((char *) du->dus.name, (char *) __du->dus.name)) { disk_util_free(du); return __du; } } - dprint(FD_DISKUTIL, "add %s to list\n", du->name); + dprint(FD_DISKUTIL, "add %s to list\n", du->dus.name); fio_gettime(&du->time, NULL); get_io_ticks(du, &du->last_dus); @@ -276,7 +297,6 @@ static struct disk_util *disk_util_add(struct thread_data * td, int majdev, return du; } - static int check_dev_match(int majdev, int mindev, char *path) { int major, minor; @@ -433,108 +453,136 @@ void init_disk_util(struct thread_data *td) f->du = __init_disk_util(td, f); } +static void show_agg_stats(struct disk_util_agg *agg, int terse) +{ + if (!agg->slavecount) + return; + + if (!terse) { + log_info(", aggrios=%u/%u, aggrmerge=%u/%u, aggrticks=%u/%u," + " aggrin_queue=%u, aggrutil=%3.2f%%", + agg->ios[0] / agg->slavecount, + agg->ios[1] / agg->slavecount, + agg->merges[0] / agg->slavecount, + agg->merges[1] / agg->slavecount, + agg->ticks[0] / agg->slavecount, + agg->ticks[1] / agg->slavecount, + agg->time_in_queue / agg->slavecount, + agg->max_util.u.f); + } else { + log_info("slaves;%u;%u;%u;%u;%u;%u;%u;%3.2f%%", + agg->ios[0] / agg->slavecount, + agg->ios[1] / agg->slavecount, + agg->merges[0] / agg->slavecount, + agg->merges[1] / agg->slavecount, + agg->ticks[0] / agg->slavecount, + agg->ticks[1] / agg->slavecount, + agg->time_in_queue / agg->slavecount, + agg->max_util.u.f); + } +} + static void aggregate_slaves_stats(struct disk_util *masterdu) { + struct disk_util_agg *agg = &masterdu->agg; struct disk_util_stat *dus; struct flist_head *entry; struct disk_util *slavedu; - double util, max_util = 0; - int slavecount = 0; - - unsigned merges[2] = { 0, }; - unsigned ticks[2] = { 0, }; - unsigned time_in_queue = { 0, }; - unsigned long long sectors[2] = { 0, }; - unsigned ios[2] = { 0, }; + double util; flist_for_each(entry, &masterdu->slaves) { slavedu = flist_entry(entry, struct disk_util, slavelist); dus = &slavedu->dus; - ios[0] += dus->ios[0]; - ios[1] += dus->ios[1]; - merges[0] += dus->merges[0]; - merges[1] += dus->merges[1]; - sectors[0] += dus->sectors[0]; - sectors[1] += dus->sectors[1]; - ticks[0] += dus->ticks[0]; - ticks[1] += dus->ticks[1]; - time_in_queue += dus->time_in_queue; - ++slavecount; - - util = (double) (100 * dus->io_ticks / (double) slavedu->msec); + agg->ios[0] += dus->ios[0]; + agg->ios[1] += dus->ios[1]; + agg->merges[0] += dus->merges[0]; + agg->merges[1] += dus->merges[1]; + agg->sectors[0] += dus->sectors[0]; + agg->sectors[1] += dus->sectors[1]; + agg->ticks[0] += dus->ticks[0]; + agg->ticks[1] += dus->ticks[1]; + agg->time_in_queue += dus->time_in_queue; + agg->slavecount++; + + util = (double) (100 * dus->io_ticks / (double) slavedu->dus.msec); /* System utilization is the utilization of the * component with the highest utilization. */ - if (util > max_util) - max_util = util; + if (util > agg->max_util.u.f) + agg->max_util.u.f = util; } - if (max_util > 100.0) - max_util = 100.0; + if (agg->max_util.u.f > 100.0) + agg->max_util.u.f = 100.0; +} - log_info(", aggrios=%u/%u, aggrmerge=%u/%u, aggrticks=%u/%u," - " aggrin_queue=%u, aggrutil=%3.2f%%", - ios[0]/slavecount, ios[1]/slavecount, - merges[0]/slavecount, merges[1]/slavecount, - ticks[0]/slavecount, ticks[1]/slavecount, - time_in_queue/slavecount, max_util); +void free_disk_util(void) +{ + struct disk_util *du; + while (!flist_empty(&disk_list)) { + du = flist_entry(disk_list.next, struct disk_util, list); + flist_del(&du->list); + disk_util_free(du); + } + + last_majdev = last_mindev = -1; } -void show_disk_util(void) +void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg, + int terse) { - struct disk_util_stat *dus; - struct flist_head *entry, *next; - struct disk_util *du; double util; - if (flist_empty(&disk_list)) - return; + util = (double) 100 * dus->io_ticks / (double) dus->msec; + if (util > 100.0) + util = 100.0; - log_info("\nDisk stats (read/write):\n"); - - flist_for_each(entry, &disk_list) { - du = flist_entry(entry, struct disk_util, list); - dus = &du->dus; - - util = (double) 100 * du->dus.io_ticks / (double) du->msec; - if (util > 100.0) - util = 100.0; - - /* If this node is the slave of a master device, as - * happens in case of software RAIDs, inward-indent - * this stats line to reflect a master-slave - * relationship. Because the master device gets added - * before the slave devices, we can safely assume that - * the master's stats line has been displayed in a - * previous iteration of this loop. - */ - if(!flist_empty(&du->slavelist)) - log_info(" "); + if (agg->slavecount) + log_info(" "); + if (!terse) { log_info(" %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, " - "in_queue=%u, util=%3.2f%%", du->name, - dus->ios[0], dus->ios[1], - dus->merges[0], dus->merges[1], - dus->ticks[0], dus->ticks[1], - dus->time_in_queue, util); - - /* If the device has slaves, aggregate the stats for - * those slave devices also. - */ - if(!flist_empty(&du->slaves)) - aggregate_slaves_stats(du); - - log_info("\n"); + "in_queue=%u, util=%3.2f%%", dus->name, + dus->ios[0], dus->ios[1], + dus->merges[0], dus->merges[1], + dus->ticks[0], dus->ticks[1], + dus->time_in_queue, util); + } else { + log_info(";%s;%u;%u;%u;%u;%u;%u;%u;%3.2f%%", + dus->name, dus->ios[0], dus->ios[1], + dus->merges[0], dus->merges[1], + dus->ticks[0], dus->ticks[1], + dus->time_in_queue, util); } /* - * now free the list + * If the device has slaves, aggregate the stats for + * those slave devices also. */ - flist_for_each_safe(entry, next, &disk_list) { - flist_del(entry); + if (agg->slavecount) + show_agg_stats(agg, terse); + + if (!terse) + log_info("\n"); +} + +void show_disk_util(int terse) +{ + struct flist_head *entry; + struct disk_util *du; + + if (flist_empty(&disk_list)) + return; + + if (!terse) + log_info("\nDisk stats (read/write):\n"); + + flist_for_each(entry, &disk_list) { du = flist_entry(entry, struct disk_util, list); - disk_util_free(du); + + aggregate_slaves_stats(du); + print_disk_util(&du->dus, &du->agg, terse); } }