Commit 64fbcd16 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Frederic Weisbecker

tracing/function: Simplify __ftrace_replace_code()

Rewrite the __ftrace_replace_code() function, simplify it, but don't
change the code's logic.

First, we get the state we want to set, if the record has the same
state, then do nothing, otherwise enable/disable it.
Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Reviewed-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
parent da706d8b
...@@ -1017,70 +1017,34 @@ static int ...@@ -1017,70 +1017,34 @@ static int
__ftrace_replace_code(struct dyn_ftrace *rec, int enable) __ftrace_replace_code(struct dyn_ftrace *rec, int enable)
{ {
unsigned long ftrace_addr; unsigned long ftrace_addr;
unsigned long ip, fl; unsigned long flag = 0UL;
ftrace_addr = (unsigned long)FTRACE_ADDR; ftrace_addr = (unsigned long)FTRACE_ADDR;
ip = rec->ip;
/* /*
* If this record is not to be traced and * If this record is not to be traced or we want to disable it,
* it is not enabled then do nothing. * then disable it.
* *
* If this record is not to be traced and * If we want to enable it and filtering is off, then enable it.
* it is enabled then disable it.
* *
* If we want to enable it and filtering is on, enable it only if
* it's filtered
*/ */
if (rec->flags & FTRACE_FL_NOTRACE) { if (enable && !(rec->flags & FTRACE_FL_NOTRACE)) {
if (rec->flags & FTRACE_FL_ENABLED) if (!ftrace_filtered || (rec->flags & FTRACE_FL_FILTER))
rec->flags &= ~FTRACE_FL_ENABLED; flag = FTRACE_FL_ENABLED;
else }
return 0;
} else if (ftrace_filtered && enable) {
/*
* Filtering is on:
*/
fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);
/* Record is filtered and enabled, do nothing */
if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED))
return 0;
/* Record is not filtered or enabled, do nothing */
if (!fl)
return 0;
/* Record is not filtered but enabled, disable it */
if (fl == FTRACE_FL_ENABLED)
rec->flags &= ~FTRACE_FL_ENABLED;
else
/* Otherwise record is filtered but not enabled, enable it */
rec->flags |= FTRACE_FL_ENABLED;
} else {
/* Disable or not filtered */
if (enable) { /* If the state of this record hasn't changed, then do nothing */
/* if record is enabled, do nothing */ if ((rec->flags & FTRACE_FL_ENABLED) == flag)
if (rec->flags & FTRACE_FL_ENABLED)
return 0; return 0;
if (flag) {
rec->flags |= FTRACE_FL_ENABLED; rec->flags |= FTRACE_FL_ENABLED;
return ftrace_make_call(rec, ftrace_addr);
} else {
/* if record is not enabled, do nothing */
if (!(rec->flags & FTRACE_FL_ENABLED))
return 0;
rec->flags &= ~FTRACE_FL_ENABLED;
}
} }
if (rec->flags & FTRACE_FL_ENABLED) rec->flags &= ~FTRACE_FL_ENABLED;
return ftrace_make_call(rec, ftrace_addr);
else
return ftrace_make_nop(NULL, rec, ftrace_addr); return ftrace_make_nop(NULL, rec, ftrace_addr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment