* [PATCH 0/6] blktrace: last round of fixes
@ 2009-03-27 2:19 Li Zefan
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
` (5 more replies)
0 siblings, 6 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:19 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
This is the last round of fixes for blktrace, I hope. :)
[PATCH 1/6] blktrace: make classic output more classic
[PATCH 2/6] blktrace: fix blk_probes_ref chaos
[PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace
[PATCH 4/6] trace: make 'mem' argument of trace_seq_putmem() const
[PATCH 5/6] blktrace: extract duplidate code
[PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly
---
blktrace.c | 188 +++++++++++++++++++++++++++++++++------------------------
trace_output.c | 6 -
trace_output.h | 5 -
3 files changed, 117 insertions(+), 82 deletions(-)
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 1/6] blktrace: make classic output more classic
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
@ 2009-03-27 2:19 ` Li Zefan
2009-03-27 3:30 ` Li Zefan
` (2 more replies)
2009-03-27 2:20 ` [PATCH 2/6] blktrace: fix blk_probes_ref chaos Li Zefan
` (4 subsequent siblings)
5 siblings, 3 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:19 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
In the classic user-space blktrace, the output timestamp is sec.nsec
not sec.usec.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/blktrace.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index d43cdac..933639a 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -995,7 +995,7 @@ static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
unsigned long long ts = ns2usecs(iter->ts);
- unsigned long usec_rem = do_div(ts, USEC_PER_SEC);
+ unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
unsigned secs = (unsigned long)ts;
const struct trace_entry *ent = iter->ent;
const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
@@ -1003,9 +1003,9 @@ static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
fill_rwbs(rwbs, t);
return trace_seq_printf(&iter->seq,
- "%3d,%-3d %2d %5d.%06lu %5u %2s %3s ",
+ "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
MAJOR(t->device), MINOR(t->device), iter->cpu,
- secs, usec_rem, ent->pid, act, rwbs);
+ secs, nsec_rem, ent->pid, act, rwbs);
}
static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 2/6] blktrace: fix blk_probes_ref chaos
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
@ 2009-03-27 2:20 ` Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:20 ` [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
` (3 subsequent siblings)
5 siblings, 2 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:20 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
ioctl-based blktrace allocates bt and registers tracepoints when
ioctl(BLKTRACESETUP), and do all cleanups when ioctl(BLKTRACETEARDOWN).
while ftrace-based blktrace allocates/frees bt when:
# echo 1/0 > /sys/block/sda/sda1/trace/enable
and registers/unregisters tracepoints when:
# echo blk/nop > /debugfs/tracing/current_tracer
or
# echo 1/0 > /debugfs/tracing/tracing_enable
The separatation of allocation and registeration causes 2 problems:
1. current user-space blktrace still calls ioctl(TEARDOWN) when
ioctl(SETUP) failed:
# echo 1 > /sys/block/sda/sda1/trace/enable
# blktrace /dev/sda
BLKTRACESETUP: Device or resource busy
^C
and now blk_probes_ref == -1
2. Another way to make blk_probes_ref == -1:
# plugin sdb && mount sdb1
# echo 1 > /sys/block/sdb/sdb1/trace/enable
# remove sdb
This patch does the allocation and registeration when writing
sdaX/trace/enable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/blktrace.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 933639a..f36e531 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -478,7 +478,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
goto err;
}
- if (atomic_add_return(1, &blk_probes_ref) == 1)
+ if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
return 0;
@@ -1091,8 +1091,6 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- if (atomic_add_return(1, &blk_probes_ref) == 1)
- blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1107,15 +1105,10 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
}
static void blk_tracer_reset(struct trace_array *tr)
{
- if (!atomic_read(&blk_probes_ref))
- return;
-
blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1254,6 +1247,9 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (bt == NULL)
return -EINVAL;
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+
kfree(bt);
return 0;
}
@@ -1280,6 +1276,9 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
return -EBUSY;
}
+ if (atomic_inc_return(&blk_probes_ref) == 1)
+ blk_register_tracepoints();
+
return 0;
}
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
2009-03-27 2:20 ` [PATCH 2/6] blktrace: fix blk_probes_ref chaos Li Zefan
@ 2009-03-27 2:20 ` Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:21 ` [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const Li Zefan
` (2 subsequent siblings)
5 siblings, 2 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:20 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
When mixing the use of ioctl-based blktrace and ftrace-based blktrace,
we can leak memory in this way:
# btrace /dev/sda > /dev/null &
# echo 0 > /sys/block/sda/sda1/trace/enable
now we leak bt->dropped_file, bt->msg_file, bt->rchan...
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/blktrace.c | 29 ++++++++++++-----------------
1 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index f36e531..6b38a34 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -247,7 +247,7 @@ record_it:
static struct dentry *blk_tree_root;
static DEFINE_MUTEX(blk_tree_mutex);
-static void blk_trace_cleanup(struct blk_trace *bt)
+static void blk_trace_free(struct blk_trace *bt)
{
debugfs_remove(bt->msg_file);
debugfs_remove(bt->dropped_file);
@@ -255,6 +255,11 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
+}
+
+static void blk_trace_cleanup(struct blk_trace *bt)
+{
+ blk_trace_free(bt);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
}
@@ -410,11 +415,11 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (buts->name[i] == '/')
buts->name[i] = '_';
- ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
- goto err;
+ return -ENOMEM;
+ ret = -ENOMEM;
bt->sequence = alloc_percpu(unsigned long);
if (!bt->sequence)
goto err;
@@ -483,17 +488,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
return 0;
err:
- if (bt) {
- if (bt->msg_file)
- debugfs_remove(bt->msg_file);
- if (bt->dropped_file)
- debugfs_remove(bt->dropped_file);
- free_percpu(bt->sequence);
- free_percpu(bt->msg_data);
- if (bt->rchan)
- relay_close(bt->rchan);
- kfree(bt);
- }
+ blk_trace_free(bt);
return ret;
}
@@ -1091,6 +1086,7 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
+ blk_tracer_enabled = true;
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1098,18 +1094,17 @@ static int blk_tracer_init(struct trace_array *tr)
{
blk_tr = tr;
blk_tracer_start(tr);
- blk_tracer_enabled = true;
return 0;
}
static void blk_tracer_stop(struct trace_array *tr)
{
+ blk_tracer_enabled = false;
trace_flags |= TRACE_ITER_CONTEXT_INFO;
}
static void blk_tracer_reset(struct trace_array *tr)
{
- blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1250,7 +1245,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- kfree(bt);
+ blk_trace_free(bt);
return 0;
}
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
` (2 preceding siblings ...)
2009-03-27 2:20 ` [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
@ 2009-03-27 2:21 ` Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
2009-03-27 2:21 ` [PATCH 5/6] blktrace: extract duplidate code Li Zefan
2009-03-27 2:21 ` [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
5 siblings, 2 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:21 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
I passed a const value to trace_seq_putmem(), and I got compile warning.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/trace_output.c | 6 +++---
kernel/trace/trace_output.h | 5 +++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 6595074..d72b9a6 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -137,7 +137,7 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c)
return 1;
}
-int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
{
if (len > ((PAGE_SIZE - 1) - s->len))
return 0;
@@ -148,10 +148,10 @@ int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
return len;
}
-int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
{
unsigned char hex[HEX_CHARS];
- unsigned char *data = mem;
+ const unsigned char *data = mem;
int i, j;
#ifdef __BIG_ENDIAN
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index 46fb961..e0bde39 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -31,8 +31,9 @@ extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
size_t cnt);
extern int trace_seq_puts(struct trace_seq *s, const char *str);
extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
-extern int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len);
-extern int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len);
+extern int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len);
+extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
+ size_t len);
extern void *trace_seq_reserve(struct trace_seq *s, size_t len);
extern int trace_seq_path(struct trace_seq *s, struct path *path);
extern int seq_print_userip_objs(const struct userstack_entry *entry,
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 5/6] blktrace: extract duplidate code
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
` (3 preceding siblings ...)
2009-03-27 2:21 ` [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const Li Zefan
@ 2009-03-27 2:21 ` Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
2009-03-27 2:21 ` [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
5 siblings, 2 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:21 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
blk_trace_event_print() and blk_tracer_print_line() share most of the code.
text data bss dec hex filename
8605 393 12 9010 2332 kernel/trace/blktrace.o.orig
text data bss dec hex filename
8555 393 12 8960 2300 kernel/trace/blktrace.o
This patch also prepares for the next patch, that prints out BLK_TN_MESSAGE.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/blktrace.c | 62 ++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 6b38a34..7dda5ea 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -986,29 +986,31 @@ static void get_pdu_remap(const struct trace_entry *ent,
r->sector = be64_to_cpu(sector);
}
-static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
+typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act);
+
+static int blk_log_action_classic(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
unsigned long long ts = ns2usecs(iter->ts);
unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
unsigned secs = (unsigned long)ts;
- const struct trace_entry *ent = iter->ent;
- const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
+ const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
fill_rwbs(rwbs, t);
return trace_seq_printf(&iter->seq,
"%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
MAJOR(t->device), MINOR(t->device), iter->cpu,
- secs, nsec_rem, ent->pid, act, rwbs);
+ secs, nsec_rem, iter->ent->pid, act, rwbs);
}
-static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
- const char *act)
+static int blk_log_action(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
+ const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
+
fill_rwbs(rwbs, t);
- return trace_seq_printf(s, "%3d,%-3d %2s %3s ",
+ return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ",
MAJOR(t->device), MINOR(t->device), act, rwbs);
}
@@ -1129,22 +1131,25 @@ static const struct {
[__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap },
};
-static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
- int flags)
+static enum print_line_t print_one_line(struct trace_iterator *iter,
+ bool classic)
{
struct trace_seq *s = &iter->seq;
- const struct blk_io_trace *t = (struct blk_io_trace *)iter->ent;
- const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ const struct blk_io_trace *t;
+ u16 what;
int ret;
+ bool long_act;
+ blk_log_action_t *log_action;
- if (!trace_print_context(iter))
- return TRACE_TYPE_PARTIAL_LINE;
+ t = te_blk_io_trace(iter->ent);
+ what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
+ log_action = classic ? &blk_log_action_classic : &blk_log_action;
if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
ret = trace_seq_printf(s, "Bad pc action %x\n", what);
else {
- const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
- ret = blk_log_action_seq(s, t, what2act[what].act[long_act]);
+ ret = log_action(iter, what2act[what].act[long_act]);
if (ret)
ret = what2act[what].print(s, iter->ent);
}
@@ -1152,6 +1157,15 @@ static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
}
+static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
+ int flags)
+{
+ if (!trace_print_context(iter))
+ return TRACE_TYPE_PARTIAL_LINE;
+
+ return print_one_line(iter, false);
+}
+
static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
{
struct trace_seq *s = &iter->seq;
@@ -1177,26 +1191,10 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags)
static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)
{
- const struct blk_io_trace *t;
- u16 what;
- int ret;
-
if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
return TRACE_TYPE_UNHANDLED;
- t = (const struct blk_io_trace *)iter->ent;
- what = t->action & ((1 << BLK_TC_SHIFT) - 1);
-
- if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
- ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what);
- else {
- const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
- ret = blk_log_action_iter(iter, what2act[what].act[long_act]);
- if (ret)
- ret = what2act[what].print(&iter->seq, iter->ent);
- }
-
- return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
+ return print_one_line(iter, true);
}
static struct tracer blk_tracer __read_mostly = {
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
` (4 preceding siblings ...)
2009-03-27 2:21 ` [PATCH 5/6] blktrace: extract duplidate code Li Zefan
@ 2009-03-27 2:21 ` Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
5 siblings, 2 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 2:21 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
Before this patch:
# cat trace
make-5383 [001] 741.240059: 8,7 P N [make]
__trace_note_message: cfq1074
# echo 1 > options/blk_classic
# cat trace
8,7 1 0.692221252 0 C W 130411392 + 1024 [0]
Bad pc action 6361
Bad pc action 283d
# echo 0 > options/blk_classic
# echo bin > trace_options
# cat trace_pipe | blkparse -i -
(can't parse messages generated by blk_add_trace_msg())
After this patch:
# cat trace
<idle>-0 [001] 187.600933: 8,7 C W 145220224 + 8 [0]
<idle>-0 [001] 187.600946: 8,7 m N cfq1076 complete
# echo 1 > options/blk_classic
# cat trace
8,7 1 0.256378996 238 I W 113190728 + 8 [pdflush]
8,7 1 0.256378998 238 m N cfq1076 insert_request
# echo 0 > options/blk_classic
# echo bin > trace_options
# cat trace_pipe | blkparse -i -
8,7 1 0 22.973250293 0 C W 102770576 + 8 [0]
8,7 1 0 22.973259213 0 m N cfq1076 complete
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/blktrace.c | 80 +++++++++++++++++++++++++++++++++++-----------
1 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 7dda5ea..47c9d85 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -59,22 +59,39 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
const void *data, size_t len)
{
struct blk_io_trace *t;
+ struct ring_buffer_event *event = NULL;
+ int pc = 0;
+ int cpu = smp_processor_id();
+ bool blk_tracer = blk_tracer_enabled;
+
+ if (blk_tracer) {
+ pc = preempt_count();
+ event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK,
+ sizeof(*t) + len,
+ 0, pc);
+ if (!event)
+ return;
+ t = ring_buffer_event_data(event);
+ goto record_it;
+ }
if (!bt->rchan)
return;
t = relay_reserve(bt->rchan, sizeof(*t) + len);
if (t) {
- const int cpu = smp_processor_id();
-
t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
t->time = ktime_to_ns(ktime_get());
+record_it:
t->device = bt->dev;
t->action = action;
t->pid = pid;
t->cpu = cpu;
t->pdu_len = len;
memcpy((void *) t + sizeof(*t), data, len);
+
+ if (blk_tracer)
+ trace_buffer_unlock_commit(blk_tr, event, 0, pc);
}
}
@@ -110,14 +127,8 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
unsigned long flags;
char *buf;
- if (blk_tracer_enabled) {
- va_start(args, fmt);
- ftrace_vprintk(fmt, args);
- va_end(args);
- return;
- }
-
- if (!bt->msg_data)
+ if (unlikely(bt->trace_state != Blktrace_running &&
+ !blk_tracer_enabled))
return;
local_irq_save(flags);
@@ -168,9 +179,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
unsigned long *sequence;
pid_t pid;
int cpu, pc = 0;
+ bool blk_tracer = blk_tracer_enabled;
- if (unlikely(bt->trace_state != Blktrace_running &&
- !blk_tracer_enabled))
+ if (unlikely(bt->trace_state != Blktrace_running && !blk_tracer))
return;
what |= ddir_act[rw & WRITE];
@@ -185,7 +196,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
return;
cpu = raw_smp_processor_id();
- if (blk_tracer_enabled) {
+ if (blk_tracer) {
tracing_record_cmdline(current);
pc = preempt_count();
@@ -235,7 +246,7 @@ record_it:
if (pdu_len)
memcpy((void *) t + sizeof(*t), pdu_data, pdu_len);
- if (blk_tracer_enabled) {
+ if (blk_tracer) {
trace_buffer_unlock_commit(blk_tr, event, 0, pc);
return;
}
@@ -922,6 +933,11 @@ static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
int i = 0;
int tc = t->action >> BLK_TC_SHIFT;
+ if (t->action == BLK_TN_MESSAGE) {
+ rwbs[i++] = 'N';
+ goto out;
+ }
+
if (tc & BLK_TC_DISCARD)
rwbs[i++] = 'D';
else if (tc & BLK_TC_WRITE)
@@ -939,7 +955,7 @@ static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
rwbs[i++] = 'S';
if (tc & BLK_TC_META)
rwbs[i++] = 'M';
-
+out:
rwbs[i] = '\0';
}
@@ -1074,6 +1090,17 @@ static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent)
get_pdu_int(ent), cmd);
}
+static int blk_log_msg(struct trace_seq *s, const struct trace_entry *ent)
+{
+ int ret;
+ const struct blk_io_trace *t = te_blk_io_trace(ent);
+
+ ret = trace_seq_putmem(s, t + 1, t->pdu_len);
+ if (ret)
+ return trace_seq_putc(s, '\n');
+ return ret;
+}
+
/*
* struct tracer operations
*/
@@ -1146,6 +1173,13 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
log_action = classic ? &blk_log_action_classic : &blk_log_action;
+ if (t->action == BLK_TN_MESSAGE) {
+ ret = log_action(iter, long_act ? "message" : "m");
+ if (ret)
+ ret = blk_log_msg(s, iter->ent);
+ goto out;
+ }
+
if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
ret = trace_seq_printf(s, "Bad pc action %x\n", what);
else {
@@ -1153,7 +1187,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
if (ret)
ret = what2act[what].print(s, iter->ent);
}
-
+out:
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
}
@@ -1253,11 +1287,16 @@ static int blk_trace_remove_queue(struct request_queue *q)
static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
{
struct blk_trace *old_bt, *bt = NULL;
+ int ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
return -ENOMEM;
+ bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
+ if (!bt->msg_data)
+ goto free_bt;
+
bt->dev = dev;
bt->act_mask = (u16)-1;
bt->end_lba = -1ULL;
@@ -1265,14 +1304,17 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
old_bt = xchg(&q->blk_trace, bt);
if (old_bt != NULL) {
(void)xchg(&q->blk_trace, old_bt);
- kfree(bt);
- return -EBUSY;
+ ret = -EBUSY;
+ goto free_bt;
}
if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
-
return 0;
+
+free_bt:
+ blk_trace_free(bt);
+ return ret;
}
/*
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 1/6] blktrace: make classic output more classic
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
@ 2009-03-27 3:30 ` Li Zefan
2009-03-28 21:27 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2 siblings, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-27 3:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jens Axboe, Arnaldo Carvalho de Melo, Steven Rostedt,
Frederic Weisbecker, LKML
> @@ -995,7 +995,7 @@ static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
> {
> char rwbs[6];
> unsigned long long ts = ns2usecs(iter->ts);
This should be changed to "ts = iter->ts".
I'll fix it and resend the patchset, since this affects a later patch.
> - unsigned long usec_rem = do_div(ts, USEC_PER_SEC);
> + unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
> unsigned secs = (unsigned long)ts;
> const struct trace_entry *ent = iter->ent;
> const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
> @@ -1003,9 +1003,9 @@ static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
> fill_rwbs(rwbs, t);
^ permalink raw reply [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: make classic output more classic
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
2009-03-27 3:30 ` Li Zefan
@ 2009-03-28 21:27 ` Li Zefan
2009-03-30 1:19 ` Li Zefan
2 siblings, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-28 21:27 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 4a80b7286d8aff20d447977451622cdc01adb127
Gitweb: http://git.kernel.org/tip/4a80b7286d8aff20d447977451622cdc01adb127
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:19:46 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 28 Mar 2009 12:51:40 +0100
blktrace: make classic output more classic
Impact: fix ftrace plugin timestamp output
In the classic user-space blktrace, the output timestamp is sec.nsec
not sec.usec.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37C2.7050307@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index d43cdac..5b28f0f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -994,8 +994,8 @@ static void get_pdu_remap(const struct trace_entry *ent,
static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
- unsigned long long ts = ns2usecs(iter->ts);
- unsigned long usec_rem = do_div(ts, USEC_PER_SEC);
+ unsigned long long ts = iter->ts;
+ unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
unsigned secs = (unsigned long)ts;
const struct trace_entry *ent = iter->ent;
const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
@@ -1003,9 +1003,9 @@ static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
fill_rwbs(rwbs, t);
return trace_seq_printf(&iter->seq,
- "%3d,%-3d %2d %5d.%06lu %5u %2s %3s ",
+ "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
MAJOR(t->device), MINOR(t->device), iter->cpu,
- secs, usec_rem, ent->pid, act, rwbs);
+ secs, nsec_rem, ent->pid, act, rwbs);
}
static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: fix blk_probes_ref chaos
2009-03-27 2:20 ` [PATCH 2/6] blktrace: fix blk_probes_ref chaos Li Zefan
@ 2009-03-28 21:28 ` Li Zefan
2009-03-30 1:19 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-28 21:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 2311b67256cb376cdbb541c781b95397f6896911
Gitweb: http://git.kernel.org/tip/2311b67256cb376cdbb541c781b95397f6896911
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:20:09 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 28 Mar 2009 12:51:41 +0100
blktrace: fix blk_probes_ref chaos
Impact: fix mixed ioctl and ftrace-plugin blktrace use refcount bugs
ioctl-based blktrace allocates bt and registers tracepoints when
ioctl(BLKTRACESETUP), and do all cleanups when ioctl(BLKTRACETEARDOWN).
while ftrace-based blktrace allocates/frees bt when:
# echo 1/0 > /sys/block/sda/sda1/trace/enable
and registers/unregisters tracepoints when:
# echo blk/nop > /debugfs/tracing/current_tracer
or
# echo 1/0 > /debugfs/tracing/tracing_enable
The separatation of allocation and registeration causes 2 problems:
1. current user-space blktrace still calls ioctl(TEARDOWN) when
ioctl(SETUP) failed:
# echo 1 > /sys/block/sda/sda1/trace/enable
# blktrace /dev/sda
BLKTRACESETUP: Device or resource busy
^C
and now blk_probes_ref == -1
2. Another way to make blk_probes_ref == -1:
# plugin sdb && mount sdb1
# echo 1 > /sys/block/sdb/sdb1/trace/enable
# remove sdb
This patch does the allocation and registeration when writing
sdaX/trace/enable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37D9.6030201@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 5b28f0f..8d6bd12 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -478,7 +478,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
goto err;
}
- if (atomic_add_return(1, &blk_probes_ref) == 1)
+ if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
return 0;
@@ -1091,8 +1091,6 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- if (atomic_add_return(1, &blk_probes_ref) == 1)
- blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1107,15 +1105,10 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
}
static void blk_tracer_reset(struct trace_array *tr)
{
- if (!atomic_read(&blk_probes_ref))
- return;
-
blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1254,6 +1247,9 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (bt == NULL)
return -EINVAL;
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+
kfree(bt);
return 0;
}
@@ -1280,6 +1276,9 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
return -EBUSY;
}
+ if (atomic_inc_return(&blk_probes_ref) == 1)
+ blk_register_tracepoints();
+
return 0;
}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: fix memory leak when freeing struct blk_io_trace
2009-03-27 2:20 ` [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
@ 2009-03-28 21:28 ` Li Zefan
2009-03-30 1:19 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-28 21:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 3cf224e4aa4a1f24361bce35b3bb54f553bee069
Gitweb: http://git.kernel.org/tip/3cf224e4aa4a1f24361bce35b3bb54f553bee069
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:20:24 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 28 Mar 2009 12:51:41 +0100
blktrace: fix memory leak when freeing struct blk_io_trace
Impact: fix mixed ioctl and ftrace-plugin blktrace use memory leak
When mixing the use of ioctl-based blktrace and ftrace-based blktrace,
we can leak memory in this way:
# btrace /dev/sda > /dev/null &
# echo 0 > /sys/block/sda/sda1/trace/enable
now we leak bt->dropped_file, bt->msg_file, bt->rchan...
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37E8.6070609@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 29 ++++++++++++-----------------
1 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8d6bd12..2f21d77 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -247,7 +247,7 @@ record_it:
static struct dentry *blk_tree_root;
static DEFINE_MUTEX(blk_tree_mutex);
-static void blk_trace_cleanup(struct blk_trace *bt)
+static void blk_trace_free(struct blk_trace *bt)
{
debugfs_remove(bt->msg_file);
debugfs_remove(bt->dropped_file);
@@ -255,6 +255,11 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
+}
+
+static void blk_trace_cleanup(struct blk_trace *bt)
+{
+ blk_trace_free(bt);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
}
@@ -410,11 +415,11 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (buts->name[i] == '/')
buts->name[i] = '_';
- ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
- goto err;
+ return -ENOMEM;
+ ret = -ENOMEM;
bt->sequence = alloc_percpu(unsigned long);
if (!bt->sequence)
goto err;
@@ -483,17 +488,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
return 0;
err:
- if (bt) {
- if (bt->msg_file)
- debugfs_remove(bt->msg_file);
- if (bt->dropped_file)
- debugfs_remove(bt->dropped_file);
- free_percpu(bt->sequence);
- free_percpu(bt->msg_data);
- if (bt->rchan)
- relay_close(bt->rchan);
- kfree(bt);
- }
+ blk_trace_free(bt);
return ret;
}
@@ -1091,6 +1086,7 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
+ blk_tracer_enabled = true;
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1098,18 +1094,17 @@ static int blk_tracer_init(struct trace_array *tr)
{
blk_tr = tr;
blk_tracer_start(tr);
- blk_tracer_enabled = true;
return 0;
}
static void blk_tracer_stop(struct trace_array *tr)
{
+ blk_tracer_enabled = false;
trace_flags |= TRACE_ITER_CONTEXT_INFO;
}
static void blk_tracer_reset(struct trace_array *tr)
{
- blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1250,7 +1245,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- kfree(bt);
+ blk_trace_free(bt);
return 0;
}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] trace: make argument 'mem' of trace_seq_putmem() const
2009-03-27 2:21 ` [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const Li Zefan
@ 2009-03-28 21:28 ` Li Zefan
2009-03-30 1:20 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-28 21:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: f45847ce7668620080f7eac1c2e78333e98c7fe6
Gitweb: http://git.kernel.org/tip/f45847ce7668620080f7eac1c2e78333e98c7fe6
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:21:00 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 28 Mar 2009 12:51:42 +0100
trace: make argument 'mem' of trace_seq_putmem() const
Impact: fix build warning
I passed a const value to trace_seq_putmem(), and I got compile warning.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC380C.4010700@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/trace_output.c | 6 +++---
kernel/trace/trace_output.h | 5 +++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 9c1ddd6..aeac358 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -147,7 +147,7 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c)
return 1;
}
-int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
{
if (len > ((PAGE_SIZE - 1) - s->len))
return 0;
@@ -158,10 +158,10 @@ int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
return len;
}
-int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
{
unsigned char hex[HEX_CHARS];
- unsigned char *data = mem;
+ const unsigned char *data = mem;
int i, j;
#ifdef __BIG_ENDIAN
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index d8cb8c9..9163021 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -33,8 +33,9 @@ extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
size_t cnt);
extern int trace_seq_puts(struct trace_seq *s, const char *str);
extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
-extern int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len);
-extern int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len);
+extern int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len);
+extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
+ size_t len);
extern void *trace_seq_reserve(struct trace_seq *s, size_t len);
extern int trace_seq_path(struct trace_seq *s, struct path *path);
extern int seq_print_userip_objs(const struct userstack_entry *entry,
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: extract duplidate code
2009-03-27 2:21 ` [PATCH 5/6] blktrace: extract duplidate code Li Zefan
@ 2009-03-28 21:28 ` Li Zefan
2009-03-30 1:20 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-28 21:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: e1eb6c441d543eb3de17c214e3adb11bdd83b10e
Gitweb: http://git.kernel.org/tip/e1eb6c441d543eb3de17c214e3adb11bdd83b10e
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:21:23 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 28 Mar 2009 12:51:42 +0100
blktrace: extract duplidate code
Impact: cleanup
blk_trace_event_print() and blk_tracer_print_line() share most of the code.
text data bss dec hex filename
8605 393 12 9010 2332 kernel/trace/blktrace.o.orig
text data bss dec hex filename
8555 393 12 8960 2300 kernel/trace/blktrace.o
This patch also prepares for the next patch, that prints out BLK_TN_MESSAGE.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC3823.7010904@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 62 ++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 2f21d77..c103b0c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -986,29 +986,31 @@ static void get_pdu_remap(const struct trace_entry *ent,
r->sector = be64_to_cpu(sector);
}
-static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
+typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act);
+
+static int blk_log_action_classic(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
unsigned long long ts = iter->ts;
unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
unsigned secs = (unsigned long)ts;
- const struct trace_entry *ent = iter->ent;
- const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
+ const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
fill_rwbs(rwbs, t);
return trace_seq_printf(&iter->seq,
"%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
MAJOR(t->device), MINOR(t->device), iter->cpu,
- secs, nsec_rem, ent->pid, act, rwbs);
+ secs, nsec_rem, iter->ent->pid, act, rwbs);
}
-static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
- const char *act)
+static int blk_log_action(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
+ const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
+
fill_rwbs(rwbs, t);
- return trace_seq_printf(s, "%3d,%-3d %2s %3s ",
+ return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ",
MAJOR(t->device), MINOR(t->device), act, rwbs);
}
@@ -1129,22 +1131,25 @@ static const struct {
[__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap },
};
-static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
- int flags)
+static enum print_line_t print_one_line(struct trace_iterator *iter,
+ bool classic)
{
struct trace_seq *s = &iter->seq;
- const struct blk_io_trace *t = (struct blk_io_trace *)iter->ent;
- const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ const struct blk_io_trace *t;
+ u16 what;
int ret;
+ bool long_act;
+ blk_log_action_t *log_action;
- if (!trace_print_context(iter))
- return TRACE_TYPE_PARTIAL_LINE;
+ t = te_blk_io_trace(iter->ent);
+ what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
+ log_action = classic ? &blk_log_action_classic : &blk_log_action;
if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
ret = trace_seq_printf(s, "Bad pc action %x\n", what);
else {
- const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
- ret = blk_log_action_seq(s, t, what2act[what].act[long_act]);
+ ret = log_action(iter, what2act[what].act[long_act]);
if (ret)
ret = what2act[what].print(s, iter->ent);
}
@@ -1152,6 +1157,15 @@ static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
}
+static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
+ int flags)
+{
+ if (!trace_print_context(iter))
+ return TRACE_TYPE_PARTIAL_LINE;
+
+ return print_one_line(iter, false);
+}
+
static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
{
struct trace_seq *s = &iter->seq;
@@ -1177,26 +1191,10 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags)
static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)
{
- const struct blk_io_trace *t;
- u16 what;
- int ret;
-
if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
return TRACE_TYPE_UNHANDLED;
- t = (const struct blk_io_trace *)iter->ent;
- what = t->action & ((1 << BLK_TC_SHIFT) - 1);
-
- if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
- ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what);
- else {
- const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
- ret = blk_log_action_iter(iter, what2act[what].act[long_act]);
- if (ret)
- ret = what2act[what].print(&iter->seq, iter->ent);
- }
-
- return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
+ return print_one_line(iter, true);
}
static struct tracer blk_tracer __read_mostly = {
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: print out BLK_TN_MESSAGE properly
2009-03-27 2:21 ` [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
@ 2009-03-28 21:28 ` Li Zefan
2009-03-30 1:20 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-28 21:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 10d19f051b0e16475a0bc34d6aa0bff2df35e45f
Gitweb: http://git.kernel.org/tip/10d19f051b0e16475a0bc34d6aa0bff2df35e45f
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:21:54 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 28 Mar 2009 12:51:43 +0100
blktrace: print out BLK_TN_MESSAGE properly
Impact: improve ftrace plugin output
Before this patch:
# cat trace
make-5383 [001] 741.240059: 8,7 P N [make]
__trace_note_message: cfq1074
# echo 1 > options/blk_classic
# cat trace
8,7 1 0.692221252 0 C W 130411392 + 1024 [0]
Bad pc action 6361
Bad pc action 283d
# echo 0 > options/blk_classic
# echo bin > trace_options
# cat trace_pipe | blkparse -i -
(can't parse messages generated by blk_add_trace_msg())
After this patch:
# cat trace
<idle>-0 [001] 187.600933: 8,7 C W 145220224 + 8 [0]
<idle>-0 [001] 187.600946: 8,7 m N cfq1076 complete
# echo 1 > options/blk_classic
# cat trace
8,7 1 0.256378996 238 I W 113190728 + 8 [pdflush]
8,7 1 0.256378998 238 m N cfq1076 insert_request
# echo 0 > options/blk_classic
# echo bin > trace_options
# cat trace_pipe | blkparse -i -
8,7 1 0 22.973250293 0 C W 102770576 + 8 [0]
8,7 1 0 22.973259213 0 m N cfq1076 complete
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC3842.60608@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 80 +++++++++++++++++++++++++++++++++++-----------
1 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c103b0c..947c5b3 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -59,22 +59,39 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
const void *data, size_t len)
{
struct blk_io_trace *t;
+ struct ring_buffer_event *event = NULL;
+ int pc = 0;
+ int cpu = smp_processor_id();
+ bool blk_tracer = blk_tracer_enabled;
+
+ if (blk_tracer) {
+ pc = preempt_count();
+ event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK,
+ sizeof(*t) + len,
+ 0, pc);
+ if (!event)
+ return;
+ t = ring_buffer_event_data(event);
+ goto record_it;
+ }
if (!bt->rchan)
return;
t = relay_reserve(bt->rchan, sizeof(*t) + len);
if (t) {
- const int cpu = smp_processor_id();
-
t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
t->time = ktime_to_ns(ktime_get());
+record_it:
t->device = bt->dev;
t->action = action;
t->pid = pid;
t->cpu = cpu;
t->pdu_len = len;
memcpy((void *) t + sizeof(*t), data, len);
+
+ if (blk_tracer)
+ trace_buffer_unlock_commit(blk_tr, event, 0, pc);
}
}
@@ -110,14 +127,8 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
unsigned long flags;
char *buf;
- if (blk_tracer_enabled) {
- va_start(args, fmt);
- ftrace_vprintk(fmt, args);
- va_end(args);
- return;
- }
-
- if (!bt->msg_data)
+ if (unlikely(bt->trace_state != Blktrace_running &&
+ !blk_tracer_enabled))
return;
local_irq_save(flags);
@@ -168,9 +179,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
unsigned long *sequence;
pid_t pid;
int cpu, pc = 0;
+ bool blk_tracer = blk_tracer_enabled;
- if (unlikely(bt->trace_state != Blktrace_running &&
- !blk_tracer_enabled))
+ if (unlikely(bt->trace_state != Blktrace_running && !blk_tracer))
return;
what |= ddir_act[rw & WRITE];
@@ -185,7 +196,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
return;
cpu = raw_smp_processor_id();
- if (blk_tracer_enabled) {
+ if (blk_tracer) {
tracing_record_cmdline(current);
pc = preempt_count();
@@ -235,7 +246,7 @@ record_it:
if (pdu_len)
memcpy((void *) t + sizeof(*t), pdu_data, pdu_len);
- if (blk_tracer_enabled) {
+ if (blk_tracer) {
trace_buffer_unlock_commit(blk_tr, event, 0, pc);
return;
}
@@ -922,6 +933,11 @@ static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
int i = 0;
int tc = t->action >> BLK_TC_SHIFT;
+ if (t->action == BLK_TN_MESSAGE) {
+ rwbs[i++] = 'N';
+ goto out;
+ }
+
if (tc & BLK_TC_DISCARD)
rwbs[i++] = 'D';
else if (tc & BLK_TC_WRITE)
@@ -939,7 +955,7 @@ static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
rwbs[i++] = 'S';
if (tc & BLK_TC_META)
rwbs[i++] = 'M';
-
+out:
rwbs[i] = '\0';
}
@@ -1074,6 +1090,17 @@ static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent)
get_pdu_int(ent), cmd);
}
+static int blk_log_msg(struct trace_seq *s, const struct trace_entry *ent)
+{
+ int ret;
+ const struct blk_io_trace *t = te_blk_io_trace(ent);
+
+ ret = trace_seq_putmem(s, t + 1, t->pdu_len);
+ if (ret)
+ return trace_seq_putc(s, '\n');
+ return ret;
+}
+
/*
* struct tracer operations
*/
@@ -1146,6 +1173,13 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
log_action = classic ? &blk_log_action_classic : &blk_log_action;
+ if (t->action == BLK_TN_MESSAGE) {
+ ret = log_action(iter, long_act ? "message" : "m");
+ if (ret)
+ ret = blk_log_msg(s, iter->ent);
+ goto out;
+ }
+
if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
ret = trace_seq_printf(s, "Bad pc action %x\n", what);
else {
@@ -1153,7 +1187,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
if (ret)
ret = what2act[what].print(s, iter->ent);
}
-
+out:
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
}
@@ -1253,11 +1287,16 @@ static int blk_trace_remove_queue(struct request_queue *q)
static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
{
struct blk_trace *old_bt, *bt = NULL;
+ int ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
return -ENOMEM;
+ bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
+ if (!bt->msg_data)
+ goto free_bt;
+
bt->dev = dev;
bt->act_mask = (u16)-1;
bt->end_lba = -1ULL;
@@ -1265,14 +1304,17 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
old_bt = xchg(&q->blk_trace, bt);
if (old_bt != NULL) {
(void)xchg(&q->blk_trace, old_bt);
- kfree(bt);
- return -EBUSY;
+ ret = -EBUSY;
+ goto free_bt;
}
if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
-
return 0;
+
+free_bt:
+ blk_trace_free(bt);
+ return ret;
}
/*
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: make classic output more classic
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
2009-03-27 3:30 ` Li Zefan
2009-03-28 21:27 ` [tip:tracing/blktrace] " Li Zefan
@ 2009-03-30 1:19 ` Li Zefan
2 siblings, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-30 1:19 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 300dc4f1581ef42567a90cb640d994d24d41bf9c
Gitweb: http://git.kernel.org/tip/300dc4f1581ef42567a90cb640d994d24d41bf9c
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:19:46 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:15:42 +0200
blktrace: make classic output more classic
Impact: fix ftrace plugin timestamp output
In the classic user-space blktrace, the output timestamp is sec.nsec
not sec.usec.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37C2.7050307@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index d43cdac..5b28f0f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -994,8 +994,8 @@ static void get_pdu_remap(const struct trace_entry *ent,
static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
- unsigned long long ts = ns2usecs(iter->ts);
- unsigned long usec_rem = do_div(ts, USEC_PER_SEC);
+ unsigned long long ts = iter->ts;
+ unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
unsigned secs = (unsigned long)ts;
const struct trace_entry *ent = iter->ent;
const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
@@ -1003,9 +1003,9 @@ static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
fill_rwbs(rwbs, t);
return trace_seq_printf(&iter->seq,
- "%3d,%-3d %2d %5d.%06lu %5u %2s %3s ",
+ "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
MAJOR(t->device), MINOR(t->device), iter->cpu,
- secs, usec_rem, ent->pid, act, rwbs);
+ secs, nsec_rem, ent->pid, act, rwbs);
}
static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: fix blk_probes_ref chaos
2009-03-27 2:20 ` [PATCH 2/6] blktrace: fix blk_probes_ref chaos Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
@ 2009-03-30 1:19 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-30 1:19 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: e465dbcc55d36b37af55d95a279f352a3f517279
Gitweb: http://git.kernel.org/tip/e465dbcc55d36b37af55d95a279f352a3f517279
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:20:09 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:15:50 +0200
blktrace: fix blk_probes_ref chaos
Impact: fix mixed ioctl and ftrace-plugin blktrace use refcount bugs
ioctl-based blktrace allocates bt and registers tracepoints when
ioctl(BLKTRACESETUP), and do all cleanups when ioctl(BLKTRACETEARDOWN).
while ftrace-based blktrace allocates/frees bt when:
# echo 1/0 > /sys/block/sda/sda1/trace/enable
and registers/unregisters tracepoints when:
# echo blk/nop > /debugfs/tracing/current_tracer
or
# echo 1/0 > /debugfs/tracing/tracing_enable
The separatation of allocation and registeration causes 2 problems:
1. current user-space blktrace still calls ioctl(TEARDOWN) when
ioctl(SETUP) failed:
# echo 1 > /sys/block/sda/sda1/trace/enable
# blktrace /dev/sda
BLKTRACESETUP: Device or resource busy
^C
and now blk_probes_ref == -1
2. Another way to make blk_probes_ref == -1:
# plugin sdb && mount sdb1
# echo 1 > /sys/block/sdb/sdb1/trace/enable
# remove sdb
This patch does the allocation and registeration when writing
sdaX/trace/enable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37D9.6030201@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 5b28f0f..8d6bd12 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -478,7 +478,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
goto err;
}
- if (atomic_add_return(1, &blk_probes_ref) == 1)
+ if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
return 0;
@@ -1091,8 +1091,6 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- if (atomic_add_return(1, &blk_probes_ref) == 1)
- blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1107,15 +1105,10 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
}
static void blk_tracer_reset(struct trace_array *tr)
{
- if (!atomic_read(&blk_probes_ref))
- return;
-
blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1254,6 +1247,9 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (bt == NULL)
return -EINVAL;
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+
kfree(bt);
return 0;
}
@@ -1280,6 +1276,9 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
return -EBUSY;
}
+ if (atomic_inc_return(&blk_probes_ref) == 1)
+ blk_register_tracepoints();
+
return 0;
}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: fix memory leak when freeing struct blk_io_trace
2009-03-27 2:20 ` [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
@ 2009-03-30 1:19 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-30 1:19 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 5dec363daed91bff6d01dec5f6ce80085b91e311
Gitweb: http://git.kernel.org/tip/5dec363daed91bff6d01dec5f6ce80085b91e311
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:20:24 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:16:00 +0200
blktrace: fix memory leak when freeing struct blk_io_trace
Impact: fix mixed ioctl and ftrace-plugin blktrace use memory leak
When mixing the use of ioctl-based blktrace and ftrace-based blktrace,
we can leak memory in this way:
# btrace /dev/sda > /dev/null &
# echo 0 > /sys/block/sda/sda1/trace/enable
now we leak bt->dropped_file, bt->msg_file, bt->rchan...
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37E8.6070609@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 29 ++++++++++++-----------------
1 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8d6bd12..2f21d77 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -247,7 +247,7 @@ record_it:
static struct dentry *blk_tree_root;
static DEFINE_MUTEX(blk_tree_mutex);
-static void blk_trace_cleanup(struct blk_trace *bt)
+static void blk_trace_free(struct blk_trace *bt)
{
debugfs_remove(bt->msg_file);
debugfs_remove(bt->dropped_file);
@@ -255,6 +255,11 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
+}
+
+static void blk_trace_cleanup(struct blk_trace *bt)
+{
+ blk_trace_free(bt);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
}
@@ -410,11 +415,11 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (buts->name[i] == '/')
buts->name[i] = '_';
- ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
- goto err;
+ return -ENOMEM;
+ ret = -ENOMEM;
bt->sequence = alloc_percpu(unsigned long);
if (!bt->sequence)
goto err;
@@ -483,17 +488,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
return 0;
err:
- if (bt) {
- if (bt->msg_file)
- debugfs_remove(bt->msg_file);
- if (bt->dropped_file)
- debugfs_remove(bt->dropped_file);
- free_percpu(bt->sequence);
- free_percpu(bt->msg_data);
- if (bt->rchan)
- relay_close(bt->rchan);
- kfree(bt);
- }
+ blk_trace_free(bt);
return ret;
}
@@ -1091,6 +1086,7 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
+ blk_tracer_enabled = true;
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1098,18 +1094,17 @@ static int blk_tracer_init(struct trace_array *tr)
{
blk_tr = tr;
blk_tracer_start(tr);
- blk_tracer_enabled = true;
return 0;
}
static void blk_tracer_stop(struct trace_array *tr)
{
+ blk_tracer_enabled = false;
trace_flags |= TRACE_ITER_CONTEXT_INFO;
}
static void blk_tracer_reset(struct trace_array *tr)
{
- blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1250,7 +1245,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- kfree(bt);
+ blk_trace_free(bt);
return 0;
}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] trace: make argument 'mem' of trace_seq_putmem() const
2009-03-27 2:21 ` [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
@ 2009-03-30 1:20 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-30 1:20 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: a8168d4a50145652812866390939ae6774627a8e
Gitweb: http://git.kernel.org/tip/a8168d4a50145652812866390939ae6774627a8e
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:21:00 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:16:16 +0200
trace: make argument 'mem' of trace_seq_putmem() const
Impact: fix build warning
I passed a const value to trace_seq_putmem(), and I got compile warning.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC380C.4010700@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/trace_output.c | 6 +++---
kernel/trace/trace_output.h | 5 +++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 9c1ddd6..aeac358 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -147,7 +147,7 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c)
return 1;
}
-int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
{
if (len > ((PAGE_SIZE - 1) - s->len))
return 0;
@@ -158,10 +158,10 @@ int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
return len;
}
-int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
{
unsigned char hex[HEX_CHARS];
- unsigned char *data = mem;
+ const unsigned char *data = mem;
int i, j;
#ifdef __BIG_ENDIAN
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index d8cb8c9..9163021 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -33,8 +33,9 @@ extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
size_t cnt);
extern int trace_seq_puts(struct trace_seq *s, const char *str);
extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
-extern int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len);
-extern int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len);
+extern int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len);
+extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
+ size_t len);
extern void *trace_seq_reserve(struct trace_seq *s, size_t len);
extern int trace_seq_path(struct trace_seq *s, struct path *path);
extern int seq_print_userip_objs(const struct userstack_entry *entry,
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: extract duplidate code
2009-03-27 2:21 ` [PATCH 5/6] blktrace: extract duplidate code Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
@ 2009-03-30 1:20 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-30 1:20 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 1c80ad012bad2fe4662aae2534b3d7d5cf362ef8
Gitweb: http://git.kernel.org/tip/1c80ad012bad2fe4662aae2534b3d7d5cf362ef8
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:21:23 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:16:24 +0200
blktrace: extract duplidate code
Impact: cleanup
blk_trace_event_print() and blk_tracer_print_line() share most of the code.
text data bss dec hex filename
8605 393 12 9010 2332 kernel/trace/blktrace.o.orig
text data bss dec hex filename
8555 393 12 8960 2300 kernel/trace/blktrace.o
This patch also prepares for the next patch, that prints out BLK_TN_MESSAGE.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC3823.7010904@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 62 ++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 2f21d77..c103b0c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -986,29 +986,31 @@ static void get_pdu_remap(const struct trace_entry *ent,
r->sector = be64_to_cpu(sector);
}
-static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
+typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act);
+
+static int blk_log_action_classic(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
unsigned long long ts = iter->ts;
unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
unsigned secs = (unsigned long)ts;
- const struct trace_entry *ent = iter->ent;
- const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
+ const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
fill_rwbs(rwbs, t);
return trace_seq_printf(&iter->seq,
"%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
MAJOR(t->device), MINOR(t->device), iter->cpu,
- secs, nsec_rem, ent->pid, act, rwbs);
+ secs, nsec_rem, iter->ent->pid, act, rwbs);
}
-static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
- const char *act)
+static int blk_log_action(struct trace_iterator *iter, const char *act)
{
char rwbs[6];
+ const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
+
fill_rwbs(rwbs, t);
- return trace_seq_printf(s, "%3d,%-3d %2s %3s ",
+ return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ",
MAJOR(t->device), MINOR(t->device), act, rwbs);
}
@@ -1129,22 +1131,25 @@ static const struct {
[__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap },
};
-static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
- int flags)
+static enum print_line_t print_one_line(struct trace_iterator *iter,
+ bool classic)
{
struct trace_seq *s = &iter->seq;
- const struct blk_io_trace *t = (struct blk_io_trace *)iter->ent;
- const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ const struct blk_io_trace *t;
+ u16 what;
int ret;
+ bool long_act;
+ blk_log_action_t *log_action;
- if (!trace_print_context(iter))
- return TRACE_TYPE_PARTIAL_LINE;
+ t = te_blk_io_trace(iter->ent);
+ what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
+ log_action = classic ? &blk_log_action_classic : &blk_log_action;
if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
ret = trace_seq_printf(s, "Bad pc action %x\n", what);
else {
- const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
- ret = blk_log_action_seq(s, t, what2act[what].act[long_act]);
+ ret = log_action(iter, what2act[what].act[long_act]);
if (ret)
ret = what2act[what].print(s, iter->ent);
}
@@ -1152,6 +1157,15 @@ static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
}
+static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
+ int flags)
+{
+ if (!trace_print_context(iter))
+ return TRACE_TYPE_PARTIAL_LINE;
+
+ return print_one_line(iter, false);
+}
+
static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
{
struct trace_seq *s = &iter->seq;
@@ -1177,26 +1191,10 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags)
static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)
{
- const struct blk_io_trace *t;
- u16 what;
- int ret;
-
if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
return TRACE_TYPE_UNHANDLED;
- t = (const struct blk_io_trace *)iter->ent;
- what = t->action & ((1 << BLK_TC_SHIFT) - 1);
-
- if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
- ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what);
- else {
- const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
- ret = blk_log_action_iter(iter, what2act[what].act[long_act]);
- if (ret)
- ret = what2act[what].print(&iter->seq, iter->ent);
- }
-
- return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
+ return print_one_line(iter, true);
}
static struct tracer blk_tracer __read_mostly = {
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip:tracing/blktrace] blktrace: print out BLK_TN_MESSAGE properly
2009-03-27 2:21 ` [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
@ 2009-03-30 1:20 ` Li Zefan
1 sibling, 0 replies; 20+ messages in thread
From: Li Zefan @ 2009-03-30 1:20 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, acme, hpa, mingo, lizf, jens.axboe, fweisbec,
rostedt, tglx, mingo
Commit-ID: 36edcee82b04a201500529ec1257a303ad002e7d
Gitweb: http://git.kernel.org/tip/36edcee82b04a201500529ec1257a303ad002e7d
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:21:54 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:16:32 +0200
blktrace: print out BLK_TN_MESSAGE properly
Impact: improve ftrace plugin output
Before this patch:
# cat trace
make-5383 [001] 741.240059: 8,7 P N [make]
__trace_note_message: cfq1074
# echo 1 > options/blk_classic
# cat trace
8,7 1 0.692221252 0 C W 130411392 + 1024 [0]
Bad pc action 6361
Bad pc action 283d
# echo 0 > options/blk_classic
# echo bin > trace_options
# cat trace_pipe | blkparse -i -
(can't parse messages generated by blk_add_trace_msg())
After this patch:
# cat trace
<idle>-0 [001] 187.600933: 8,7 C W 145220224 + 8 [0]
<idle>-0 [001] 187.600946: 8,7 m N cfq1076 complete
# echo 1 > options/blk_classic
# cat trace
8,7 1 0.256378996 238 I W 113190728 + 8 [pdflush]
8,7 1 0.256378998 238 m N cfq1076 insert_request
# echo 0 > options/blk_classic
# echo bin > trace_options
# cat trace_pipe | blkparse -i -
8,7 1 0 22.973250293 0 C W 102770576 + 8 [0]
8,7 1 0 22.973259213 0 m N cfq1076 complete
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC3842.60608@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 80 +++++++++++++++++++++++++++++++++++-----------
1 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c103b0c..947c5b3 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -59,22 +59,39 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
const void *data, size_t len)
{
struct blk_io_trace *t;
+ struct ring_buffer_event *event = NULL;
+ int pc = 0;
+ int cpu = smp_processor_id();
+ bool blk_tracer = blk_tracer_enabled;
+
+ if (blk_tracer) {
+ pc = preempt_count();
+ event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK,
+ sizeof(*t) + len,
+ 0, pc);
+ if (!event)
+ return;
+ t = ring_buffer_event_data(event);
+ goto record_it;
+ }
if (!bt->rchan)
return;
t = relay_reserve(bt->rchan, sizeof(*t) + len);
if (t) {
- const int cpu = smp_processor_id();
-
t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
t->time = ktime_to_ns(ktime_get());
+record_it:
t->device = bt->dev;
t->action = action;
t->pid = pid;
t->cpu = cpu;
t->pdu_len = len;
memcpy((void *) t + sizeof(*t), data, len);
+
+ if (blk_tracer)
+ trace_buffer_unlock_commit(blk_tr, event, 0, pc);
}
}
@@ -110,14 +127,8 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
unsigned long flags;
char *buf;
- if (blk_tracer_enabled) {
- va_start(args, fmt);
- ftrace_vprintk(fmt, args);
- va_end(args);
- return;
- }
-
- if (!bt->msg_data)
+ if (unlikely(bt->trace_state != Blktrace_running &&
+ !blk_tracer_enabled))
return;
local_irq_save(flags);
@@ -168,9 +179,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
unsigned long *sequence;
pid_t pid;
int cpu, pc = 0;
+ bool blk_tracer = blk_tracer_enabled;
- if (unlikely(bt->trace_state != Blktrace_running &&
- !blk_tracer_enabled))
+ if (unlikely(bt->trace_state != Blktrace_running && !blk_tracer))
return;
what |= ddir_act[rw & WRITE];
@@ -185,7 +196,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
return;
cpu = raw_smp_processor_id();
- if (blk_tracer_enabled) {
+ if (blk_tracer) {
tracing_record_cmdline(current);
pc = preempt_count();
@@ -235,7 +246,7 @@ record_it:
if (pdu_len)
memcpy((void *) t + sizeof(*t), pdu_data, pdu_len);
- if (blk_tracer_enabled) {
+ if (blk_tracer) {
trace_buffer_unlock_commit(blk_tr, event, 0, pc);
return;
}
@@ -922,6 +933,11 @@ static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
int i = 0;
int tc = t->action >> BLK_TC_SHIFT;
+ if (t->action == BLK_TN_MESSAGE) {
+ rwbs[i++] = 'N';
+ goto out;
+ }
+
if (tc & BLK_TC_DISCARD)
rwbs[i++] = 'D';
else if (tc & BLK_TC_WRITE)
@@ -939,7 +955,7 @@ static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
rwbs[i++] = 'S';
if (tc & BLK_TC_META)
rwbs[i++] = 'M';
-
+out:
rwbs[i] = '\0';
}
@@ -1074,6 +1090,17 @@ static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent)
get_pdu_int(ent), cmd);
}
+static int blk_log_msg(struct trace_seq *s, const struct trace_entry *ent)
+{
+ int ret;
+ const struct blk_io_trace *t = te_blk_io_trace(ent);
+
+ ret = trace_seq_putmem(s, t + 1, t->pdu_len);
+ if (ret)
+ return trace_seq_putc(s, '\n');
+ return ret;
+}
+
/*
* struct tracer operations
*/
@@ -1146,6 +1173,13 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
log_action = classic ? &blk_log_action_classic : &blk_log_action;
+ if (t->action == BLK_TN_MESSAGE) {
+ ret = log_action(iter, long_act ? "message" : "m");
+ if (ret)
+ ret = blk_log_msg(s, iter->ent);
+ goto out;
+ }
+
if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
ret = trace_seq_printf(s, "Bad pc action %x\n", what);
else {
@@ -1153,7 +1187,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
if (ret)
ret = what2act[what].print(s, iter->ent);
}
-
+out:
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
}
@@ -1253,11 +1287,16 @@ static int blk_trace_remove_queue(struct request_queue *q)
static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
{
struct blk_trace *old_bt, *bt = NULL;
+ int ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
return -ENOMEM;
+ bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
+ if (!bt->msg_data)
+ goto free_bt;
+
bt->dev = dev;
bt->act_mask = (u16)-1;
bt->end_lba = -1ULL;
@@ -1265,14 +1304,17 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
old_bt = xchg(&q->blk_trace, bt);
if (old_bt != NULL) {
(void)xchg(&q->blk_trace, old_bt);
- kfree(bt);
- return -EBUSY;
+ ret = -EBUSY;
+ goto free_bt;
}
if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
-
return 0;
+
+free_bt:
+ blk_trace_free(bt);
+ return ret;
}
/*
^ permalink raw reply related [flat|nested] 20+ messages in thread
end of thread, other threads:[~2009-03-30 1:22 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
2009-03-27 3:30 ` Li Zefan
2009-03-28 21:27 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:20 ` [PATCH 2/6] blktrace: fix blk_probes_ref chaos Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:20 ` [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:21 ` [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
2009-03-27 2:21 ` [PATCH 5/6] blktrace: extract duplidate code Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
2009-03-27 2:21 ` [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox