2009-07-22 03:21:40

by Xiao Guangrong

[permalink] [raw]
Subject: [PATCH 1/3] tracing/ksym_tracer: fix the output of ksym tracer

Fix the output format of ksym tracer, make it properly aligned

Befor patch:
# tracer: ksym_tracer
#
# TASK-PID CPU# Symbol Type Function
# | | | | |
bash 1378 1 ksym_tracer_mutex W mutex_lock+0x11/0x27
bash 1378 1 ksym_filter_head W process_new_ksym_entry+0xd2/0x10c
bash 1378 1 ksym_tracer_mutex W mutex_unlock+0x12/0x1b
cat 1429 0 ksym_tracer_mutex W mutex_lock+0x11/0x27

After patch:
# tracer: ksym_tracer
#
# TASK-PID CPU# Symbol Type Function
# | | | | |
cat-1423 [000] ksym_tracer_mutex RW mutex_lock+0x11/0x27
cat-1423 [000] ksym_filter_head RW ksym_trace_filter_read+0x6e/0x10d
cat-1423 [000] ksym_tracer_mutex RW mutex_unlock+0x12/0x1b
cat-1423 [000] ksym_tracer_mutex RW mutex_lock+0x11/0x27
cat-1423 [000] ksym_filter_head RW ksym_trace_filter_read+0x6e/0x10d
cat-1423 [000] ksym_tracer_mutex RW mutex_unlock+0x12/0x1b

Signed-off-by: Xiao Guangrong <[email protected]>
---
kernel/trace/trace_ksym.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index 1256a6e..fbf3a8e 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -370,13 +370,12 @@ static int ksym_trace_init(struct trace_array *tr)

static void ksym_trace_print_header(struct seq_file *m)
{
-
seq_puts(m,
- "# TASK-PID CPU# Symbol Type "
- "Function \n");
+ "# TASK-PID CPU# Symbol "
+ "Type Function\n");
seq_puts(m,
- "# | | | | "
- "| \n");
+ "# | | | "
+ " | |\n");
}

static enum print_line_t ksym_trace_output(struct trace_iterator *iter)
@@ -392,7 +391,7 @@ static enum print_line_t ksym_trace_output(struct trace_iterator *iter)

trace_assign_type(field, entry);

