!20 blktrace: backport upstream bugfix patches

Merge pull request !20 from liuzhiqiang/master
This commit is contained in:
openeuler-ci-bot 2020-07-14 09:08:55 +08:00 committed by Gitee
commit 3f2910d652
17 changed files with 1013 additions and 102 deletions

View File

@ -0,0 +1,67 @@
From 9967365e47e90511b89d2f20bb1d5c91c31cc610 Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Sun, 5 Nov 2017 08:52:21 -0700
Subject: [PATCH 01/15] jhash: fix annoying gcc fall through warnings
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
jhash.h | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/jhash.h b/jhash.h
index 4cebd23..a4d3106 100644
--- a/jhash.h
+++ b/jhash.h
@@ -73,22 +73,21 @@ static inline u32 jhash(const void *key, u32 length, u32 initval)
k += 12;
}
- /* last block: affect all 32 bits of (c) */
- /* all the case statements fall through */
+ /* Last block: affect all 32 bits of (c) */
switch (length) {
- case 12: c += (u32)k[11]<<24;
- case 11: c += (u32)k[10]<<16;
- case 10: c += (u32)k[9]<<8;
- case 9 : c += k[8];
- case 8 : b += (u32)k[7]<<24;
- case 7 : b += (u32)k[6]<<16;
- case 6 : b += (u32)k[5]<<8;
- case 5 : b += k[4];
- case 4 : a += (u32)k[3]<<24;
- case 3 : a += (u32)k[2]<<16;
- case 2 : a += (u32)k[1]<<8;
- case 1 : a += k[0];
- __jhash_final(a, b, c);
+ case 12: c += (u32)k[11]<<24; /* fall through */
+ case 11: c += (u32)k[10]<<16; /* fall through */
+ case 10: c += (u32)k[9]<<8; /* fall through */
+ case 9: c += k[8]; /* fall through */
+ case 8: b += (u32)k[7]<<24; /* fall through */
+ case 7: b += (u32)k[6]<<16; /* fall through */
+ case 6: b += (u32)k[5]<<8; /* fall through */
+ case 5: b += k[4]; /* fall through */
+ case 4: a += (u32)k[3]<<24; /* fall through */
+ case 3: a += (u32)k[2]<<16; /* fall through */
+ case 2: a += (u32)k[1]<<8; /* fall through */
+ case 1: a += k[0];
+ __jhash_final(a, b, c);
case 0 :
break;
}
@@ -117,10 +116,9 @@ static inline u32 jhash2(u32 *k, u32 length, u32 initval)
}
/* handle the last 3 u32's */
- /* all the case statements fall through */
switch (length) {
- case 3: c += k[2];
- case 2: b += k[1];
+ case 3: c += k[2]; /* fall through */
+ case 2: b += k[1]; /* fall through */
case 1: a += k[0];
__jhash_final(a, b, c);
case 0: /* case 0: nothing left to add */
--
1.8.3.1

View File

@ -0,0 +1,26 @@
From 84a054951222f902a07bf77dfee0d80c83ee9c6a Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Sun, 5 Nov 2017 08:54:41 -0700
Subject: [PATCH 02/15] btt/devs: silence warning on sprintf overflow
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
btt/devs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/btt/devs.c b/btt/devs.c
index ccaae87..12ce2ca 100644
--- a/btt/devs.c
+++ b/btt/devs.c
@@ -108,7 +108,7 @@ void dip_exit(void)
static inline FILE *open_pit(struct d_info *dip)
{
FILE *fp;
- char str[256];
+ char str[272];
sprintf(str, "%s_pit.dat", dip->dip_name);
if ((fp = my_fopen(str, "w")) == NULL)
--
1.8.3.1

View File

@ -1,89 +0,0 @@
From 007e3250a86bfaf78c3729197cc2add76de4aacc Mon Sep 17 00:00:00 2001
From: eulerstorage <eulerstorage@huawei.com>
Date: Wed, 18 Mar 2020 20:37:33 +0800
Subject: [PATCH] 45
---
btt/bno_plot.py | 14 +++++++-------
btt/btt_plot.py | 6 +++---
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/btt/bno_plot.py b/btt/bno_plot.py
index aa92480..3506f33 100644
--- a/btt/bno_plot.py
+++ b/btt/bno_plot.py
@@ -60,14 +60,14 @@ def parse_args(in_args):
try:
(opts, args) = getopt.getopt(in_args, s_opts, l_opts)
- except getopt.error, msg:
+ except getopt.error as msg:
print >>sys.stderr, msg
print >>sys.stderr, __doc__
sys.exit(1)
for (o, a) in opts:
if o in ('-h', '--help'):
- print __doc__
+ print (__doc__)
sys.exit(0)
elif o in ('-v', '--verbose'):
verbose += 1
@@ -84,10 +84,10 @@ if __name__ == '__main__':
(bnos, keys_below) = parse_args(sys.argv[1:])
if verbose:
- print 'Using files:',
- for bno in bnos: print bno,
- if keys_below: print '\nKeys are to be placed below graph'
- else: print ''
+ print ('Using files:'),
+ for bno in bnos: print (bno),
+ if keys_below: print ('\nKeys are to be placed below graph')
+ else: print ('')
tmpdir = tempfile.mktemp()
os.mkdir(tmpdir)
@@ -116,7 +116,7 @@ if __name__ == '__main__':
if pid == 0:
cmd = 'gnuplot %s/plot.cmds -' % tmpdir
- if verbose: print 'Executing %s' % cmd
+ if verbose: print ('Executing %s' % cmd)
os.chdir(tmpdir)
os.system(cmd)
diff --git a/btt/btt_plot.py b/btt/btt_plot.py
index b81dad5..79bdfad 100755
--- a/btt/btt_plot.py
+++ b/btt/btt_plot.py
@@ -163,7 +163,7 @@ def get_data(files):
if not os.path.exists(file):
fatal('%s not found' % file)
elif verbose:
- print 'Processing %s' % file
+ print ('Processing %s' % file)
xs = []
ys = []
@@ -214,7 +214,7 @@ def parse_args(args):
try:
(opts, args) = getopt.getopt(args[1:], s_opts, l_opts)
- except getopt.error, msg:
+ except getopt.error as msg:
print >>sys.stderr, msg
fatal(__doc__)
@@ -314,7 +314,7 @@ def generate_output(type, db):
ofile = '%s.png' % type
if verbose:
- print 'Generating plot into %s' % ofile
+ print ('Generating plot into %s' % ofile)
fig = plt.figure(figsize=plot_size)
ax = fig.add_subplot(111)
--
1.8.3.1

View File

@ -0,0 +1,66 @@
From 4ad65be104d69a100354897e0f04602b4a68461d Mon Sep 17 00:00:00 2001
From: Gwendal Grignou <gwendal@chromium.org>
Date: Fri, 18 Aug 2017 15:00:22 -0700
Subject: [PATCH 03/15] btt: Fix overlapping IO stats.
Keep scanning the tree for overlapping IO otherwise Q2G and process
traces will be incorrect.
Let assume we have 2 IOs:
A A+a
|---------------------------------------|
B B+b
|-----------------|
In the red/black tree we have:
o -> [A,A+a]
/ \
left right
/ \
[...]o o -> [B, B+b]
In the current code, if we would not be able to find [B+b] in the tree:
B is greater than A, so we won't go left
B+b is smaller than A+a, so we are not going right either.
When we have a [X, X+x] IO to look for:
We need to check for right when either:
X+x >= A+a (for merged IO)
and
X > A (for overlapping IO)
TEST=Check with a trace with overlapping IO: Q2C and Q2G are expected.
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
btt/dip_rb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/btt/dip_rb.c b/btt/dip_rb.c
index 2aa7ffc..6efef6c 100644
--- a/btt/dip_rb.c
+++ b/btt/dip_rb.c
@@ -57,7 +57,7 @@ struct io *rb_find_sec(struct rb_root *root, __u64 sec)
__iop = rb_entry(n, struct io, rb_node);
if (sec < BIT_START(__iop))
n = n->rb_left;
- else if (sec >= BIT_END(__iop))
+ else if (sec > BIT_START(__iop))
n = n->rb_right;
else
return __iop;
@@ -82,7 +82,7 @@ void rb_foreach(struct rb_node *n, struct io *iop,
}
if (iop_s < this_s)
rb_foreach(n->rb_left, iop, fnc, head);
- if (this_e < iop_e)
+ if ((this_e < iop_e) || (this_s < iop_s))
rb_foreach(n->rb_right, iop, fnc, head);
}
}
--
1.8.3.1

