diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-10-14 23:20:34 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-10-15 05:35:22 -0400 |
commit | fce29d15b59245597f7f320db4a9f2be0f5fb512 (patch) | |
tree | f854f32b7c85b02935e9d04ee35957fb7bc7c4bb /kernel/trace | |
parent | 713490e02eed242b4c1c672b3c0c8b708f8b6f1d (diff) |
tracing/filters: Refactor subsystem filter code
Change:
for_each_pred
for_each_subsystem
To:
for_each_subsystem
for_each_pred
This change also prepares for later patches.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4AD69502.8060903@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace')
-rw-r--r-- | kernel/trace/trace.h | 1 | ||||
-rw-r--r-- | kernel/trace/trace_events_filter.c | 124 |
2 files changed, 45 insertions, 80 deletions
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index acef8b4636f0..628614532d16 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
@@ -683,7 +683,6 @@ struct event_filter { | |||
683 | int n_preds; | 683 | int n_preds; |
684 | struct filter_pred **preds; | 684 | struct filter_pred **preds; |
685 | char *filter_string; | 685 | char *filter_string; |
686 | bool no_reset; | ||
687 | }; | 686 | }; |
688 | 687 | ||
689 | struct event_subsystem { | 688 | struct event_subsystem { |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 92672016da28..9c4f9a0dae2b 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
@@ -615,14 +615,7 @@ static int init_subsystem_preds(struct event_subsystem *system) | |||
615 | return 0; | 615 | return 0; |
616 | } | 616 | } |
617 | 617 | ||
618 | enum { | 618 | static void filter_free_subsystem_preds(struct event_subsystem *system) |
619 | FILTER_DISABLE_ALL, | ||
620 | FILTER_INIT_NO_RESET, | ||
621 | FILTER_SKIP_NO_RESET, | ||
622 | }; | ||
623 | |||
624 | static void filter_free_subsystem_preds(struct event_subsystem *system, | ||
625 | int flag) | ||
626 | { | 619 | { |
627 | struct ftrace_event_call *call; | 620 | struct ftrace_event_call *call; |
628 | 621 | ||
@@ -633,14 +626,6 @@ static void filter_free_subsystem_preds(struct event_subsystem *system, | |||
633 | if (strcmp(call->system, system->name) != 0) | 626 | if (strcmp(call->system, system->name) != 0) |
634 | continue; | 627 | continue; |
635 | 628 | ||
636 | if (flag == FILTER_INIT_NO_RESET) { | ||
637 | call->filter->no_reset = false; | ||
638 | continue; | ||
639 | } | ||
640 | |||
641 | if (flag == FILTER_SKIP_NO_RESET && call->filter->no_reset) | ||
642 | continue; | ||
643 | |||
644 | filter_disable_preds(call); | 629 | filter_disable_preds(call); |
645 | remove_filter_string(call->filter); | 630 | remove_filter_string(call->filter); |
646 | } | 631 | } |
@@ -817,44 +802,6 @@ add_pred_fn: | |||
817 | return 0; | 802 | return 0; |
818 | } | 803 | } |
819 | 804 | ||
820 | static int filter_add_subsystem_pred(struct filter_parse_state *ps, | ||
821 | struct event_subsystem *system, | ||
822 | struct filter_pred *pred, | ||
823 | char *filter_string, | ||
824 | bool dry_run) | ||
825 | { | ||
826 | struct ftrace_event_call *call; | ||
827 | int err = 0; | ||
828 | bool fail = true; | ||
829 | |||
830 | list_for_each_entry(call, &ftrace_events, list) { | ||
831 | |||
832 | if (!call->define_fields) | ||
833 | continue; | ||
834 | |||
835 | if (strcmp(call->system, system->name)) | ||
836 | continue; | ||
837 | |||
838 | if (call->filter->no_reset) | ||
839 | continue; | ||
840 | |||
841 | err = filter_add_pred(ps, call, pred, dry_run); | ||
842 | if (err) | ||
843 | call->filter->no_reset = true; | ||
844 | else | ||
845 | fail = false; | ||
846 | |||
847 | if (!dry_run) | ||
848 | replace_filter_string(call->filter, filter_string); | ||
849 | } | ||
850 | |||
851 | if (fail) { | ||
852 | parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0); | ||
853 | return err; | ||
854 | } | ||
855 | return 0; | ||
856 | } | ||
857 | |||
858 | static void parse_init(struct filter_parse_state *ps, | 805 | static void parse_init(struct filter_parse_state *ps, |
859 | struct filter_op *ops, | 806 | struct filter_op *ops, |
860 | char *infix_string) | 807 | char *infix_string) |
@@ -1209,8 +1156,7 @@ static int check_preds(struct filter_parse_state *ps) | |||
1209 | return 0; | 1156 | return 0; |
1210 | } | 1157 | } |
1211 | 1158 | ||
1212 | static int replace_preds(struct event_subsystem *system, | 1159 | static int replace_preds(struct ftrace_event_call *call, |
1213 | struct ftrace_event_call *call, | ||
1214 | struct filter_parse_state *ps, | 1160 | struct filter_parse_state *ps, |
1215 | char *filter_string, | 1161 | char *filter_string, |
1216 | bool dry_run) | 1162 | bool dry_run) |
@@ -1257,11 +1203,7 @@ static int replace_preds(struct event_subsystem *system, | |||
1257 | add_pred: | 1203 | add_pred: |
1258 | if (!pred) | 1204 | if (!pred) |
1259 | return -ENOMEM; | 1205 | return -ENOMEM; |
1260 | if (call) | 1206 | err = filter_add_pred(ps, call, pred, dry_run); |
1261 | err = filter_add_pred(ps, call, pred, false); | ||
1262 | else | ||
1263 | err = filter_add_subsystem_pred(ps, system, pred, | ||
1264 | filter_string, dry_run); | ||
1265 | filter_free_pred(pred); | 1207 | filter_free_pred(pred); |
1266 | if (err) | 1208 | if (err) |
1267 | return err; | 1209 | return err; |
@@ -1272,6 +1214,44 @@ add_pred: | |||
1272 | return 0; | 1214 | return 0; |
1273 | } | 1215 | } |
1274 | 1216 | ||
1217 | static int replace_system_preds(struct event_subsystem *system, | ||
1218 | struct filter_parse_state *ps, | ||
1219 | char *filter_string) | ||
1220 | { | ||
1221 | struct ftrace_event_call *call; | ||
1222 | int err; | ||
1223 | bool fail = true; | ||
1224 | |||
1225 | list_for_each_entry(call, &ftrace_events, list) { | ||
1226 | |||
1227 | if (!call->define_fields) | ||
1228 | continue; | ||
1229 | |||
1230 | if (strcmp(call->system, system->name) != 0) | ||
1231 | continue; | ||
1232 | |||
1233 | /* try to see if the filter can be applied */ | ||
1234 | err = replace_preds(call, ps, filter_string, true); | ||
1235 | if (err) | ||
1236 | continue; | ||
1237 | |||
1238 | /* really apply the filter */ | ||
1239 | filter_disable_preds(call); | ||
1240 | err = replace_preds(call, ps, filter_string, false); | ||
1241 | if (err) | ||
1242 | filter_disable_preds(call); | ||
1243 | else | ||
1244 | replace_filter_string(call->filter, filter_string); | ||
1245 | fail = false; | ||
1246 | } | ||
1247 | |||
1248 | if (fail) { | ||
1249 | parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0); | ||
1250 | return err; | ||
1251 | } | ||
1252 | return 0; | ||
1253 | } | ||
1254 | |||
1275 | int apply_event_filter(struct ftrace_event_call *call, char *filter_string) | 1255 | int apply_event_filter(struct ftrace_event_call *call, char *filter_string) |
1276 | { | 1256 | { |
1277 | int err; | 1257 | int err; |
@@ -1306,7 +1286,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) | |||
1306 | goto out; | 1286 | goto out; |
1307 | } | 1287 | } |
1308 | 1288 | ||
1309 | err = replace_preds(NULL, call, ps, filter_string, false); | 1289 | err = replace_preds(call, ps, filter_string, false); |
1310 | if (err) | 1290 | if (err) |
1311 | append_filter_err(ps, call->filter); | 1291 | append_filter_err(ps, call->filter); |
1312 | 1292 | ||
@@ -1334,7 +1314,7 @@ int apply_subsystem_event_filter(struct event_subsystem *system, | |||
1334 | goto out_unlock; | 1314 | goto out_unlock; |
1335 | 1315 | ||
1336 | if (!strcmp(strstrip(filter_string), "0")) { | 1316 | if (!strcmp(strstrip(filter_string), "0")) { |
1337 | filter_free_subsystem_preds(system, FILTER_DISABLE_ALL); | 1317 | filter_free_subsystem_preds(system); |
1338 | remove_filter_string(system->filter); | 1318 | remove_filter_string(system->filter); |
1339 | mutex_unlock(&event_mutex); | 1319 | mutex_unlock(&event_mutex); |
1340 | return 0; | 1320 | return 0; |
@@ -1354,23 +1334,9 @@ int apply_subsystem_event_filter(struct event_subsystem *system, | |||
1354 | goto out; | 1334 | goto out; |
1355 | } | 1335 | } |
1356 | 1336 | ||
1357 | filter_free_subsystem_preds(system, FILTER_INIT_NO_RESET); | 1337 | err = replace_system_preds(system, ps, filter_string); |
1358 | 1338 | if (err) | |
1359 | /* try to see the filter can be applied to which events */ | ||
1360 | err = replace_preds(system, NULL, ps, filter_string, true); | ||
1361 | if (err) { | ||
1362 | append_filter_err(ps, system->filter); | ||
1363 | goto out; | ||
1364 | } | ||
1365 | |||
1366 | filter_free_subsystem_preds(system, FILTER_SKIP_NO_RESET); | ||
1367 | |||
1368 | /* really apply the filter to the events */ | ||
1369 | err = replace_preds(system, NULL, ps, filter_string, false); | ||
1370 | if (err) { | ||
1371 | append_filter_err(ps, system->filter); | 1339 | append_filter_err(ps, system->filter); |
1372 | filter_free_subsystem_preds(system, 2); | ||
1373 | } | ||
1374 | 1340 | ||
1375 | out: | 1341 | out: |
1376 | filter_opstack_clear(ps); | 1342 | filter_opstack_clear(ps); |