- ret = trace_seq_printf(s, "%-15s %-5d %-3d %-20s ", field->cmd,
+ ret = trace_seq_printf(s, "%11s-%-5d [%03d] %-30s ", field->cmd,
entry->pid, iter->cpu, field->ksym_name);
if (!ret)
return TRACE_TYPE_PARTIAL_LINE;
@@ -412,7 +411,7 @@ static enum print_line_t ksym_trace_output(struct trace_iterator *iter)
return TRACE_TYPE_PARTIAL_LINE;

sprint_symbol(str, field->ip);
- ret = trace_seq_printf(s, "%-20s\n", str);
+ ret = trace_seq_printf(s, "%s\n", str);
if (!ret)
return TRACE_TYPE_PARTIAL_LINE;

--
1.6.1.2


2009-07-22 03:23:48

by Xiao Guangrong

[permalink] [raw]
Subject: [PATCH 2/3] tracing/ksym_tracer: fix write operation of ksym_trace_filter

This patch fix 2 bugs:
- fix the return value of ksym_trace_filter_write() when we want to
clear symbol in ksym_trace_filter file
for example:
# echo global_trace:rw- > /debug/tracing/ksym_trace_filter
# echo global_trace:--- > /debug/tracing/ksym_trace_filter
-bash: echo: write error: Invalid argument
# cat /debug/tracing/ksym_trace_filter
#
We want to clear 'global_trace' in ksym_trace_filter, it complain
with "Invalid argument", but the operation is successful

- the "r--" access types is not allowed, but ksym_trace_filter file think
it OK
for example:
# echo ksym_tracer_mutex:r-- > ksym_trace_filter
-bash: echo: write error: Resource temporarily unavailable
# dmesg
ksym_tracer request failed. Try again later!!

The error occur at register_kernel_hw_breakpoint(), but It's should
at access types parser

Signed-off-by: Xiao Guangrong <[email protected]>
---
kernel/trace/trace_ksym.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index fbf3a8e..cd5cb65 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -135,6 +135,9 @@ static int ksym_trace_get_access_type(char *str)
case 6:
access = HW_BREAKPOINT_RW;
break;
+ case 4:
+ access = -EINVAL;
+ break;
case 2:
access = HW_BREAKPOINT_WRITE;
break;
@@ -312,6 +315,7 @@ static ssize_t ksym_trace_filter_write(struct file *file,
kfree(entry->ksym_hbp->info.name);
kfree(entry->ksym_hbp);
kfree(entry);
+ ret = 0;
goto out;
} else {
/* Check for malformed request: (4) */
--
1.6.1.2

2009-07-22 03:25:22

by Xiao Guangrong

[permalink] [raw]
Subject: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter

It's rather bored to clear symbol one by one in ksym_trace_filter
file, so, this patch can let ksym_trace_filter file support quick
clear, we can write "0" to this file, it can clear all symbols

for example:
# cat ksym_trace_filter
ksym_filter_head:rw-
global_trace:rw-
# echo 0 > ksym_trace_filter
# cat ksym_trace_filter
#

Signed-off-by: Xiao Guangrong <[email protected]>
---
kernel/trace/trace_ksym.c | 45 +++++++++++++++++++++++++++------------------
1 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index cd5cb65..96b9e19 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -163,8 +163,6 @@ static int parse_ksym_trace_str(char *input_string, char **ksymname,
{
int ret;

- strstrip(input_string);
-
*ksymname = strsep(&input_string, ":");
*addr = kallsyms_lookup_name(*ksymname);

@@ -262,6 +260,25 @@ static ssize_t ksym_trace_filter_read(struct file *filp, char __user *ubuf,
return cnt;
}

+static void __ksym_trace_reset(void)
+{
+ struct trace_ksym *entry;
+ struct hlist_node *node, *node1;
+
+ mutex_lock(&ksym_tracer_mutex);
+ hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
+ ksym_hlist) {
+ unregister_kernel_hw_breakpoint(entry->ksym_hbp);
+ ksym_filter_entry_count--;
+ hlist_del_rcu(&(entry->ksym_hlist));
+ synchronize_rcu();
+ kfree(entry->ksym_hbp->info.name);
+ kfree(entry->ksym_hbp);
+ kfree(entry);
+ }
+ mutex_unlock(&ksym_tracer_mutex);
+}
+
static ssize_t ksym_trace_filter_write(struct file *file,
const char __user *buffer,
size_t count, loff_t *ppos)
@@ -282,6 +299,13 @@ static ssize_t ksym_trace_filter_write(struct file *file,
}
input_string[count] = '\0';

+ strstrip(input_string);
+ if (!strcmp(input_string, "0")) {
+ __ksym_trace_reset();
+ kfree(input_string);
+ return count;
+ }
+
ret = op = parse_ksym_trace_str(input_string, &ksymname, &ksym_addr);
if (ret < 0) {
kfree(input_string);
@@ -341,23 +365,8 @@ static const struct file_operations ksym_tracing_fops = {

static void ksym_trace_reset(struct trace_array *tr)
{
- struct trace_ksym *entry;
- struct hlist_node *node, *node1;
-
ksym_tracing_enabled = 0;
-
- mutex_lock(&ksym_tracer_mutex);
- hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
- ksym_hlist) {
- unregister_kernel_hw_breakpoint(entry->ksym_hbp);
- ksym_filter_entry_count--;
- hlist_del_rcu(&(entry->ksym_hlist));
- synchronize_rcu();
- kfree(entry->ksym_hbp->info.name);
- kfree(entry->ksym_hbp);
- kfree(entry);
- }
- mutex_unlock(&ksym_tracer_mutex);
+ __ksym_trace_reset();
}

static int ksym_trace_init(struct trace_array *tr)
--
1.6.1.2

2009-07-22 05:08:48

by K.Prasad

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter

On Wed, Jul 22, 2009 at 11:25:14AM +0800, Xiao Guangrong wrote:
> It's rather bored to clear symbol one by one in ksym_trace_filter
> file, so, this patch can let ksym_trace_filter file support quick
> clear, we can write "0" to this file, it can clear all symbols
>
> for example:
> # cat ksym_trace_filter
> ksym_filter_head:rw-
> global_trace:rw-
> # echo 0 > ksym_trace_filter
> # cat ksym_trace_filter
> #
>

It's nice to have this feature added and the other patches fix issues in
ksym tracer. Can you have this patch add the capability to clear all
breakpoints in one-shot through wild-cards?

Ingo wanted something like "echo "*:---" > ksym_trace_filter". The patch
I sent here: http://lkml.org/lkml/2009/6/20/73 implements the same. You
may want to implement something on those lines.

Thanks,
K.Prasad

2009-07-22 09:57:01

by Xiao Guangrong

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter



K.Prasad wrote:
> On Wed, Jul 22, 2009 at 11:25:14AM +0800, Xiao Guangrong wrote:
>> It's rather bored to clear symbol one by one in ksym_trace_filter
>> file, so, this patch can let ksym_trace_filter file support quick
>> clear, we can write "0" to this file, it can clear all symbols
>>
>> for example:
>> # cat ksym_trace_filter
>> ksym_filter_head:rw-
>> global_trace:rw-
>> # echo 0 > ksym_trace_filter
>> # cat ksym_trace_filter
>> #
>>
>
> It's nice to have this feature added and the other patches fix issues in
> ksym tracer. Can you have this patch add the capability to clear all
> breakpoints in one-shot through wild-cards?
>

It already can clear all breakpoints in one-shot by write "0" to
ksym_trace_filter file, do you means that we need to support other
way for it? like:

echo > ksym_trace_filter
echo "*:---" > ksym_trace_filter

IMHO, one way to clear all breakpoints is enough, no need to add
more code for the same function, for example, in trace events filter,
only echo 0 > filter can properly clear all filters.

Are you sure other way is necessary?

Thanks,
Xiao

> Ingo wanted something like "echo "*:---" > ksym_trace_filter". The patch
> I sent here: http://lkml.org/lkml/2009/6/20/73 implements the same. You
> may want to implement something on those lines.
>
> Thanks,
> K.Prasad
>
>
>

2009-07-22 15:18:10

by K.Prasad

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter

On Wed, Jul 22, 2009 at 05:56:49PM +0800, Xiao Guangrong wrote:
>
>
> K.Prasad wrote:
> > On Wed, Jul 22, 2009 at 11:25:14AM +0800, Xiao Guangrong wrote:
> >> It's rather bored to clear symbol one by one in ksym_trace_filter
> >> file, so, this patch can let ksym_trace_filter file support quick
> >> clear, we can write "0" to this file, it can clear all symbols
> >>
> >> for example:
> >> # cat ksym_trace_filter
> >> ksym_filter_head:rw-
> >> global_trace:rw-
> >> # echo 0 > ksym_trace_filter
> >> # cat ksym_trace_filter
> >> #
> >>
> >
> > It's nice to have this feature added and the other patches fix issues in
> > ksym tracer. Can you have this patch add the capability to clear all
> > breakpoints in one-shot through wild-cards?
> >
>
> It already can clear all breakpoints in one-shot by write "0" to
> ksym_trace_filter file, do you means that we need to support other
> way for it? like:
>
> echo > ksym_trace_filter
> echo "*:---" > ksym_trace_filter
>
> IMHO, one way to clear all breakpoints is enough, no need to add
> more code for the same function, for example, in trace events filter,
> only echo 0 > filter can properly clear all filters.
>
> Are you sure other way is necessary?
>
> Thanks,
> Xiao
>

As I stated before, the ability to support
echo "*:---" > ksym_trace_filter was Ingo Molnar's suggestion, so if
he's not particular about having it now we may skip it.

However, given that it requires just a few lines of code in addition,
say

+ /* Clear all breakpoints if echo "*:---" > ksym_trace_filter */
+ if ((strncmp(ksymname, "*", strlen("*")) == 0) && (op == 0)) {
+ ksym_trace_reset(NULL);
+ kfree(input_string);
+ return count;
+ }

in ksym_trace_filter_write(), and that the patch is already present it
shouldn't be bothersome to add it.

Thanks,
K.Prasad

2009-07-23 00:50:50

by Xiao Guangrong

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter



K.Prasad wrote:

> As I stated before, the ability to support
> echo "*:---" > ksym_trace_filter was Ingo Molnar's suggestion, so if
> he's not particular about having it now we may skip it.
>

OK, I'll fix it.

> However, given that it requires just a few lines of code in addition,
> say
>
> + /* Clear all breakpoints if echo "*:---" > ksym_trace_filter */
> + if ((strncmp(ksymname, "*", strlen("*")) == 0) && (op == 0)) {
> + ksym_trace_reset(NULL);
> + kfree(input_string);
> + return count;
> + }
>

I think below way is simpler:

+ /*
+ /* Clear all breakpoints if:
+ /* 1: echo > ksym_trace_filter
+ /* 2: echo 0 > ksym_trace_filter
+ /* 3: echo "*:---" > ksym_trace_filter
+ */
+ strstrip(input_string);
+ if (!input_string[0] || !strcmp(input_string, "0") ||
+ (!strcmp(input, "*:---")) {
+ __ksym_trace_reset();
+ kfree(input_string);
+ return count;
+ }
+

I'll sent a new patch after do some test for it.

Thanks,
Xiao

> in ksym_trace_filter_write(), and that the patch is already present it
> shouldn't be bothersome to add it.
>
> Thanks,
> K.Prasad
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>

2009-07-23 04:01:38

by Xiao Guangrong

[permalink] [raw]
Subject: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2

It's rather bored to clear symbol one by one in ksym_trace_filter
file, so, this patch can let ksym_trace_filter file support quick
clear, we can write "0" to this file, it can clear all symbols

for example:
# cat ksym_trace_filter
ksym_filter_head:rw-
global_trace:rw-
# echo 0 > ksym_trace_filter
# cat ksym_trace_filter
#

Changelog v1->v2:
Add other way to clear all breakpoints by writing NULL or "*:---"
to ksym_trace_filter file base on K.Prasad's suggestion

Signed-off-by: Xiao Guangrong <[email protected]>
---
kernel/trace/trace_ksym.c | 53 +++++++++++++++++++++++++++++---------------
1 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index cd5cb65..2fde875 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -163,8 +163,6 @@ static int parse_ksym_trace_str(char *input_string, char **ksymname,
{
int ret;

- strstrip(input_string);
-
*ksymname = strsep(&input_string, ":");
*addr = kallsyms_lookup_name(*ksymname);

@@ -262,6 +260,25 @@ static ssize_t ksym_trace_filter_read(struct file *filp, char __user *ubuf,
return cnt;
}

+static void __ksym_trace_reset(void)
+{
+ struct trace_ksym *entry;
+ struct hlist_node *node, *node1;
+
+ mutex_lock(&ksym_tracer_mutex);
+ hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
+ ksym_hlist) {
+ unregister_kernel_hw_breakpoint(entry->ksym_hbp);
+ ksym_filter_entry_count--;
+ hlist_del_rcu(&(entry->ksym_hlist));
+ synchronize_rcu();
+ kfree(entry->ksym_hbp->info.name);
+ kfree(entry->ksym_hbp);
+ kfree(entry);
+ }
+ mutex_unlock(&ksym_tracer_mutex);
+}
+
static ssize_t ksym_trace_filter_write(struct file *file,
const char __user *buffer,
size_t count, loff_t *ppos)
@@ -282,6 +299,21 @@ static ssize_t ksym_trace_filter_write(struct file *file,
}
input_string[count] = '\0';

+ strstrip(input_string);
+
+ /*
+ * Clear all breakpoints if:
+ * 1: echo > ksym_trace_filter
+ * 2: echo 0 > ksym_trace_filter
+ * 3: echo "*:---" > ksym_trace_filter
+ */
+ if (!input_string[0] || !strcmp(input_string, "0") ||
+ !strcmp(input_string, "*:---")) {
+ __ksym_trace_reset();
+ kfree(input_string);
+ return count;
+ }
+
ret = op = parse_ksym_trace_str(input_string, &ksymname, &ksym_addr);
if (ret < 0) {
kfree(input_string);
@@ -341,23 +373,8 @@ static const struct file_operations ksym_tracing_fops = {

static void ksym_trace_reset(struct trace_array *tr)
{
- struct trace_ksym *entry;
- struct hlist_node *node, *node1;
-
ksym_tracing_enabled = 0;
-
- mutex_lock(&ksym_tracer_mutex);
- hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
- ksym_hlist) {
- unregister_kernel_hw_breakpoint(entry->ksym_hbp);
- ksym_filter_entry_count--;
- hlist_del_rcu(&(entry->ksym_hlist));
- synchronize_rcu();
- kfree(entry->ksym_hbp->info.name);
- kfree(entry->ksym_hbp);
- kfree(entry);
- }
- mutex_unlock(&ksym_tracer_mutex);
+ __ksym_trace_reset();
}

static int ksym_trace_init(struct trace_array *tr)
--
1.6.1.2

2009-07-24 00:46:30

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2



On Thu, 23 Jul 2009, Xiao Guangrong wrote:

> It's rather bored to clear symbol one by one in ksym_trace_filter
> file, so, this patch can let ksym_trace_filter file support quick
> clear, we can write "0" to this file, it can clear all symbols
>
> for example:
> # cat ksym_trace_filter
> ksym_filter_head:rw-
> global_trace:rw-
> # echo 0 > ksym_trace_filter
> # cat ksym_trace_filter
> #
>
> Changelog v1->v2:
> Add other way to clear all breakpoints by writing NULL or "*:---"
> to ksym_trace_filter file base on K.Prasad's suggestion

Thanks guys, I'll go ahead and queue this up for 32.

-- Steve

2009-07-24 02:06:17

by Xiao Guangrong

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2



Steven Rostedt wrote:
>
> On Thu, 23 Jul 2009, Xiao Guangrong wrote:
>
>> It's rather bored to clear symbol one by one in ksym_trace_filter
>> file, so, this patch can let ksym_trace_filter file support quick
>> clear, we can write "0" to this file, it can clear all symbols
>>
>> for example:
>> # cat ksym_trace_filter
>> ksym_filter_head:rw-
>> global_trace:rw-
>> # echo 0 > ksym_trace_filter
>> # cat ksym_trace_filter
>> #
>>
>> Changelog v1->v2:
>> Add other way to clear all breakpoints by writing NULL or "*:---"
>> to ksym_trace_filter file base on K.Prasad's suggestion
>
> Thanks guys, I'll go ahead and queue this up for 32.
>

Hi Steven,

Could you have a look at other 2 patches in this series:

[PATCH 1/3] tracing/ksym_tracer: fix the output of ksym tracer
[PATCH 2/3] tracing/ksym_tracer: fix write operation of ksym_trace_filter

I think those fix is valuable, and K.Prasad has no objection.

Thanks,
Xiao

> -- Steve
>
>
>

2009-07-24 02:11:44

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 3/3] tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2


On Fri, 24 Jul 2009, Xiao Guangrong wrote:
> Steven Rostedt wrote:
> >
> > On Thu, 23 Jul 2009, Xiao Guangrong wrote:
> >
> >> It's rather bored to clear symbol one by one in ksym_trace_filter
> >> file, so, this patch can let ksym_trace_filter file support quick
> >> clear, we can write "0" to this file, it can clear all symbols
> >>
> >> for example:
> >> # cat ksym_trace_filter
> >> ksym_filter_head:rw-
> >> global_trace:rw-
> >> # echo 0 > ksym_trace_filter
> >> # cat ksym_trace_filter
> >> #
> >>
> >> Changelog v1->v2:
> >> Add other way to clear all breakpoints by writing NULL or "*:---"
> >> to ksym_trace_filter file base on K.Prasad's suggestion
> >
> > Thanks guys, I'll go ahead and queue this up for 32.
> >
>
> Hi Steven,
>
> Could you have a look at other 2 patches in this series:
>
> [PATCH 1/3] tracing/ksym_tracer: fix the output of ksym tracer
> [PATCH 2/3] tracing/ksym_tracer: fix write operation of ksym_trace_filter
>
> I think those fix is valuable, and K.Prasad has no objection.

Ah, sorry for the confusion. I've queued up the entire series. I'm just
playing with it now, and will post a pull request shortly.

-- Steve

2009-11-21 13:35:59

by Xiao Guangrong

[permalink] [raw]
Subject: [tip:perf/core] tracing/ksym_tracer: fix the output of ksym tracer

Commit-ID: d857ace143df3884954887e1899a65831ca72ece
Gitweb: http://git.kernel.org/tip/d857ace143df3884954887e1899a65831ca72ece
Author: Xiao Guangrong <[email protected]>
AuthorDate: Wed, 22 Jul 2009 11:21:31 +0800
Committer: Steven Rostedt <[email protected]>
CommitDate: Thu, 23 Jul 2009 20:51:35 -0400

tracing/ksym_tracer: fix the output of ksym tracer

Fix the output format of ksym tracer, make it properly aligned

Befor patch:
# tracer: ksym_tracer
#
# TASK-PID CPU# Symbol Type Function
# | | | | |
bash 1378 1 ksym_tracer_mutex W mutex_lock+0x11/0x27
bash 1378 1 ksym_filter_head W process_new_ksym_entry+0xd2/0x10c
bash 1378 1 ksym_tracer_mutex W mutex_unlock+0x12/0x1b
cat 1429 0 ksym_tracer_mutex W mutex_lock+0x11/0x27

After patch:
# tracer: ksym_tracer
#
# TASK-PID CPU# Symbol Type Function
# | | | | |
cat-1423 [000] ksym_tracer_mutex RW mutex_lock+0x11/0x27
cat-1423 [000] ksym_filter_head RW ksym_trace_filter_read+0x6e/0x10d
cat-1423 [000] ksym_tracer_mutex RW mutex_unlock+0x12/0x1b
cat-1423 [000] ksym_tracer_mutex RW mutex_lock+0x11/0x27
cat-1423 [000] ksym_filter_head RW ksym_trace_filter_read+0x6e/0x10d
cat-1423 [000] ksym_tracer_mutex RW mutex_unlock+0x12/0x1b

Signed-off-by: Xiao Guangrong <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
---
kernel/trace/trace_ksym.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index 1256a6e..fbf3a8e 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -370,13 +370,12 @@ static int ksym_trace_init(struct trace_array *tr)

static void ksym_trace_print_header(struct seq_file *m)
{
-
seq_puts(m,
- "# TASK-PID CPU# Symbol Type "
- "Function \n");
+ "# TASK-PID CPU# Symbol "
+ "Type Function\n");
seq_puts(m,
- "# | | | | "
- "| \n");
+ "# | | | "
+ " | |\n");
}

static enum print_line_t ksym_trace_output(struct trace_iterator *iter)
@@ -392,7 +391,7 @@ static enum print_line_t ksym_trace_output(struct trace_iterator *iter)

trace_assign_type(field, entry);

- ret = trace_seq_printf(s, "%-15s %-5d %-3d %-20s ", field->cmd,
+ ret = trace_seq_printf(s, "%11s-%-5d [%03d] %-30s ", field->cmd,
entry->pid, iter->cpu, field->ksym_name);
if (!ret)
return TRACE_TYPE_PARTIAL_LINE;
@@ -412,7 +411,7 @@ static enum print_line_t ksym_trace_output(struct trace_iterator *iter)
return TRACE_TYPE_PARTIAL_LINE;

sprint_symbol(str, field->ip);
- ret = trace_seq_printf(s, "%-20s\n", str);
+ ret = trace_seq_printf(s, "%s\n", str);
if (!ret)
return TRACE_TYPE_PARTIAL_LINE;

2009-11-21 13:36:11

by Xiao Guangrong

[permalink] [raw]
Subject: [tip:perf/core] tracing/ksym_tracer: fix write operation of ksym_trace_filter

Commit-ID: 8e068542a8d9efec55126284d2f5cb32f003d507
Gitweb: http://git.kernel.org/tip/8e068542a8d9efec55126284d2f5cb32f003d507
Author: Xiao Guangrong <[email protected]>
AuthorDate: Wed, 22 Jul 2009 11:23:41 +0800
Committer: Steven Rostedt <[email protected]>
CommitDate: Thu, 23 Jul 2009 20:52:05 -0400

tracing/ksym_tracer: fix write operation of ksym_trace_filter

This patch fix 2 bugs:
- fix the return value of ksym_trace_filter_write() when we want to
clear symbol in ksym_trace_filter file
for example:
# echo global_trace:rw- > /debug/tracing/ksym_trace_filter
# echo global_trace:--- > /debug/tracing/ksym_trace_filter
-bash: echo: write error: Invalid argument
# cat /debug/tracing/ksym_trace_filter
#
We want to clear 'global_trace' in ksym_trace_filter, it complain
with "Invalid argument", but the operation is successful

- the "r--" access types is not allowed, but ksym_trace_filter file think
it OK
for example:
# echo ksym_tracer_mutex:r-- > ksym_trace_filter
-bash: echo: write error: Resource temporarily unavailable
# dmesg
ksym_tracer request failed. Try again later!!

The error occur at register_kernel_hw_breakpoint(), but It's should
at access types parser

Signed-off-by: Xiao Guangrong <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
---
kernel/trace/trace_ksym.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index fbf3a8e..cd5cb65 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -135,6 +135,9 @@ static int ksym_trace_get_access_type(char *str)
case 6:
access = HW_BREAKPOINT_RW;
break;
+ case 4:
+ access = -EINVAL;
+ break;
case 2:
access = HW_BREAKPOINT_WRITE;
break;
@@ -312,6 +315,7 @@ static ssize_t ksym_trace_filter_write(struct file *file,
kfree(entry->ksym_hbp->info.name);
kfree(entry->ksym_hbp);
kfree(entry);
+ ret = 0;
goto out;
} else {
/* Check for malformed request: (4) */

2009-11-21 13:36:11

by Xiao Guangrong

[permalink] [raw]
Subject: [tip:perf/core] tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2

Commit-ID: 75e33751ca8bbb72dd6f1a74d2810ddc8cbe4bdf
Gitweb: http://git.kernel.org/tip/75e33751ca8bbb72dd6f1a74d2810ddc8cbe4bdf
Author: Xiao Guangrong <[email protected]>
AuthorDate: Thu, 23 Jul 2009 12:01:22 +0800
Committer: Steven Rostedt <[email protected]>
CommitDate: Thu, 23 Jul 2009 20:54:40 -0400

tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2

It's rather boring to clear symbol one by one in ksym_trace_filter
file, so, this patch will let ksym_trace_filter file support quickly
clear all break points. We can write "0" to this file and it will clear
all symbols

for example:
# cat ksym_trace_filter
ksym_filter_head:rw-
global_trace:rw-
# echo 0 > ksym_trace_filter
# cat ksym_trace_filter
#

Changelog v1->v2:
Add other ways to clear all breakpoints by writing NULL or "*:---"
to ksym_trace_filter file base on K.Prasad's suggestion

Signed-off-by: Xiao Guangrong <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
---
kernel/trace/trace_ksym.c | 53 +++++++++++++++++++++++++++++---------------
1 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index cd5cb65..2fde875 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -163,8 +163,6 @@ static int parse_ksym_trace_str(char *input_string, char **ksymname,
{
int ret;

- strstrip(input_string);
-
*ksymname = strsep(&input_string, ":");
*addr = kallsyms_lookup_name(*ksymname);

@@ -262,6 +260,25 @@ static ssize_t ksym_trace_filter_read(struct file *filp, char __user *ubuf,
return cnt;
}

+static void __ksym_trace_reset(void)
+{
+ struct trace_ksym *entry;
+ struct hlist_node *node, *node1;
+
+ mutex_lock(&ksym_tracer_mutex);
+ hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
+ ksym_hlist) {
+ unregister_kernel_hw_breakpoint(entry->ksym_hbp);
+ ksym_filter_entry_count--;
+ hlist_del_rcu(&(entry->ksym_hlist));
+ synchronize_rcu();
+ kfree(entry->ksym_hbp->info.name);
+ kfree(entry->ksym_hbp);
+ kfree(entry);
+ }
+ mutex_unlock(&ksym_tracer_mutex);
+}
+
static ssize_t ksym_trace_filter_write(struct file *file,
const char __user *buffer,
size_t count, loff_t *ppos)
@@ -282,6 +299,21 @@ static ssize_t ksym_trace_filter_write(struct file *file,
}
input_string[count] = '\0';

+ strstrip(input_string);
+
+ /*
+ * Clear all breakpoints if:
+ * 1: echo > ksym_trace_filter
+ * 2: echo 0 > ksym_trace_filter
+ * 3: echo "*:---" > ksym_trace_filter
+ */
+ if (!input_string[0] || !strcmp(input_string, "0") ||
+ !strcmp(input_string, "*:---")) {
+ __ksym_trace_reset();
+ kfree(input_string);
+ return count;
+ }
+
ret = op = parse_ksym_trace_str(input_string, &ksymname, &ksym_addr);
if (ret < 0) {
kfree(input_string);
@@ -341,23 +373,8 @@ static const struct file_operations ksym_tracing_fops = {

static void ksym_trace_reset(struct trace_array *tr)
{
- struct trace_ksym *entry;
- struct hlist_node *node, *node1;
-
ksym_tracing_enabled = 0;
-
- mutex_lock(&ksym_tracer_mutex);
- hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
- ksym_hlist) {
- unregister_kernel_hw_breakpoint(entry->ksym_hbp);
- ksym_filter_entry_count--;
- hlist_del_rcu(&(entry->ksym_hlist));
- synchronize_rcu();
- kfree(entry->ksym_hbp->info.name);
- kfree(entry->ksym_hbp);
- kfree(entry);
- }
- mutex_unlock(&ksym_tracer_mutex);
+ __ksym_trace_reset();
}

static int ksym_trace_init(struct trace_array *tr)