tracing/filter: Allocate the preds in an array
authorSteven Rostedt <srostedt@redhat.com>
Fri, 28 Jan 2011 03:49:48 +0000 (22:49 -0500)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 8 Feb 2011 01:56:18 +0000 (20:56 -0500)
Currently we allocate an array of pointers to filter_preds, and then
allocate a separate filter_pred for each item in the array.
This adds slight overhead in the filters as it needs to derefernce
twice to get to the op condition.

Allocating the preds themselves in a single array removes a dereference
as well as helps on the cache footprint.

Cc: Tom Zanussi <tzanussi@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace.h
kernel/trace/trace_events_filter.c

index 441fc1bc85d697a15c86738fe1dff2e7a9b20c05..254d04a84ec30397ab39f23d21b83ea47a033f65 100644 (file)
@@ -663,7 +663,7 @@ struct ftrace_event_field {
 struct event_filter {
        int                     n_preds;        /* Number assigned */
        int                     a_preds;        /* allocated */
-       struct filter_pred      **preds;
+       struct filter_pred      *preds;
        char                    *filter_string;
 };
 
index 8f00a11ce7788739ceff318a4b86524d1c6bbbab..b6c910642a1edcfdf9ff3c88ecfc9e14a7f3f7ad 100644 (file)
@@ -362,7 +362,7 @@ int filter_match_preds(struct event_filter *filter, void *rec)
 {
        int match = -1, top = 0, val1 = 0, val2 = 0;
        int stack[MAX_FILTER_PRED];
-       struct filter_pred **preds;
+       struct filter_pred *preds;
        struct filter_pred *pred;
        int n_preds = ACCESS_ONCE(filter->n_preds);
        int i;
@@ -377,7 +377,7 @@ int filter_match_preds(struct event_filter *filter, void *rec)
        preds = rcu_dereference_sched(filter->preds);
 
        for (i = 0; i < n_preds; i++) {
-               pred = preds[i];
+               pred = &preds[i];
                if (!pred->pop_n) {
                        match = pred->fn(pred, rec);
                        stack[top++] = match;
@@ -559,10 +559,8 @@ static void __free_preds(struct event_filter *filter)
        int i;
 
        if (filter->preds) {
-               for (i = 0; i < filter->a_preds; i++) {
-                       if (filter->preds[i])
-                               filter_free_pred(filter->preds[i]);
-               }
+               for (i = 0; i < filter->a_preds; i++)
+                       kfree(filter->preds[i].field_name);
                kfree(filter->preds);
                filter->preds = NULL;
        }
@@ -572,7 +570,6 @@ static void __free_preds(struct event_filter *filter)
 
 static void reset_preds(struct event_filter *filter)
 {
-       struct filter_pred *pred;
        int n_preds = filter->n_preds;
        int i;
 
@@ -580,10 +577,8 @@ static void reset_preds(struct event_filter *filter)
        if (!filter->preds)
                return;
 
-       for (i = 0; i < n_preds; i++) {
-               pred = filter->preds[i];
-               pred->fn = filter_pred_none;
-       }
+       for (i = 0; i < n_preds; i++)
+               filter->preds[i].fn = filter_pred_none;
 }
 
 static void filter_disable_preds(struct ftrace_event_call *call)
@@ -658,19 +653,11 @@ static int __alloc_preds(struct event_filter *filter, int n_preds)
                return -EINVAL;
 
        for (i = 0; i < n_preds; i++) {
-               pred = filter->preds[i];
-               if (!pred)
-                       pred = kzalloc(sizeof(*pred), GFP_KERNEL);
-               if (!pred)
-                       goto oom;
+               pred = &filter->preds[i];
                pred->fn = filter_pred_none;
-               filter->preds[i] = pred;
        }
 
        return 0;
- oom:
-       __free_preds(filter);
-       return -ENOMEM;
 }
 
 static int init_filter(struct ftrace_event_call *call)
@@ -730,8 +717,8 @@ static int filter_add_pred_fn(struct filter_parse_state *ps,
        }
 
        idx = filter->n_preds;
-       filter_clear_pred(filter->preds[idx]);
-       err = filter_set_pred(filter->preds[idx], pred, fn);
+       filter_clear_pred(&filter->preds[idx]);
+       err = filter_set_pred(&filter->preds[idx], pred, fn);
        if (err)
                return err;