Skip to content

Commit 936e074

Browse files
Steven Rostedtrostedt
authored andcommitted
ftrace: Modify ftrace_set_filter/notrace to take ops
Since users of the function tracer can now pick and choose which functions they want to trace agnostically from other users of the function tracer, we need to pass the ops struct to the ftrace_set_filter() functions. The functions ftrace_set_global_filter() and ftrace_set_global_notrace() is added to keep the old filter functions which are used to modify the generic function tracers. Signed-off-by: Steven Rostedt <[email protected]>
1 parent cdbe61b commit 936e074

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

include/linux/ftrace.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ struct dyn_ftrace {
179179
};
180180

181181
int ftrace_force_update(void);
182-
void ftrace_set_filter(unsigned char *buf, int len, int reset);
182+
void ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
183+
int len, int reset);
184+
void ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
185+
int len, int reset);
186+
void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
187+
void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
183188

184189
int register_ftrace_command(struct ftrace_func_command *cmd);
185190
int unregister_ftrace_command(struct ftrace_func_command *cmd);

kernel/trace/ftrace.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,10 @@ ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len,
28262826
struct ftrace_hash *hash;
28272827
int ret;
28282828

2829+
/* All global ops uses the global ops filters */
2830+
if (ops->flags & FTRACE_OPS_FL_GLOBAL)
2831+
ops = &global_ops;
2832+
28292833
if (unlikely(ftrace_disabled))
28302834
return -ENODEV;
28312835

@@ -2856,20 +2860,57 @@ ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len,
28562860

28572861
/**
28582862
* ftrace_set_filter - set a function to filter on in ftrace
2863+
* @ops - the ops to set the filter with
2864+
* @buf - the string that holds the function filter text.
2865+
* @len - the length of the string.
2866+
* @reset - non zero to reset all filters before applying this filter.
2867+
*
2868+
* Filters denote which functions should be enabled when tracing is enabled.
2869+
* If @buf is NULL and reset is set, all functions will be enabled for tracing.
2870+
*/
2871+
void ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
2872+
int len, int reset)
2873+
{
2874+
ftrace_set_regex(ops, buf, len, reset, 1);
2875+
}
2876+
EXPORT_SYMBOL_GPL(ftrace_set_filter);
2877+
2878+
/**
2879+
* ftrace_set_notrace - set a function to not trace in ftrace
2880+
* @ops - the ops to set the notrace filter with
2881+
* @buf - the string that holds the function notrace text.
2882+
* @len - the length of the string.
2883+
* @reset - non zero to reset all filters before applying this filter.
2884+
*
2885+
* Notrace Filters denote which functions should not be enabled when tracing
2886+
* is enabled. If @buf is NULL and reset is set, all functions will be enabled
2887+
* for tracing.
2888+
*/
2889+
void ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
2890+
int len, int reset)
2891+
{
2892+
ftrace_set_regex(ops, buf, len, reset, 0);
2893+
}
2894+
EXPORT_SYMBOL_GPL(ftrace_set_notrace);
2895+
/**
2896+
* ftrace_set_filter - set a function to filter on in ftrace
2897+
* @ops - the ops to set the filter with
28592898
* @buf - the string that holds the function filter text.
28602899
* @len - the length of the string.
28612900
* @reset - non zero to reset all filters before applying this filter.
28622901
*
28632902
* Filters denote which functions should be enabled when tracing is enabled.
28642903
* If @buf is NULL and reset is set, all functions will be enabled for tracing.
28652904
*/
2866-
void ftrace_set_filter(unsigned char *buf, int len, int reset)
2905+
void ftrace_set_global_filter(unsigned char *buf, int len, int reset)
28672906
{
28682907
ftrace_set_regex(&global_ops, buf, len, reset, 1);
28692908
}
2909+
EXPORT_SYMBOL_GPL(ftrace_set_global_filter);
28702910

28712911
/**
28722912
* ftrace_set_notrace - set a function to not trace in ftrace
2913+
* @ops - the ops to set the notrace filter with
28732914
* @buf - the string that holds the function notrace text.
28742915
* @len - the length of the string.
28752916
* @reset - non zero to reset all filters before applying this filter.
@@ -2878,10 +2919,11 @@ void ftrace_set_filter(unsigned char *buf, int len, int reset)
28782919
* is enabled. If @buf is NULL and reset is set, all functions will be enabled
28792920
* for tracing.
28802921
*/
2881-
void ftrace_set_notrace(unsigned char *buf, int len, int reset)
2922+
void ftrace_set_global_notrace(unsigned char *buf, int len, int reset)
28822923
{
28832924
ftrace_set_regex(&global_ops, buf, len, reset, 0);
28842925
}
2926+
EXPORT_SYMBOL_GPL(ftrace_set_global_notrace);
28852927

28862928
/*
28872929
* command line interface to allow users to set filters on boot up.

kernel/trace/trace_selftest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
131131
func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
132132

133133
/* filter only on our function */
134-
ftrace_set_filter(func_name, strlen(func_name), 1);
134+
ftrace_set_global_filter(func_name, strlen(func_name), 1);
135135

136136
/* enable tracing */
137137
ret = tracer_init(trace, tr);
@@ -181,7 +181,7 @@ int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
181181
tracer_enabled = save_tracer_enabled;
182182

183183
/* Enable tracing on all functions again */
184-
ftrace_set_filter(NULL, 0, 1);
184+
ftrace_set_global_filter(NULL, 0, 1);
185185

186186
return ret;
187187
}

0 commit comments

Comments
 (0)