Skip to content

Commit

Permalink
tracing/ksym_tracer: support quick clear for ksym_trace_filter -- v2
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Xiao Guangrong authored and rostedt committed Jul 24, 2009
1 parent 8e06854 commit 75e3375
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions kernel/trace/trace_ksym.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 75e3375

Please sign in to comment.