Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 491d0dcf authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt
Browse files

ftrace: Consolidate updating of ftrace_trace_function



There are three locations that perform almost identical functions in order
to update the ftrace_trace_function (the ftrace function variable that gets
called by mcount).

Consolidate these into a single function called update_ftrace_function().

Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 996e87be
Loading
Loading
Loading
Loading
+34 −61
Original line number Original line Diff line number Diff line
@@ -151,34 +151,26 @@ static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip)
}
}
#endif
#endif


static int __register_ftrace_function(struct ftrace_ops *ops)
static void update_ftrace_function(void)
{
{
	ops->next = ftrace_list;
	/*
	 * We are entering ops into the ftrace_list but another
	 * CPU might be walking that list. We need to make sure
	 * the ops->next pointer is valid before another CPU sees
	 * the ops pointer included into the ftrace_list.
	 */
	rcu_assign_pointer(ftrace_list, ops);

	if (ftrace_enabled) {
	ftrace_func_t func;
	ftrace_func_t func;


		if (ops->next == &ftrace_list_end)
	/*
			func = ops->func;
	 * If there's only one function registered, then call that
	 * function directly. Otherwise, we need to iterate over the
	 * registered callers.
	 */
	if (ftrace_list == &ftrace_list_end ||
	    ftrace_list->next == &ftrace_list_end)
		func = ftrace_list->func;
	else
	else
		func = ftrace_list_func;
		func = ftrace_list_func;


	/* If we filter on pids, update to use the pid function */
	if (!list_empty(&ftrace_pids)) {
	if (!list_empty(&ftrace_pids)) {
		set_ftrace_pid_function(func);
		set_ftrace_pid_function(func);
		func = ftrace_pid_func;
		func = ftrace_pid_func;
	}
	}

		/*
		 * For one func, simply call it directly.
		 * For more than one func, call the chain.
		 */
#ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
#ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
	ftrace_trace_function = func;
	ftrace_trace_function = func;
#else
#else
@@ -187,6 +179,20 @@ static int __register_ftrace_function(struct ftrace_ops *ops)
#endif
#endif
}
}


static int __register_ftrace_function(struct ftrace_ops *ops)
{
	ops->next = ftrace_list;
	/*
	 * We are entering ops into the ftrace_list but another
	 * CPU might be walking that list. We need to make sure
	 * the ops->next pointer is valid before another CPU sees
	 * the ops pointer included into the ftrace_list.
	 */
	rcu_assign_pointer(ftrace_list, ops);

	if (ftrace_enabled)
		update_ftrace_function();

	return 0;
	return 0;
}
}


@@ -213,52 +219,19 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops)


	*p = (*p)->next;
	*p = (*p)->next;


	if (ftrace_enabled) {
	if (ftrace_enabled)
		/* If we only have one func left, then call that directly */
		update_ftrace_function();
		if (ftrace_list->next == &ftrace_list_end) {
			ftrace_func_t func = ftrace_list->func;

			if (!list_empty(&ftrace_pids)) {
				set_ftrace_pid_function(func);
				func = ftrace_pid_func;
			}
#ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
			ftrace_trace_function = func;
#else
			__ftrace_trace_function = func;
#endif
		}
	}


	return 0;
	return 0;
}
}


static void ftrace_update_pid_func(void)
static void ftrace_update_pid_func(void)
{
{
	ftrace_func_t func;
	/* Only do something if we are tracing something */

	if (ftrace_trace_function == ftrace_stub)
	if (ftrace_trace_function == ftrace_stub)
		return;
		return;


#ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
	update_ftrace_function();
	func = ftrace_trace_function;
#else
	func = __ftrace_trace_function;
#endif

	if (!list_empty(&ftrace_pids)) {
		set_ftrace_pid_function(func);
		func = ftrace_pid_func;
	} else {
		if (func == ftrace_pid_func)
			func = ftrace_pid_function;
	}

#ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
	ftrace_trace_function = func;
#else
	__ftrace_trace_function = func;
#endif
}
}


#ifdef CONFIG_FUNCTION_PROFILER
#ifdef CONFIG_FUNCTION_PROFILER