加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0015-blkparse-Initialize-and-test-for-undefined-request-t.patch 4.67 KB
一键复制 编辑 原始数据 按行查看 历史
From ea086768766f3bf56eec789ba160c90e99a3e622 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruenba@redhat.com>
Date: Mon, 13 Apr 2020 21:01:51 +0200
Subject: [PATCH 15/15] blkparse: Initialize and test for undefined request
tracking timestamps
Currently, event tracking timestamps aren't initialized at all even though some
places in the code assume that a value of 0 indicates 'undefined'. However, 0
is the timestamp of the first event, so use -1ULL for 'undefined' instead.
In addition, make sure timestamps are only initialized once, and always check
if timestamps are defined before using them.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
blkparse.c | 46 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/blkparse.c b/blkparse.c
index 2d89bc5..5b3f83a 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
@@ -306,6 +307,21 @@ static int have_drv_data = 0;
#define CPU_IDX(cpu) ((cpu) / CPUS_PER_LONG)
#define CPU_BIT(cpu) ((cpu) & (CPUS_PER_LONG - 1))
+static void io_warn_unless(struct blk_io_trace *t, int condition,
+ const char *fmt, ...)
+{
+ va_list ap;
+
+ if (condition)
+ return;
+ va_start(ap, fmt);
+ printf("(%d,%d) request %llu + %u: ",
+ MAJOR(t->device), MINOR(t->device),
+ t->sector, t->bytes);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+}
+
static void output_binary(void *buf, int len)
{
if (dump_binary) {
@@ -968,6 +984,10 @@ static struct io_track *find_track(struct per_dev_info *pdi, pid_t pid,
if (!iot->ppm)
iot->ppm = add_ppm_hash(pid, "unknown");
iot->sector = sector;
+ iot->allocation_time = -1ULL;
+ iot->queue_time = -1ULL;
+ iot->dispatch_time = -1ULL;
+ iot->completion_time = -1ULL;
track_rb_insert(pdi, iot);
}
@@ -1004,6 +1024,8 @@ static void log_track_getrq(struct per_dev_info *pdi, struct blk_io_trace *t)
return;
iot = find_track(pdi, t->pid, t->sector);
+ io_warn_unless(t, iot->allocation_time == -1ULL,
+ "confused about %s time", "allocation");
iot->allocation_time = t->time;
}
@@ -1019,6 +1041,8 @@ static void log_track_queue(struct per_dev_info *pdi, struct blk_io_trace *t)
return;
iot = find_track(pdi, t->pid, t->sector);
+ io_warn_unless(t, iot->dispatch_time == -1ULL,
+ "confused about %s time", "dispatch");
iot->dispatch_time = t->time;
}
@@ -1035,9 +1059,11 @@ static unsigned long long log_track_insert(struct per_dev_info *pdi,
return -1;
iot = find_track(pdi, t->pid, t->sector);
+ io_warn_unless(t, iot->queue_time == -1ULL,
+ "confused about %s time", "queue");
iot->queue_time = t->time;
- if (!iot->allocation_time)
+ if (iot->allocation_time == -1ULL)
return -1;
elapsed = iot->queue_time - iot->allocation_time;
@@ -1059,7 +1085,7 @@ static unsigned long long log_track_insert(struct per_dev_info *pdi,
static unsigned long long log_track_issue(struct per_dev_info *pdi,
struct blk_io_trace *t)
{
- unsigned long long elapsed;
+ unsigned long long elapsed = -1ULL;
struct io_track *iot;
if (!track_ios)
@@ -1076,10 +1102,13 @@ static unsigned long long log_track_issue(struct per_dev_info *pdi,
return -1;
}
+ io_warn_unless(t, iot->dispatch_time == -1ULL,
+ "confused about %s time", "dispatch");
iot->dispatch_time = t->time;
- elapsed = iot->dispatch_time - iot->queue_time;
+ if (iot->queue_time != -1ULL)
+ elapsed = iot->dispatch_time - iot->queue_time;
- if (per_process_stats) {
+ if (elapsed != -1ULL && per_process_stats) {
struct per_process_info *ppi = find_ppi(iot->ppm->pid);
int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
@@ -1096,7 +1125,7 @@ static unsigned long long log_track_issue(struct per_dev_info *pdi,
static unsigned long long log_track_complete(struct per_dev_info *pdi,
struct blk_io_trace *t)
{
- unsigned long long elapsed;
+ unsigned long long elapsed = -1ULL;
struct io_track *iot;
if (!track_ios)
@@ -1111,10 +1140,13 @@ static unsigned long long log_track_complete(struct per_dev_info *pdi,
return -1;
}
+ io_warn_unless(t, iot->completion_time == -1ULL,
+ "confused about %s time", "completion");
iot->completion_time = t->time;
- elapsed = iot->completion_time - iot->dispatch_time;
+ if (iot->dispatch_time != -1ULL)
+ elapsed = iot->completion_time - iot->dispatch_time;
- if (per_process_stats) {
+ if (elapsed != -1ULL && per_process_stats) {
struct per_process_info *ppi = find_ppi(iot->ppm->pid);
int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化