blkdev: Refactoring block io latency histogram codes
The current io_latency_state structure includes entries for read and write requests. There are special types of write commands such as sync and discard (trim) commands, and the current implementation is not general enough if we want to separate latency histogram for such special commands. This change makes io_latency_state structure request-type neutral. It also changes to print the latency average. Signed-off-by: Hyojun Kim <hyojun@google.com>
This commit is contained in:
parent
52c02cf1b2
commit
d96d95dd1d
6 changed files with 74 additions and 107 deletions
|
@ -3574,76 +3574,43 @@ int __init blk_dev_init(void)
|
|||
* TODO : If necessary, we can make the histograms per-cpu and aggregate
|
||||
* them when printing them out.
|
||||
*/
|
||||
void
|
||||
blk_zero_latency_hist(struct io_latency_state *s)
|
||||
{
|
||||
memset(s->latency_y_axis_read, 0,
|
||||
sizeof(s->latency_y_axis_read));
|
||||
memset(s->latency_y_axis_write, 0,
|
||||
sizeof(s->latency_y_axis_write));
|
||||
s->latency_reads_elems = 0;
|
||||
s->latency_writes_elems = 0;
|
||||
}
|
||||
EXPORT_SYMBOL(blk_zero_latency_hist);
|
||||
|
||||
ssize_t
|
||||
blk_latency_hist_show(struct io_latency_state *s, char *buf)
|
||||
blk_latency_hist_show(char* name, struct io_latency_state *s, char *buf,
|
||||
int buf_size)
|
||||
{
|
||||
int i;
|
||||
int bytes_written = 0;
|
||||
u_int64_t num_elem, elem;
|
||||
int pct;
|
||||
u_int64_t average;
|
||||
|
||||
num_elem = s->latency_reads_elems;
|
||||
if (num_elem > 0) {
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"IO svc_time Read Latency Histogram (n = %llu):\n",
|
||||
num_elem);
|
||||
for (i = 0;
|
||||
i < ARRAY_SIZE(latency_x_axis_us);
|
||||
i++) {
|
||||
elem = s->latency_y_axis_read[i];
|
||||
pct = div64_u64(elem * 100, num_elem);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"\t< %5lluus%15llu%15d%%\n",
|
||||
latency_x_axis_us[i],
|
||||
elem, pct);
|
||||
}
|
||||
/* Last element in y-axis table is overflow */
|
||||
elem = s->latency_y_axis_read[i];
|
||||
pct = div64_u64(elem * 100, num_elem);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"\t> %5dms%15llu%15d%%\n", 10,
|
||||
elem, pct);
|
||||
}
|
||||
num_elem = s->latency_writes_elems;
|
||||
if (num_elem > 0) {
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"IO svc_time Write Latency Histogram (n = %llu):\n",
|
||||
num_elem);
|
||||
for (i = 0;
|
||||
i < ARRAY_SIZE(latency_x_axis_us);
|
||||
i++) {
|
||||
elem = s->latency_y_axis_write[i];
|
||||
pct = div64_u64(elem * 100, num_elem);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"\t< %5lluus%15llu%15d%%\n",
|
||||
latency_x_axis_us[i],
|
||||
elem, pct);
|
||||
}
|
||||
/* Last element in y-axis table is overflow */
|
||||
elem = s->latency_y_axis_write[i];
|
||||
pct = div64_u64(elem * 100, num_elem);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"\t> %5dms%15llu%15d%%\n", 10,
|
||||
elem, pct);
|
||||
num_elem = s->latency_elems;
|
||||
if (num_elem > 0) {
|
||||
average = div64_u64(s->latency_sum, s->latency_elems);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
buf_size - bytes_written,
|
||||
"IO svc_time %s Latency Histogram (n = %llu,"
|
||||
" average = %llu):\n", name, num_elem, average);
|
||||
for (i = 0;
|
||||
i < ARRAY_SIZE(latency_x_axis_us);
|
||||
i++) {
|
||||
elem = s->latency_y_axis[i];
|
||||
pct = div64_u64(elem * 100, num_elem);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"\t< %6lluus%15llu%15d%%\n",
|
||||
latency_x_axis_us[i],
|
||||
elem, pct);
|
||||
}
|
||||
/* Last element in y-axis table is overflow */
|
||||
elem = s->latency_y_axis[i];
|
||||
pct = div64_u64(elem * 100, num_elem);
|
||||
bytes_written += scnprintf(buf + bytes_written,
|
||||
PAGE_SIZE - bytes_written,
|
||||
"\t>=%6lluus%15llu%15d%%\n",
|
||||
latency_x_axis_us[i - 1], elem, pct);
|
||||
}
|
||||
|
||||
return bytes_written;
|
||||
}
|
||||
EXPORT_SYMBOL(blk_latency_hist_show);
|
||||
|
|
|
@ -191,9 +191,10 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
|
|||
completion = ktime_get();
|
||||
delta_us = ktime_us_delta(completion,
|
||||
mrq->io_start);
|
||||
blk_update_latency_hist(&host->io_lat_s,
|
||||
(mrq->data->flags & MMC_DATA_READ),
|
||||
delta_us);
|
||||
blk_update_latency_hist(
|
||||
(mrq->data->flags & MMC_DATA_READ) ?
|
||||
&host->io_lat_read :
|
||||
&host->io_lat_write, delta_us);
|
||||
}
|
||||
#endif
|
||||
trace_mmc_blk_rw_end(cmd->opcode, cmd->arg, mrq->data);
|
||||
|
@ -2932,8 +2933,14 @@ static ssize_t
|
|||
latency_hist_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
||||
size_t written_bytes;
|
||||
|
||||
return blk_latency_hist_show(&host->io_lat_s, buf);
|
||||
written_bytes = blk_latency_hist_show("Read", &host->io_lat_read,
|
||||
buf, PAGE_SIZE);
|
||||
written_bytes += blk_latency_hist_show("Write", &host->io_lat_write,
|
||||
buf + written_bytes, PAGE_SIZE - written_bytes);
|
||||
|
||||
return written_bytes;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2951,9 +2958,10 @@ latency_hist_store(struct device *dev, struct device_attribute *attr,
|
|||
|
||||
if (kstrtol(buf, 0, &value))
|
||||
return -EINVAL;
|
||||
if (value == BLK_IO_LAT_HIST_ZERO)
|
||||
blk_zero_latency_hist(&host->io_lat_s);
|
||||
else if (value == BLK_IO_LAT_HIST_ENABLE ||
|
||||
if (value == BLK_IO_LAT_HIST_ZERO) {
|
||||
memset(&host->io_lat_read, 0, sizeof(host->io_lat_read));
|
||||
memset(&host->io_lat_write, 0, sizeof(host->io_lat_write));
|
||||
} else if (value == BLK_IO_LAT_HIST_ENABLE ||
|
||||
value == BLK_IO_LAT_HIST_DISABLE)
|
||||
host->latency_hist_enabled = value;
|
||||
return count;
|
||||
|
|
|
@ -3207,10 +3207,10 @@ static void ufshcd_transfer_req_compl(struct ufs_hba *hba)
|
|||
completion = ktime_get();
|
||||
delta_us = ktime_us_delta(completion,
|
||||
req->lat_hist_io_start);
|
||||
/* rq_data_dir() => true if WRITE */
|
||||
blk_update_latency_hist(&hba->io_lat_s,
|
||||
(rq_data_dir(req) == READ),
|
||||
delta_us);
|
||||
blk_update_latency_hist(
|
||||
(rq_data_dir(req) == READ) ?
|
||||
&hba->io_lat_read :
|
||||
&hba->io_lat_write, delta_us);
|
||||
}
|
||||
}
|
||||
/* Do not touch lrbp after scsi done */
|
||||
|
@ -5382,9 +5382,10 @@ latency_hist_store(struct device *dev, struct device_attribute *attr,
|
|||
|
||||
if (kstrtol(buf, 0, &value))
|
||||
return -EINVAL;
|
||||
if (value == BLK_IO_LAT_HIST_ZERO)
|
||||
blk_zero_latency_hist(&hba->io_lat_s);
|
||||
else if (value == BLK_IO_LAT_HIST_ENABLE ||
|
||||
if (value == BLK_IO_LAT_HIST_ZERO) {
|
||||
memset(&hba->io_lat_read, 0, sizeof(hba->io_lat_read));
|
||||
memset(&hba->io_lat_write, 0, sizeof(hba->io_lat_write));
|
||||
} else if (value == BLK_IO_LAT_HIST_ENABLE ||
|
||||
value == BLK_IO_LAT_HIST_DISABLE)
|
||||
hba->latency_hist_enabled = value;
|
||||
return count;
|
||||
|
@ -5395,8 +5396,14 @@ latency_hist_show(struct device *dev, struct device_attribute *attr,
|
|||
char *buf)
|
||||
{
|
||||
struct ufs_hba *hba = dev_get_drvdata(dev);
|
||||
size_t written_bytes;
|
||||
|
||||
return blk_latency_hist_show(&hba->io_lat_s, buf);
|
||||
written_bytes = blk_latency_hist_show("Read", &hba->io_lat_read,
|
||||
buf, PAGE_SIZE);
|
||||
written_bytes += blk_latency_hist_show("Write", &hba->io_lat_write,
|
||||
buf + written_bytes, PAGE_SIZE - written_bytes);
|
||||
|
||||
return written_bytes;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(latency_hist, S_IRUGO | S_IWUSR,
|
||||
|
|
|
@ -542,7 +542,8 @@ struct ufs_hba {
|
|||
bool is_sys_suspended;
|
||||
|
||||
int latency_hist_enabled;
|
||||
struct io_latency_state io_lat_s;
|
||||
struct io_latency_state io_lat_read;
|
||||
struct io_latency_state io_lat_write;
|
||||
};
|
||||
|
||||
/* Returns true if clocks can be gated. Otherwise false */
|
||||
|
|
|
@ -1694,43 +1694,26 @@ static const u_int64_t latency_x_axis_us[] = {
|
|||
#define BLK_IO_LAT_HIST_ZERO 2
|
||||
|
||||
struct io_latency_state {
|
||||
u_int64_t latency_y_axis_read[ARRAY_SIZE(latency_x_axis_us) + 1];
|
||||
u_int64_t latency_reads_elems;
|
||||
u_int64_t latency_y_axis_write[ARRAY_SIZE(latency_x_axis_us) + 1];
|
||||
u_int64_t latency_writes_elems;
|
||||
u_int64_t latency_y_axis[ARRAY_SIZE(latency_x_axis_us) + 1];
|
||||
u_int64_t latency_elems;
|
||||
u_int64_t latency_sum;
|
||||
};
|
||||
|
||||
static inline void
|
||||
blk_update_latency_hist(struct io_latency_state *s,
|
||||
int read,
|
||||
u_int64_t delta_us)
|
||||
blk_update_latency_hist(struct io_latency_state *s, u_int64_t delta_us)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(latency_x_axis_us); i++) {
|
||||
if (delta_us < (u_int64_t)latency_x_axis_us[i]) {
|
||||
if (read)
|
||||
s->latency_y_axis_read[i]++;
|
||||
else
|
||||
s->latency_y_axis_write[i]++;
|
||||
for (i = 0; i < ARRAY_SIZE(latency_x_axis_us); i++)
|
||||
if (delta_us < (u_int64_t)latency_x_axis_us[i])
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == ARRAY_SIZE(latency_x_axis_us)) {
|
||||
/* Overflowed the histogram */
|
||||
if (read)
|
||||
s->latency_y_axis_read[i]++;
|
||||
else
|
||||
s->latency_y_axis_write[i]++;
|
||||
}
|
||||
if (read)
|
||||
s->latency_reads_elems++;
|
||||
else
|
||||
s->latency_writes_elems++;
|
||||
s->latency_y_axis[i]++;
|
||||
s->latency_elems++;
|
||||
s->latency_sum += delta_us;
|
||||
}
|
||||
|
||||
void blk_zero_latency_hist(struct io_latency_state *s);
|
||||
ssize_t blk_latency_hist_show(struct io_latency_state *s, char *buf);
|
||||
ssize_t blk_latency_hist_show(char* name, struct io_latency_state *s,
|
||||
char *buf, int buf_size);
|
||||
|
||||
#else /* CONFIG_BLOCK */
|
||||
|
||||
|
|
|
@ -382,7 +382,8 @@ struct mmc_host {
|
|||
|
||||
#ifdef CONFIG_BLOCK
|
||||
int latency_hist_enabled;
|
||||
struct io_latency_state io_lat_s;
|
||||
struct io_latency_state io_lat_read;
|
||||
struct io_latency_state io_lat_write;
|
||||
#endif
|
||||
|
||||
unsigned long private[0] ____cacheline_aligned;
|
||||
|
|
Loading…
Add table
Reference in a new issue