aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.h
diff options
context:
space:
mode:
authorTom Zanussi <tzanussi@gmail.com>2009-04-13 04:17:50 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-13 18:03:55 -0400
commit0a19e53c1514ad8e9c3cbab40c6c3f52c86f403d (patch)
tree1089246a64f65b2b3c2ba29182ed4f9ce9ad375e /kernel/trace/trace.h
parentb5c851a88a369854c04e511cefb84ea2d0cfa209 (diff)
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched on-the-fly while avoiding the use of rcu or the suspension of tracing of previous versions. It does it by adding a new filter_pred_none() predicate function which does nothing and by never deallocating either the predicates or any of the filter_pred members used in matching; the predicate lists are allocated and initialized during ftrace_event_calls initialization. Whenever a filter is removed or replaced, the filter_pred_* functions currently in use by the affected ftrace_event_call are immediately switched over to to the filter_pred_none() function, while the rest of the filter_pred members are left intact, allowing any currently executing filter_pred_* functions to finish up, using the values they're currently using. In the case of filter replacement, the new predicate values are copied into the old predicates after the above step, and the filter_pred_none() functions are replaced by the filter_pred_* functions for the new filter. In this case, it is possible though very unlikely that a previous filter_pred_* is still running even after the filter_pred_none() switch and the switch to the new filter_pred_*. In that case, however, because nothing has been deallocated in the filter_pred, the worst that can happen is that the old filter_pred_* function sees the new values and as a result produces either a false positive or a false negative, depending on the values it finds. So one downside to this method is that rarely, it can produce a bad match during the filter switch, but it should be possible to live with that, IMHO. The other downside is that at least in this patch the predicate lists are always pre-allocated, taking up memory from the start. They could probably be allocated on first-use, and de-allocated when tracing is completely stopped - if this patch makes sense, I could create another one to do that later on. Oh, and it also places a restriction on the size of __arrays in events, currently set to 128, since they can't be larger than the now embedded str_val arrays in the filter_pred struct. Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: paulmck@linux.vnet.ibm.com LKML-Reference: <1239610670.6660.49.camel@tropicana> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace.h')
-rw-r--r--kernel/trace/trace.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 9729d14767d8..b05b6ac982a1 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -813,6 +813,7 @@ struct ftrace_event_call {
813 int (*show_format)(struct trace_seq *s); 813 int (*show_format)(struct trace_seq *s);
814 int (*define_fields)(void); 814 int (*define_fields)(void);
815 struct list_head fields; 815 struct list_head fields;
816 int n_preds;
816 struct filter_pred **preds; 817 struct filter_pred **preds;
817 818
818#ifdef CONFIG_EVENT_PROFILE 819#ifdef CONFIG_EVENT_PROFILE
@@ -826,6 +827,7 @@ struct event_subsystem {
826 struct list_head list; 827 struct list_head list;
827 const char *name; 828 const char *name;
828 struct dentry *entry; 829 struct dentry *entry;
830 int n_preds;
829 struct filter_pred **preds; 831 struct filter_pred **preds;
830}; 832};
831 833
@@ -834,7 +836,8 @@ struct event_subsystem {
834 (unsigned long)event < (unsigned long)__stop_ftrace_events; \ 836 (unsigned long)event < (unsigned long)__stop_ftrace_events; \
835 event++) 837 event++)
836 838
837#define MAX_FILTER_PRED 8 839#define MAX_FILTER_PRED 8
840#define MAX_FILTER_STR_VAL 128
838 841
839struct filter_pred; 842struct filter_pred;
840 843
@@ -843,7 +846,7 @@ typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
843struct filter_pred { 846struct filter_pred {
844 filter_pred_fn_t fn; 847 filter_pred_fn_t fn;
845 u64 val; 848 u64 val;
846 char *str_val; 849 char str_val[MAX_FILTER_STR_VAL];
847 int str_len; 850 int str_len;
848 char *field_name; 851 char *field_name;
849 int offset; 852 int offset;
@@ -855,13 +858,14 @@ struct filter_pred {
855 858
856int trace_define_field(struct ftrace_event_call *call, char *type, 859int trace_define_field(struct ftrace_event_call *call, char *type,
857 char *name, int offset, int size); 860 char *name, int offset, int size);
861extern int init_preds(struct ftrace_event_call *call);
858extern void filter_free_pred(struct filter_pred *pred); 862extern void filter_free_pred(struct filter_pred *pred);
859extern void filter_print_preds(struct filter_pred **preds, 863extern void filter_print_preds(struct filter_pred **preds, int n_preds,
860 struct trace_seq *s); 864 struct trace_seq *s);
861extern int filter_parse(char **pbuf, struct filter_pred *pred); 865extern int filter_parse(char **pbuf, struct filter_pred *pred);
862extern int filter_add_pred(struct ftrace_event_call *call, 866extern int filter_add_pred(struct ftrace_event_call *call,
863 struct filter_pred *pred); 867 struct filter_pred *pred);
864extern void filter_free_preds(struct ftrace_event_call *call); 868extern void filter_disable_preds(struct ftrace_event_call *call);
865extern int filter_match_preds(struct ftrace_event_call *call, void *rec); 869extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
866extern void filter_free_subsystem_preds(struct event_subsystem *system); 870extern void filter_free_subsystem_preds(struct event_subsystem *system);
867extern int filter_add_subsystem_pred(struct event_subsystem *system, 871extern int filter_add_subsystem_pred(struct event_subsystem *system,
@@ -875,7 +879,7 @@ filter_check_discard(struct ftrace_event_call *call, void *rec,
875 struct ring_buffer *buffer, 879 struct ring_buffer *buffer,
876 struct ring_buffer_event *event) 880 struct ring_buffer_event *event)
877{ 881{
878 if (unlikely(call->preds) && !filter_match_preds(call, rec)) { 882 if (unlikely(call->n_preds) && !filter_match_preds(call, rec)) {
879 ring_buffer_discard_commit(buffer, event); 883 ring_buffer_discard_commit(buffer, event);
880 return 1; 884 return 1;
881 } 885 }