diff options
| author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2009-07-15 00:32:15 -0400 | 
|---|---|---|
| committer | Frederic Weisbecker <fweisbec@gmail.com> | 2009-07-17 00:37:53 -0400 | 
| commit | 64fbcd162819bddaf0d99e78b16371b655aa5dee (patch) | |
| tree | abc34dd23386f13675502455d99d868b9b63173e | |
| parent | da706d8bc833e7153622435560422e653bdb2e94 (diff) | |
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: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Reviewed-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
| -rw-r--r-- | kernel/trace/ftrace.c | 72 | 
1 files changed, 18 insertions, 54 deletions
| diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index bce9e01a29c8..217caeca71cd 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
| @@ -1017,71 +1017,35 @@ static int | |||
| 1017 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) | 1017 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) | 
| 1018 | { | 1018 | { | 
| 1019 | unsigned long ftrace_addr; | 1019 | unsigned long ftrace_addr; | 
| 1020 | unsigned long ip, fl; | 1020 | unsigned long flag = 0UL; | 
| 1021 | 1021 | ||
| 1022 | ftrace_addr = (unsigned long)FTRACE_ADDR; | 1022 | ftrace_addr = (unsigned long)FTRACE_ADDR; | 
| 1023 | 1023 | ||
| 1024 | ip = rec->ip; | ||
| 1025 | |||
| 1026 | /* | 1024 | /* | 
| 1027 | * If this record is not to be traced and | 1025 | * If this record is not to be traced or we want to disable it, | 
| 1028 | * it is not enabled then do nothing. | 1026 | * then disable it. | 
| 1029 | * | 1027 | * | 
| 1030 | * If this record is not to be traced and | 1028 | * If we want to enable it and filtering is off, then enable it. | 
| 1031 | * it is enabled then disable it. | ||
| 1032 | * | 1029 | * | 
| 1030 | * If we want to enable it and filtering is on, enable it only if | ||
| 1031 | * it's filtered | ||
| 1033 | */ | 1032 | */ | 
| 1034 | if (rec->flags & FTRACE_FL_NOTRACE) { | 1033 | if (enable && !(rec->flags & FTRACE_FL_NOTRACE)) { | 
| 1035 | if (rec->flags & FTRACE_FL_ENABLED) | 1034 | if (!ftrace_filtered || (rec->flags & FTRACE_FL_FILTER)) | 
| 1036 | rec->flags &= ~FTRACE_FL_ENABLED; | 1035 | flag = FTRACE_FL_ENABLED; | 
| 1037 | else | 1036 | } | 
| 1038 | return 0; | ||
| 1039 | |||
| 1040 | } else if (ftrace_filtered && enable) { | ||
| 1041 | /* | ||
| 1042 | * Filtering is on: | ||
| 1043 | */ | ||
| 1044 | |||
| 1045 | fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED); | ||
| 1046 | |||
| 1047 | /* Record is filtered and enabled, do nothing */ | ||
| 1048 | if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) | ||
| 1049 | return 0; | ||
| 1050 | |||
| 1051 | /* Record is not filtered or enabled, do nothing */ | ||
| 1052 | if (!fl) | ||
| 1053 | return 0; | ||
| 1054 | |||
| 1055 | /* Record is not filtered but enabled, disable it */ | ||
| 1056 | if (fl == FTRACE_FL_ENABLED) | ||
| 1057 | rec->flags &= ~FTRACE_FL_ENABLED; | ||
| 1058 | else | ||
| 1059 | /* Otherwise record is filtered but not enabled, enable it */ | ||
| 1060 | rec->flags |= FTRACE_FL_ENABLED; | ||
| 1061 | } else { | ||
| 1062 | /* Disable or not filtered */ | ||
| 1063 | |||
| 1064 | if (enable) { | ||
| 1065 | /* if record is enabled, do nothing */ | ||
| 1066 | if (rec->flags & FTRACE_FL_ENABLED) | ||
| 1067 | return 0; | ||
| 1068 | |||
| 1069 | rec->flags |= FTRACE_FL_ENABLED; | ||
| 1070 | |||
| 1071 | } else { | ||
| 1072 | 1037 | ||
| 1073 | /* if record is not enabled, do nothing */ | 1038 | /* If the state of this record hasn't changed, then do nothing */ | 
| 1074 | if (!(rec->flags & FTRACE_FL_ENABLED)) | 1039 | if ((rec->flags & FTRACE_FL_ENABLED) == flag) | 
| 1075 | return 0; | 1040 | return 0; | 
| 1076 | 1041 | ||
| 1077 | rec->flags &= ~FTRACE_FL_ENABLED; | 1042 | if (flag) { | 
| 1078 | } | 1043 | rec->flags |= FTRACE_FL_ENABLED; | 
| 1044 | return ftrace_make_call(rec, ftrace_addr); | ||
| 1079 | } | 1045 | } | 
| 1080 | 1046 | ||
| 1081 | if (rec->flags & FTRACE_FL_ENABLED) | 1047 | rec->flags &= ~FTRACE_FL_ENABLED; | 
| 1082 | return ftrace_make_call(rec, ftrace_addr); | 1048 | return ftrace_make_nop(NULL, rec, ftrace_addr); | 
| 1083 | else | ||
| 1084 | return ftrace_make_nop(NULL, rec, ftrace_addr); | ||
| 1085 | } | 1049 | } | 
| 1086 | 1050 | ||
| 1087 | static void ftrace_replace_code(int enable) | 1051 | static void ftrace_replace_code(int enable) | 
