diff options
Diffstat (limited to 'kernel/trace/ftrace.c')
-rw-r--r-- | kernel/trace/ftrace.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 2f32969c09df..fdf913dfc7e8 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/clocksource.h> | 17 | #include <linux/clocksource.h> |
18 | #include <linux/kallsyms.h> | 18 | #include <linux/kallsyms.h> |
19 | #include <linux/seq_file.h> | 19 | #include <linux/seq_file.h> |
20 | #include <linux/suspend.h> | ||
20 | #include <linux/debugfs.h> | 21 | #include <linux/debugfs.h> |
21 | #include <linux/hardirq.h> | 22 | #include <linux/hardirq.h> |
22 | #include <linux/kthread.h> | 23 | #include <linux/kthread.h> |
@@ -1736,9 +1737,12 @@ static void clear_ftrace_pid(struct pid *pid) | |||
1736 | { | 1737 | { |
1737 | struct task_struct *p; | 1738 | struct task_struct *p; |
1738 | 1739 | ||
1740 | rcu_read_lock(); | ||
1739 | do_each_pid_task(pid, PIDTYPE_PID, p) { | 1741 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
1740 | clear_tsk_trace_trace(p); | 1742 | clear_tsk_trace_trace(p); |
1741 | } while_each_pid_task(pid, PIDTYPE_PID, p); | 1743 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
1744 | rcu_read_unlock(); | ||
1745 | |||
1742 | put_pid(pid); | 1746 | put_pid(pid); |
1743 | } | 1747 | } |
1744 | 1748 | ||
@@ -1746,9 +1750,11 @@ static void set_ftrace_pid(struct pid *pid) | |||
1746 | { | 1750 | { |
1747 | struct task_struct *p; | 1751 | struct task_struct *p; |
1748 | 1752 | ||
1753 | rcu_read_lock(); | ||
1749 | do_each_pid_task(pid, PIDTYPE_PID, p) { | 1754 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
1750 | set_tsk_trace_trace(p); | 1755 | set_tsk_trace_trace(p); |
1751 | } while_each_pid_task(pid, PIDTYPE_PID, p); | 1756 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
1757 | rcu_read_unlock(); | ||
1752 | } | 1758 | } |
1753 | 1759 | ||
1754 | static void clear_ftrace_pid_task(struct pid **pid) | 1760 | static void clear_ftrace_pid_task(struct pid **pid) |
@@ -1965,6 +1971,7 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, | |||
1965 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 1971 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
1966 | 1972 | ||
1967 | static atomic_t ftrace_graph_active; | 1973 | static atomic_t ftrace_graph_active; |
1974 | static struct notifier_block ftrace_suspend_notifier; | ||
1968 | 1975 | ||
1969 | int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace) | 1976 | int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace) |
1970 | { | 1977 | { |
@@ -2026,7 +2033,7 @@ free: | |||
2026 | static int start_graph_tracing(void) | 2033 | static int start_graph_tracing(void) |
2027 | { | 2034 | { |
2028 | struct ftrace_ret_stack **ret_stack_list; | 2035 | struct ftrace_ret_stack **ret_stack_list; |
2029 | int ret; | 2036 | int ret, cpu; |
2030 | 2037 | ||
2031 | ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE * | 2038 | ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE * |
2032 | sizeof(struct ftrace_ret_stack *), | 2039 | sizeof(struct ftrace_ret_stack *), |
@@ -2035,6 +2042,10 @@ static int start_graph_tracing(void) | |||
2035 | if (!ret_stack_list) | 2042 | if (!ret_stack_list) |
2036 | return -ENOMEM; | 2043 | return -ENOMEM; |
2037 | 2044 | ||
2045 | /* The cpu_boot init_task->ret_stack will never be freed */ | ||
2046 | for_each_online_cpu(cpu) | ||
2047 | ftrace_graph_init_task(idle_task(cpu)); | ||
2048 | |||
2038 | do { | 2049 | do { |
2039 | ret = alloc_retstack_tasklist(ret_stack_list); | 2050 | ret = alloc_retstack_tasklist(ret_stack_list); |
2040 | } while (ret == -EAGAIN); | 2051 | } while (ret == -EAGAIN); |
@@ -2043,6 +2054,27 @@ static int start_graph_tracing(void) | |||
2043 | return ret; | 2054 | return ret; |
2044 | } | 2055 | } |
2045 | 2056 | ||
2057 | /* | ||
2058 | * Hibernation protection. | ||
2059 | * The state of the current task is too much unstable during | ||
2060 | * suspend/restore to disk. We want to protect against that. | ||
2061 | */ | ||
2062 | static int | ||
2063 | ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state, | ||
2064 | void *unused) | ||
2065 | { | ||
2066 | switch (state) { | ||
2067 | case PM_HIBERNATION_PREPARE: | ||
2068 | pause_graph_tracing(); | ||
2069 | break; | ||
2070 | |||
2071 | case PM_POST_HIBERNATION: | ||
2072 | unpause_graph_tracing(); | ||
2073 | break; | ||
2074 | } | ||
2075 | return NOTIFY_DONE; | ||
2076 | } | ||
2077 | |||
2046 | int register_ftrace_graph(trace_func_graph_ret_t retfunc, | 2078 | int register_ftrace_graph(trace_func_graph_ret_t retfunc, |
2047 | trace_func_graph_ent_t entryfunc) | 2079 | trace_func_graph_ent_t entryfunc) |
2048 | { | 2080 | { |
@@ -2050,6 +2082,9 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc, | |||
2050 | 2082 | ||
2051 | mutex_lock(&ftrace_sysctl_lock); | 2083 | mutex_lock(&ftrace_sysctl_lock); |
2052 | 2084 | ||
2085 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; | ||
2086 | register_pm_notifier(&ftrace_suspend_notifier); | ||
2087 | |||
2053 | atomic_inc(&ftrace_graph_active); | 2088 | atomic_inc(&ftrace_graph_active); |
2054 | ret = start_graph_tracing(); | 2089 | ret = start_graph_tracing(); |
2055 | if (ret) { | 2090 | if (ret) { |
@@ -2075,6 +2110,7 @@ void unregister_ftrace_graph(void) | |||
2075 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; | 2110 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
2076 | ftrace_graph_entry = ftrace_graph_entry_stub; | 2111 | ftrace_graph_entry = ftrace_graph_entry_stub; |
2077 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); | 2112 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
2113 | unregister_pm_notifier(&ftrace_suspend_notifier); | ||
2078 | 2114 | ||
2079 | mutex_unlock(&ftrace_sysctl_lock); | 2115 | mutex_unlock(&ftrace_sysctl_lock); |
2080 | } | 2116 | } |