Skip to content

Commit

Permalink
ftrace: Add helper function ftrace_ops_get_func()
Browse files Browse the repository at this point in the history
Add the helper function to what the mcount trampoline is to call
for a ftrace_ops function. This helper will be used by arch code
in the future to set up dynamic trampolines. But as this does the
same tests that are performed in choosing what function to call for
the default mcount trampoline, might as well use it to clean up
the existing code.

Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
rostedt committed Sep 9, 2014
1 parent f1ff634 commit 8735405
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/linux/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct ftrace_ops;
typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op, struct pt_regs *regs);

ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);

/*
* FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
* set in the flags member.
Expand Down
47 changes: 35 additions & 12 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,12 @@ static void update_ftrace_function(void)
* then have the mcount trampoline call the function directly.
*/
if (ftrace_ops_list == &ftrace_list_end ||
(ftrace_ops_list->next == &ftrace_list_end &&
!(ftrace_ops_list->flags & FTRACE_OPS_FL_DYNAMIC) &&
!FTRACE_FORCE_LIST_FUNC)) {
(ftrace_ops_list->next == &ftrace_list_end)) {

/* Set the ftrace_ops that the arch callback uses */
set_function_trace_op = ftrace_ops_list;
/*
* If the func handles its own recursion, call it directly.
* Otherwise call the recursion protected function that
* will call the ftrace ops function.
*/
if (ftrace_ops_list->flags & FTRACE_OPS_FL_RECURSION_SAFE)
func = ftrace_ops_list->func;
else
func = ftrace_ops_recurs_func;

func = ftrace_ops_get_func(ftrace_ops_list);
} else {
/* Just use the default ftrace_ops */
set_function_trace_op = &ftrace_list_end;
Expand Down Expand Up @@ -4856,6 +4848,37 @@ static void ftrace_ops_recurs_func(unsigned long ip, unsigned long parent_ip,
trace_clear_recursion(bit);
}

/**
* ftrace_ops_get_func - get the function a trampoline should call
* @ops: the ops to get the function for
*
* Normally the mcount trampoline will call the ops->func, but there
* are times that it should not. For example, if the ops does not
* have its own recursion protection, then it should call the
* ftrace_ops_recurs_func() instead.
*
* Returns the function that the trampoline should call for @ops.
*/
ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops)
{
/*
* If this is a dynamic ops or we force list func,
* then it needs to call the list anyway.
*/
if (ops->flags & FTRACE_OPS_FL_DYNAMIC || FTRACE_FORCE_LIST_FUNC)
return ftrace_ops_list_func;

/*
* If the func handles its own recursion, call it directly.
* Otherwise call the recursion protected function that
* will call the ftrace ops function.
*/
if (!(ops->flags & FTRACE_OPS_FL_RECURSION_SAFE))
return ftrace_ops_recurs_func;

return ops->func;
}

static void clear_ftrace_swapper(void)
{
struct task_struct *p;
Expand Down

0 comments on commit 8735405

Please sign in to comment.