View File

@ -0,0 +1,50 @@
From 3f8cadf8435fa3c9b0fe8aa1f7e2a50832310560 Mon Sep 17 00:00:00 2001
From: weiping zhang <zhangweiping@didichuxing.com>
Date: Mon, 15 Jan 2018 23:53:42 +0800
Subject: [PATCH 04/15] blktrace: don't stop tracer if not setup trace
successfully
if we run blktrace on same device twice, the second time will failed
to ioctl(BLKTRACESETUP), then it will call __stop_tracer, which lead
the first blktrace failed to access debugfs entries. So this patch add
a check to handle this case, to avoid stop tracer uncondionally.
Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
blktrace.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/blktrace.c b/blktrace.c
index e048f68..d0d271f 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -112,6 +112,7 @@ struct devpath {
struct cl_host *ch;
u32 cl_id;
time_t cl_connect_time;
+ int setup_done; /* ioctl BLKTRACESETUP done */
struct io_info *ios;
};
@@ -1083,6 +1084,7 @@ static int setup_buts(void)
if (ioctl(dpp->fd, BLKTRACESETUP, &buts) >= 0) {
dpp->ncpus = max_cpus;
dpp->buts_name = strdup(buts.name);
+ dpp->setup_done = 1;
if (dpp->stats)
free(dpp->stats);
dpp->stats = calloc(dpp->ncpus, sizeof(*dpp->stats));
@@ -1285,7 +1287,8 @@ static void rel_devpaths(void)
struct devpath *dpp = list_entry(p, struct devpath, head);
list_del(&dpp->head);
- __stop_trace(dpp->fd);
+ if (dpp->setup_done)
+ __stop_trace(dpp->fd);
close(dpp->fd);
if (dpp->heads)
--
1.8.3.1

View File

@ -0,0 +1,32 @@
From 39aa42dd6baeb9b7eb97b9bc4dadf6925799deee Mon Sep 17 00:00:00 2001
From: Weiping Zhang <zhangweiping@didichuxing.com>
Date: Sat, 7 Apr 2018 17:12:00 +0800
Subject: [PATCH 05/15] blkparse: remove duplicated entry for flag M
remove dupliated entry 'M' for man page of blkparse.
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Weiping Zhang <zhangweiping@didichuxing.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
doc/blkparse.1 | 4 ----
1 file changed, 4 deletions(-)
diff --git a/doc/blkparse.1 b/doc/blkparse.1
index be9b34b..b1cb6ef 100644
--- a/doc/blkparse.1
+++ b/doc/blkparse.1
@@ -243,10 +243,6 @@ Same as the back merge, except this i/o ends where a previously inserted
requests starts.
.HP 4
-\fBM --front or back merge\fR
-One of the above
-
-.HP 4
\fBM -- front or back merge\fR
One of the above.
--
1.8.3.1

View File

@ -1,7 +1,7 @@
From d61ff409cb4dda31386373d706ea0cfb1aaac5b7 Mon Sep 17 00:00:00 2001
From 4c31f93b0f2e2d44e598f7b7b63381811a192a5d Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Wed, 2 May 2018 10:24:17 -0600
Subject: btt: make device/devno use PATH_MAX to avoid overflow
Subject: [PATCH 06/15] btt: make device/devno use PATH_MAX to avoid overflow
Herbo Zhang reports:
@ -139,6 +139,5 @@ index 0553a9e..5fc1cb2 100644
LIST_HEAD(all_devmaps);
--
cgit v1.1
1.8.3.1

View File

@ -0,0 +1,184 @@
From 8c28ecc8192e230f859078f527527e31c663cff4 Mon Sep 17 00:00:00 2001
From: Eric Sandeen <sandeen@redhat.com>
Date: Wed, 28 Mar 2018 15:26:36 -0500
Subject: [PATCH 07/15] make btt scripts python3-ready
Many distributions are moving to python3 by default. Here's
an attempt to make the python scripts in blktrace python3-ready.
Most of this was done with automated tools. I hand fixed some
space-vs tab issues, and cast an array index to integer. It
passes rudimentary testing when run under python2.7 as well
as python3.
This doesn't do anything with the shebangs, it leaves them both
invoking whatever "env python" coughs up on the system.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
btt/bno_plot.py | 28 +++++++++++++++-------------
btt/btt_plot.py | 22 +++++++++++++---------
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/btt/bno_plot.py b/btt/bno_plot.py
index aa92480..f05cfdc 100644
--- a/btt/bno_plot.py
+++ b/btt/bno_plot.py
@@ -38,6 +38,8 @@ automatically push the keys under the graph.
To exit the plotter, enter 'quit' or ^D at the 'gnuplot> ' prompt.
"""
+from __future__ import absolute_import
+from __future__ import print_function
import getopt, glob, os, sys, tempfile
verbose = 0
@@ -60,14 +62,14 @@ def parse_args(in_args):
try:
(opts, args) = getopt.getopt(in_args, s_opts, l_opts)
- except getopt.error, msg:
- print >>sys.stderr, msg
- print >>sys.stderr, __doc__
+ except getopt.error as msg:
+ print(msg, file=sys.stderr)
+ print(__doc__, file=sys.stderr)
sys.exit(1)
for (o, a) in opts:
if o in ('-h', '--help'):
- print __doc__
+ print(__doc__)
sys.exit(0)
elif o in ('-v', '--verbose'):
verbose += 1
@@ -84,10 +86,10 @@ if __name__ == '__main__':
(bnos, keys_below) = parse_args(sys.argv[1:])
if verbose:
- print 'Using files:',
- for bno in bnos: print bno,
- if keys_below: print '\nKeys are to be placed below graph'
- else: print ''
+ print('Using files:', end=' ')
+ for bno in bnos: print(bno, end=' ')
+ if keys_below: print('\nKeys are to be placed below graph')
+ else: print('')
tmpdir = tempfile.mktemp()
os.mkdir(tmpdir)
@@ -99,7 +101,7 @@ if __name__ == '__main__':
fo = open(t, 'w')
for line in open(f, 'r'):
fld = line.split(None)
- print >>fo, fld[0], fld[1], int(fld[2])-int(fld[1])
+ print(fld[0], fld[1], int(fld[2])-int(fld[1]), file=fo)
fo.close()
t = t[t.rfind('/')+1:]
@@ -107,16 +109,16 @@ if __name__ == '__main__':
else: plot_cmd = "%s,'%s'" % (plot_cmd, t)
fo = open('%s/plot.cmds' % tmpdir, 'w')
- print >>fo, cmds
- if len(bnos) > 10 or keys_below: print >>fo, 'set key below'
- print >>fo, plot_cmd
+ print(cmds, file=fo)
+ if len(bnos) > 10 or keys_below: print('set key below', file=fo)
+ print(plot_cmd, file=fo)
fo.close()
pid = os.fork()
if pid == 0:
cmd = 'gnuplot %s/plot.cmds -' % tmpdir
- if verbose: print 'Executing %s' % cmd
+ if verbose: print('Executing %s' % cmd)
os.chdir(tmpdir)
os.system(cmd)
diff --git a/btt/btt_plot.py b/btt/btt_plot.py
index b81dad5..76fcca8 100755
--- a/btt/btt_plot.py
+++ b/btt/btt_plot.py
@@ -55,6 +55,10 @@ Arguments:
but the -o (--output) and -T (--title) options will be ignored.
"""
+from __future__ import absolute_import
+from __future__ import print_function
+import six
+from six.moves import range
__author__ = 'Alan D. Brunelle <alan.brunelle@hp.com>'
#------------------------------------------------------------------------------
@@ -82,7 +86,7 @@ get_base = lambda file: file[file.find('_')+1:file.rfind('_')]
def fatal(msg):
"""Generate fatal error message and exit"""
- print >>sys.stderr, 'FATAL: %s' % msg
+ print('FATAL: %s' % msg, file=sys.stderr)
sys.exit(1)
#------------------------------------------------------------------------------
@@ -163,7 +167,7 @@ def get_data(files):
if not os.path.exists(file):
fatal('%s not found' % file)
elif verbose:
- print 'Processing %s' % file
+ print('Processing %s' % file)
xs = []
ys = []
@@ -214,8 +218,8 @@ def parse_args(args):
try:
(opts, args) = getopt.getopt(args[1:], s_opts, l_opts)
- except getopt.error, msg:
- print >>sys.stderr, msg
+ except getopt.error as msg:
+ print(msg, file=sys.stderr)
fatal(__doc__)
for (o, a) in opts:
@@ -293,15 +297,15 @@ def generate_output(type, db):
def color(idx, style):
"""Returns a color/symbol type based upon the index passed."""
- colors = [ 'b', 'g', 'r', 'c', 'm', 'y', 'k' ]
+ colors = [ 'b', 'g', 'r', 'c', 'm', 'y', 'k' ]
l_styles = [ '-', ':', '--', '-.' ]
m_styles = [ 'o', '+', '.', ',', 's', 'v', 'x', '<', '>' ]
color = colors[idx % len(colors)]
if style == 'line':
- style = l_styles[(idx / len(l_styles)) % len(l_styles)]
+ style = l_styles[int((idx / len(l_styles)) % len(l_styles))]
elif style == 'marker':
- style = m_styles[(idx / len(m_styles)) % len(m_styles)]
+ style = m_styles[int((idx / len(m_styles)) % len(m_styles))]
return '%s%s' % (color, style)
@@ -314,7 +318,7 @@ def generate_output(type, db):
ofile = '%s.png' % type
if verbose:
- print 'Generating plot into %s' % ofile
+ print('Generating plot into %s' % ofile)
fig = plt.figure(figsize=plot_size)
ax = fig.add_subplot(111)
@@ -329,7 +333,7 @@ def generate_output(type, db):
legends = None
keys = []
- for file in db.iterkeys():
+ for file in six.iterkeys(db):
if not file in ['min_x', 'max_x', 'min_y', 'max_y']:
keys.append(file)
--
1.8.3.1

View File

@ -1,7 +1,7 @@
From d8b5a8105a76d390ae9bb197448235dfc663fdac Mon Sep 17 00:00:00 2001
From 0d0ffc078fb582357f563331b6cd06fce41cec88 Mon Sep 17 00:00:00 2001
From: sunshihao <sunshihao@huawei.com>
Date: Mon, 3 Feb 2020 17:58:10 +0800
Subject: [PATCH] blktrace: remove python2 dedpendency
Subject: [PATCH 08/15] blktrace: remove python2 dedpendency
in order to remove python2 dependency,we
use python3 as Default interpreter.
@ -13,7 +13,7 @@ Signed-off-by: sunshihao <sunshihao@huawei.com>
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/btt/bno_plot.py b/btt/bno_plot.py
index aa92480..bb0cae7 100644
index f05cfdc..74ebecb 100644
--- a/btt/bno_plot.py
+++ b/btt/bno_plot.py
@@ -1,4 +1,4 @@
@ -23,7 +23,7 @@ index aa92480..bb0cae7 100644
# btt blkno plotting interface
#
diff --git a/btt/btt_plot.py b/btt/btt_plot.py
index b81dad5..7e10f92 100755
index 76fcca8..fcd5838 100755
--- a/btt/btt_plot.py
+++ b/btt/btt_plot.py
@@ -1,4 +1,4 @@
@ -32,5 +32,6 @@ index b81dad5..7e10f92 100755
#
# btt_plot.py: Generate matplotlib plots for BTT generate data files
#
--
--
1.8.3.1

View File

@ -0,0 +1,51 @@
From 56f1d9991917ff8313e51fba5d3970042ac072ef Mon Sep 17 00:00:00 2001
From: Ignat Korchagin <ignat@cloudflare.com>
Date: Mon, 16 Sep 2019 10:30:23 -0600
Subject: [PATCH 09/15] btreplay: fix device IO remap functionality
Commit dd093eb1c48e ("Fix warnings on newer gcc") moved string buffers holding
device names during map file parse stage to stack. However, only pointers to
them are being stored in the allocated "struct map_dev" structure. These
pointers are invalid outside of scope of this function and in a different
thread context. Also "release_map_devs" function still tries to "free" them
later as if they were allocated on the heap.
Moving the buffers back to the heap by instructing "fscanf" to allocate them
while parsing the file.
Alternatively, we could redefine the "struct map_dev" to include the whole
buffers instead of just pointers to them and free them as part of releasing the
whole "struct map_dev".
Fixes: dd093eb1c48e ("Fix warnings on newer gcc")
Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
btreplay/btreplay.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/btreplay/btreplay.c b/btreplay/btreplay.c
index edaf81f..23cc2a9 100644
--- a/btreplay/btreplay.c
+++ b/btreplay/btreplay.c
@@ -645,7 +645,7 @@ static void find_input_devs(char *idir)
static void read_map_devs(char *file_name)
{
FILE *fp;
- char from_dev[256], to_dev[256];
+ char *from_dev, *to_dev;
fp = fopen(file_name, "r");
if (!fp) {
@@ -653,7 +653,7 @@ static void read_map_devs(char *file_name)
/*NOTREACHED*/
}
- while (fscanf(fp, "%s %s", from_dev, to_dev) == 2) {
+ while (fscanf(fp, "%ms %ms", &from_dev, &to_dev) == 2) {
struct map_dev *mdp = malloc(sizeof(*mdp));
mdp->from_dev = from_dev;
--
1.8.3.1

View File

@ -0,0 +1,69 @@
From 28c81fa538418628addf8b18cbed8ba5c62f3cc8 Mon Sep 17 00:00:00 2001
From: Hiroaki Mihara <hmihara@redhat.com>
Date: Wed, 25 Sep 2019 07:32:06 +0900
Subject: [PATCH 10/15] blkparse: split off the timestamp correction code in to
a separate function
find_genesis() function has code to correct abs_start_time, which is
later used to calculate the absolute timestamps of each traced
records.
Put this code in a separate function, so that it can be used later by
the blkparse code. No functional change.
Signed-off-by: Hiroaki Mihara <hmihara@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
blkparse.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/blkparse.c b/blkparse.c
index 227cc44..fb540ee 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -1920,6 +1920,22 @@ static void show_device_and_cpu_stats(void)
}
}
+static void correct_abs_start_time(void)
+{
+ long delta = genesis_time - start_timestamp;
+
+ abs_start_time.tv_sec += SECONDS(delta);
+ abs_start_time.tv_nsec += NANO_SECONDS(delta);
+ if (abs_start_time.tv_nsec < 0) {
+ abs_start_time.tv_nsec += 1000000000;
+ abs_start_time.tv_sec -= 1;
+ } else
+ if (abs_start_time.tv_nsec > 1000000000) {
+ abs_start_time.tv_nsec -= 1000000000;
+ abs_start_time.tv_sec += 1;
+ }
+}
+
static void find_genesis(void)
{
struct trace *t = trace_list;
@@ -1937,18 +1953,7 @@ static void find_genesis(void)
*/
if (start_timestamp
&& start_timestamp != genesis_time) {
- long delta = genesis_time - start_timestamp;
-
- abs_start_time.tv_sec += SECONDS(delta);
- abs_start_time.tv_nsec += NANO_SECONDS(delta);
- if (abs_start_time.tv_nsec < 0) {
- abs_start_time.tv_nsec += 1000000000;
- abs_start_time.tv_sec -= 1;
- } else
- if (abs_start_time.tv_nsec > 1000000000) {
- abs_start_time.tv_nsec -= 1000000000;
- abs_start_time.tv_sec += 1;
- }
+ correct_abs_start_time();
}
}
--
1.8.3.1

View File

@ -0,0 +1,136 @@
From 985aa086d949963717d4f730f14eeb8cafd789da Mon Sep 17 00:00:00 2001
From: Hiroaki Mihara <hmihara@redhat.com>
Date: Wed, 25 Sep 2019 07:32:50 +0900
Subject: [PATCH 11/15] blkparse: fix absolute timestamp when reading from file
This patch fixes the wrong absolute timestamps when blkparse reads
data from files.
The blkparse command prints out wrong timestamps if all the following
conditions are met,
* The blkparse command reads data from files created by blktrace.
* "z" format option is set as OUTPUT DESCRIPTION.
ex.) blkparse xxx.blktrace.0 -f "%z\n"
* start_timestamp(=blktrace command started) != genesis_time(=first
I/O traced)
When blkparse reads data from pipe instead, it yields correct
timestamps.
The root cause of this issue comes from the fact that the time
difference between start_timestamp and genesis_time is not added when
blkparse reads data from files. When blkparse reads data from pipe,
the time-difference is added through find_genesis() function.
The following test cases show the contradictions in absolute
timestams. Also the Step 4 shows that the issue is fixed with the
blkparse command with the suggesting patch.
* Step 1: After invoking blktrace command, test I/O traffic was
generated by dd command as follows,
# date +%Y%m%d_%H%M%S_%N; dd if=/dev/sda3 of=/dev/null count=1 iflag=direct
20190919_092726_077032490
1+0 records in
1+0 records out
512 bytes copied, 0.00122329 s, 419 kB/s
The timestamp was recorded just before executing dd command. The
test I/O would have been traced right after 09:27:26.077032490 .
* Step 2: The blkparse command reads data from "pipe".
$ cat test.blktrace.* | blkparse - -f "%T.%t %z %C\n"
0.000000000 09:27:22.427592 kworker/0:0
0.000002080 09:27:22.427594 kworker/0:0
.
.
3.652263118 09:27:26.079855 dd
3.652265818 09:27:26.079857 dd
3.652274742 09:27:26.079866 dd
3.652277266 09:27:26.079869 dd
The first I/O by dd command showed the relative timestamp as
3.652263118 and the absolute timestamp as 09:27:26.079855, which is
right after the timestamp shown in the Step 1.
* Step 3: The blkparse command reads from the trace "file" created in
the Step 1.
$ blkparse test -f "%T.%t %z %C\n"
Input file test.blktrace.0 added
Input file test.blktrace.1 added
Input file test.blktrace.2 added
Input file test.blktrace.3 added
0.000000000 09:27:21.187304 kworker/0:0
0.000002080 09:27:21.187306 kworker/0:0
.
.
3.652263118 09:27:24.839567 dd
3.652265818 09:27:24.839570 dd
3.652274742 09:27:24.839578 dd
3.652277266 09:27:24.839581 dd
In the previous step (Step 2), the data was passed via pipe. In this
case, the blkparse command reads data from the same file, instead.
The first I/O by dd command showed the relative timestamp as
3.652263118 and the absolute timestamp as 09:27:24.839567, which is
a few seconds earlier than the absolute timestamp recorded in the
Step 1. The order of events and the absolute timestamps contradict.
* Step 4: The blkparse command with the suggesting patch
(./blkparse_with_patch) reads data from the trace file created in
the Step 1.
$ ./blkparse_with_patch test -f "%T.%t %z %C\n"
Input file test.blktrace.0 added
Input file test.blktrace.1 added
Input file test.blktrace.2 added
Input file test.blktrace.3 added
0.000000000 09:27:22.427592 kworker/0:0
0.000002080 09:27:22.427594 kworker/0:0
.
.
3.652263118 09:27:26.079855 dd
3.652265818 09:27:26.079857 dd
3.652274742 09:27:26.079866 dd
3.652277266 09:27:26.079869 dd
In this case, the absolute timestamps showed the same value as shown
in the Step 2(the case with pipe).
The time gap between the genesis_ time and the start_timestamp was
corrected even if the blkparse reads data from files.
Signed-off-by: Hiroaki Mihara <hmihara@redhat.com>
the#
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
blkparse.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/blkparse.c b/blkparse.c
index fb540ee..08c9f60 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -2608,6 +2608,14 @@ static int do_file(void)
genesis_time = ms_peek_time(ms_head);
/*
+ * Correct abs_start_time if necessary
+ */
+ if (start_timestamp
+ && start_timestamp != genesis_time) {
+ correct_abs_start_time();
+ }
+
+ /*
* Keep processing traces while any are left
*/
while (!is_done() && ms_head && handle(ms_head))
--
1.8.3.1

View File

@ -0,0 +1,62 @@
From 0980a46e463b1c4286dab77a2a8a3f38dd2266b4 Mon Sep 17 00:00:00 2001
From: Vincent Legoll <vincent.legoll@gmail.com>
Date: Fri, 20 Mar 2020 22:44:59 +0100
Subject: [PATCH 12/15] btt_plot.py: Use `with open() as ...` context manager
to automatically handle close()
Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
btt/btt_plot.py | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/btt/btt_plot.py b/btt/btt_plot.py
index fcd5838..89ef54f 100755
--- a/btt/btt_plot.py
+++ b/btt/btt_plot.py
@@ -171,14 +171,15 @@ def get_data(files):
xs = []
ys = []
- for line in open(file, 'r'):
- f = line.rstrip().split(None)
- if line.find('#') == 0 or len(f) < 2:
- continue
- (min_x, max_x, x) = check(min_x, max_x, f[0])
- (min_y, max_y, y) = check(min_y, max_y, f[1])
- xs.append(x)
- ys.append(y)
+ with open(file, 'r') as fi:
+ for line in fi:
+ f = line.rstrip().split(None)
+ if line.find('#') == 0 or len(f) < 2:
+ continue
+ (min_x, max_x, x) = check(min_x, max_x, f[0])
+ (min_y, max_y, y) = check(min_y, max_y, f[1])
+ xs.append(x)
+ ys.append(y)
db[file] = {'x':xs, 'y':ys}
if len(xs) > 10:
@@ -388,11 +389,12 @@ def do_live(files):
def get_live_data(fn):
xs = []
ys = []
- for line in open(fn, 'r'):
- f = line.rstrip().split()
- if f[0] != '#' and len(f) == 2:
- xs.append(float(f[0]))
- ys.append(float(f[1]))
+ with open(fn, 'r') as fi:
+ for line in fi:
+ f = line.rstrip().split()
+ if f[0] != '#' and len(f) == 2:
+ xs.append(float(f[0]))
+ ys.append(float(f[1]))
return xs, ys
#----------------------------------------------------------------------
--
1.8.3.1

View File

@ -0,0 +1,49 @@
From 2d24805793941d066871f0385a206c4700ea5d59 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruenba@redhat.com>
Date: Mon, 13 Apr 2020 21:01:49 +0200
Subject: [PATCH 13/15] blkparse: Fix device in event tracking error messages
For some reason, dev in struct per_dev_info isn't set in the log_track_
functions, and so the error messages report (0,0) as the device. Fix by using
device in struct blk_io_trace instead.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
blkparse.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/blkparse.c b/blkparse.c
index 08c9f60..6cba92c 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -986,7 +986,7 @@ static void log_track_frontmerge(struct per_dev_info *pdi,
if (!iot) {
if (verbose)
fprintf(stderr, "merge not found for (%d,%d): %llu\n",
- MAJOR(pdi->dev), MINOR(pdi->dev),
+ MAJOR(t->device), MINOR(t->device),
(unsigned long long) t->sector + t_sec(t));
return;
}
@@ -1080,7 +1080,7 @@ static unsigned long long log_track_issue(struct per_dev_info *pdi,
if (!iot) {
if (verbose)
fprintf(stderr, "issue not found for (%d,%d): %llu\n",
- MAJOR(pdi->dev), MINOR(pdi->dev),
+ MAJOR(t->device), MINOR(t->device),
(unsigned long long) t->sector);
return -1;
}
@@ -1115,7 +1115,7 @@ static unsigned long long log_track_complete(struct per_dev_info *pdi,
if (!iot) {
if (verbose)
fprintf(stderr,"complete not found for (%d,%d): %llu\n",
- MAJOR(pdi->dev), MINOR(pdi->dev),
+ MAJOR(t->device), MINOR(t->device),
(unsigned long long) t->sector);
return -1;
}
--
1.8.3.1

View File

@ -0,0 +1,45 @@
From 83ebfe28ebae191d4435683660a98520b9153401 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruenba@redhat.com>
Date: Mon, 13 Apr 2020 21:01:50 +0200
Subject: [PATCH 14/15] blkparse: Allow request tracking on non md/dm devices
Fix queue to completion tracking on devices other than md/dm: without this fix,
enabling tracking with the -t option on a non-md/dm device leads to "complete
not found" errors.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
blkparse.c | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/blkparse.c b/blkparse.c
index 6cba92c..2d89bc5 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -1007,13 +1007,6 @@ static void log_track_getrq(struct per_dev_info *pdi, struct blk_io_trace *t)
iot->allocation_time = t->time;
}
-static inline int is_remapper(struct per_dev_info *pdi)
-{
- int major = MAJOR(pdi->dev);
-
- return (major == 253 || major == 9);
-}
-
/*
* for md/dm setups, the interesting cycle is Q -> C. So track queueing
* time here, as dispatch time
@@ -1024,8 +1017,6 @@ static void log_track_queue(struct per_dev_info *pdi, struct blk_io_trace *t)
if (!track_ios)
return;
- if (!is_remapper(pdi))
- return;
iot = find_track(pdi, t->pid, t->sector);
iot->dispatch_time = t->time;
--
1.8.3.1

View File

@ -0,0 +1,148 @@
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

View File

@ -1,6 +1,6 @@
Name: blktrace
Version: 1.2.0
Release: 14
Release: 15
Summary: Block IO tracer in the Linux kernel
License: GPLv2+
Source: http://brick.kernel.dk/snaps/blktrace-%{version}.tar.bz2
@ -11,9 +11,21 @@ Provides: iowatcher = %{version}-%{release}
Obsoletes: iowatcher < %{version}-%{release}
Requires: python3
Patch0: 0000-blktrace-fix-btt-overflow.patch
Patch1: 0001-remove-python2-dependency.patch
Patch2: 0002-modify-python2-expression-to-python3.patch
Patch1: 0001-jhash-fix-annoying-gcc-fall-through-warnings.patch
Patch2: 0002-btt-devs-silence-warning-on-sprintf-overflow.patch
Patch3: 0003-btt-Fix-overlapping-IO-stats.patch
Patch4: 0004-blktrace-don-t-stop-tracer-if-not-setup-trace-succes.patch
Patch5: 0005-blkparse-remove-duplicated-entry-for-flag-M.patch
Patch6: 0006-btt-make-device-devno-use-PATH_MAX-to-avoid-overflow.patch
Patch7: 0007-make-btt-scripts-python3-ready.patch
Patch8: 0008-blktrace-remove-python2-dedpendency.patch
Patch9: 0009-btreplay-fix-device-IO-remap-functionality.patch
Patch10: 0010-blkparse-split-off-the-timestamp-correction-code-in-.patch
Patch11: 0011-blkparse-fix-absolute-timestamp-when-reading-from-fi.patch
Patch12: 0012-btt_plot.py-Use-with-open-as-.-context-manager.patch
Patch13: 0013-blkparse-Fix-device-in-event-tracking-error-messages.patch
Patch14: 0014-blkparse-Allow-request-tracking-on-non-md-dm-devices.patch
Patch15: 0015-blkparse-Initialize-and-test-for-undefined-request-t.patch
%description
blktrace is a block layer IO tracing mechanism which provides detailed
@ -48,6 +60,9 @@ make dest=%{buildroot} prefix=%{buildroot}/%{_prefix} mandir=%{buildroot}/%{_man
%{_mandir}/man8/*
%changelog
* Sun Jul 12 2020 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 1.2.0-15
- backport upstream patches
* Wed Jul 1 2020 Wu Bo <wubo009@163.com> - 1.2.0-14
- rebuild package