diff options
Diffstat (limited to 'kernel/trace/ftrace.c')
-rw-r--r-- | kernel/trace/ftrace.c | 383 |
1 files changed, 240 insertions, 143 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 37ba67e33265..e51a1bcb7bed 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -60,6 +60,13 @@ static int last_ftrace_enabled; | |||
60 | /* Quick disabling of function tracer. */ | 60 | /* Quick disabling of function tracer. */ |
61 | int function_trace_stop; | 61 | int function_trace_stop; |
62 | 62 | ||
63 | /* List for set_ftrace_pid's pids. */ | ||
64 | LIST_HEAD(ftrace_pids); | ||
65 | struct ftrace_pid { | ||
66 | struct list_head list; | ||
67 | struct pid *pid; | ||
68 | }; | ||
69 | |||
63 | /* | 70 | /* |
64 | * ftrace_disabled is set when an anomaly is discovered. | 71 | * ftrace_disabled is set when an anomaly is discovered. |
65 | * ftrace_disabled is much stronger than ftrace_enabled. | 72 | * ftrace_disabled is much stronger than ftrace_enabled. |
@@ -78,6 +85,10 @@ ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; | |||
78 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; | 85 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; |
79 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; | 86 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; |
80 | 87 | ||
88 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
89 | static int ftrace_set_func(unsigned long *array, int *idx, char *buffer); | ||
90 | #endif | ||
91 | |||
81 | static void ftrace_list_func(unsigned long ip, unsigned long parent_ip) | 92 | static void ftrace_list_func(unsigned long ip, unsigned long parent_ip) |
82 | { | 93 | { |
83 | struct ftrace_ops *op = ftrace_list; | 94 | struct ftrace_ops *op = ftrace_list; |
@@ -155,7 +166,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops) | |||
155 | else | 166 | else |
156 | func = ftrace_list_func; | 167 | func = ftrace_list_func; |
157 | 168 | ||
158 | if (ftrace_pid_trace) { | 169 | if (!list_empty(&ftrace_pids)) { |
159 | set_ftrace_pid_function(func); | 170 | set_ftrace_pid_function(func); |
160 | func = ftrace_pid_func; | 171 | func = ftrace_pid_func; |
161 | } | 172 | } |
@@ -203,7 +214,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops) | |||
203 | if (ftrace_list->next == &ftrace_list_end) { | 214 | if (ftrace_list->next == &ftrace_list_end) { |
204 | ftrace_func_t func = ftrace_list->func; | 215 | ftrace_func_t func = ftrace_list->func; |
205 | 216 | ||
206 | if (ftrace_pid_trace) { | 217 | if (!list_empty(&ftrace_pids)) { |
207 | set_ftrace_pid_function(func); | 218 | set_ftrace_pid_function(func); |
208 | func = ftrace_pid_func; | 219 | func = ftrace_pid_func; |
209 | } | 220 | } |
@@ -231,7 +242,7 @@ static void ftrace_update_pid_func(void) | |||
231 | func = __ftrace_trace_function; | 242 | func = __ftrace_trace_function; |
232 | #endif | 243 | #endif |
233 | 244 | ||
234 | if (ftrace_pid_trace) { | 245 | if (!list_empty(&ftrace_pids)) { |
235 | set_ftrace_pid_function(func); | 246 | set_ftrace_pid_function(func); |
236 | func = ftrace_pid_func; | 247 | func = ftrace_pid_func; |
237 | } else { | 248 | } else { |
@@ -740,7 +751,7 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf, | |||
740 | out: | 751 | out: |
741 | mutex_unlock(&ftrace_profile_lock); | 752 | mutex_unlock(&ftrace_profile_lock); |
742 | 753 | ||
743 | filp->f_pos += cnt; | 754 | *ppos += cnt; |
744 | 755 | ||
745 | return cnt; | 756 | return cnt; |
746 | } | 757 | } |
@@ -821,8 +832,6 @@ static __init void ftrace_profile_debugfs(struct dentry *d_tracer) | |||
821 | } | 832 | } |
822 | #endif /* CONFIG_FUNCTION_PROFILER */ | 833 | #endif /* CONFIG_FUNCTION_PROFILER */ |
823 | 834 | ||
824 | /* set when tracing only a pid */ | ||
825 | struct pid *ftrace_pid_trace; | ||
826 | static struct pid * const ftrace_swapper_pid = &init_struct_pid; | 835 | static struct pid * const ftrace_swapper_pid = &init_struct_pid; |
827 | 836 | ||
828 | #ifdef CONFIG_DYNAMIC_FTRACE | 837 | #ifdef CONFIG_DYNAMIC_FTRACE |
@@ -1261,12 +1270,34 @@ static int ftrace_update_code(struct module *mod) | |||
1261 | ftrace_new_addrs = p->newlist; | 1270 | ftrace_new_addrs = p->newlist; |
1262 | p->flags = 0L; | 1271 | p->flags = 0L; |
1263 | 1272 | ||
1264 | /* convert record (i.e, patch mcount-call with NOP) */ | 1273 | /* |
1265 | if (ftrace_code_disable(mod, p)) { | 1274 | * Do the initial record convertion from mcount jump |
1266 | p->flags |= FTRACE_FL_CONVERTED; | 1275 | * to the NOP instructions. |
1267 | ftrace_update_cnt++; | 1276 | */ |
1268 | } else | 1277 | if (!ftrace_code_disable(mod, p)) { |
1269 | ftrace_free_rec(p); | 1278 | ftrace_free_rec(p); |
1279 | continue; | ||
1280 | } | ||
1281 | |||
1282 | p->flags |= FTRACE_FL_CONVERTED; | ||
1283 | ftrace_update_cnt++; | ||
1284 | |||
1285 | /* | ||
1286 | * If the tracing is enabled, go ahead and enable the record. | ||
1287 | * | ||
1288 | * The reason not to enable the record immediatelly is the | ||
1289 | * inherent check of ftrace_make_nop/ftrace_make_call for | ||
1290 | * correct previous instructions. Making first the NOP | ||
1291 | * conversion puts the module to the correct state, thus | ||
1292 | * passing the ftrace_make_call check. | ||
1293 | */ | ||
1294 | if (ftrace_start_up) { | ||
1295 | int failed = __ftrace_replace_code(p, 1); | ||
1296 | if (failed) { | ||
1297 | ftrace_bug(failed, p->ip); | ||
1298 | ftrace_free_rec(p); | ||
1299 | } | ||
1300 | } | ||
1270 | } | 1301 | } |
1271 | 1302 | ||
1272 | stop = ftrace_now(raw_smp_processor_id()); | 1303 | stop = ftrace_now(raw_smp_processor_id()); |
@@ -1656,60 +1687,6 @@ ftrace_regex_lseek(struct file *file, loff_t offset, int origin) | |||
1656 | return ret; | 1687 | return ret; |
1657 | } | 1688 | } |
1658 | 1689 | ||
1659 | enum { | ||
1660 | MATCH_FULL, | ||
1661 | MATCH_FRONT_ONLY, | ||
1662 | MATCH_MIDDLE_ONLY, | ||
1663 | MATCH_END_ONLY, | ||
1664 | }; | ||
1665 | |||
1666 | /* | ||
1667 | * (static function - no need for kernel doc) | ||
1668 | * | ||
1669 | * Pass in a buffer containing a glob and this function will | ||
1670 | * set search to point to the search part of the buffer and | ||
1671 | * return the type of search it is (see enum above). | ||
1672 | * This does modify buff. | ||
1673 | * | ||
1674 | * Returns enum type. | ||
1675 | * search returns the pointer to use for comparison. | ||
1676 | * not returns 1 if buff started with a '!' | ||
1677 | * 0 otherwise. | ||
1678 | */ | ||
1679 | static int | ||
1680 | ftrace_setup_glob(char *buff, int len, char **search, int *not) | ||
1681 | { | ||
1682 | int type = MATCH_FULL; | ||
1683 | int i; | ||
1684 | |||
1685 | if (buff[0] == '!') { | ||
1686 | *not = 1; | ||
1687 | buff++; | ||
1688 | len--; | ||
1689 | } else | ||
1690 | *not = 0; | ||
1691 | |||
1692 | *search = buff; | ||
1693 | |||
1694 | for (i = 0; i < len; i++) { | ||
1695 | if (buff[i] == '*') { | ||
1696 | if (!i) { | ||
1697 | *search = buff + 1; | ||
1698 | type = MATCH_END_ONLY; | ||
1699 | } else { | ||
1700 | if (type == MATCH_END_ONLY) | ||
1701 | type = MATCH_MIDDLE_ONLY; | ||
1702 | else | ||
1703 | type = MATCH_FRONT_ONLY; | ||
1704 | buff[i] = 0; | ||
1705 | break; | ||
1706 | } | ||
1707 | } | ||
1708 | } | ||
1709 | |||
1710 | return type; | ||
1711 | } | ||
1712 | |||
1713 | static int ftrace_match(char *str, char *regex, int len, int type) | 1690 | static int ftrace_match(char *str, char *regex, int len, int type) |
1714 | { | 1691 | { |
1715 | int matched = 0; | 1692 | int matched = 0; |
@@ -1758,7 +1735,7 @@ static void ftrace_match_records(char *buff, int len, int enable) | |||
1758 | int not; | 1735 | int not; |
1759 | 1736 | ||
1760 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; | 1737 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
1761 | type = ftrace_setup_glob(buff, len, &search, ¬); | 1738 | type = filter_parse_regex(buff, len, &search, ¬); |
1762 | 1739 | ||
1763 | search_len = strlen(search); | 1740 | search_len = strlen(search); |
1764 | 1741 | ||
@@ -1826,7 +1803,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable) | |||
1826 | } | 1803 | } |
1827 | 1804 | ||
1828 | if (strlen(buff)) { | 1805 | if (strlen(buff)) { |
1829 | type = ftrace_setup_glob(buff, strlen(buff), &search, ¬); | 1806 | type = filter_parse_regex(buff, strlen(buff), &search, ¬); |
1830 | search_len = strlen(search); | 1807 | search_len = strlen(search); |
1831 | } | 1808 | } |
1832 | 1809 | ||
@@ -1991,7 +1968,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
1991 | int count = 0; | 1968 | int count = 0; |
1992 | char *search; | 1969 | char *search; |
1993 | 1970 | ||
1994 | type = ftrace_setup_glob(glob, strlen(glob), &search, ¬); | 1971 | type = filter_parse_regex(glob, strlen(glob), &search, ¬); |
1995 | len = strlen(search); | 1972 | len = strlen(search); |
1996 | 1973 | ||
1997 | /* we do not support '!' for function probes */ | 1974 | /* we do not support '!' for function probes */ |
@@ -2068,7 +2045,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
2068 | else if (glob) { | 2045 | else if (glob) { |
2069 | int not; | 2046 | int not; |
2070 | 2047 | ||
2071 | type = ftrace_setup_glob(glob, strlen(glob), &search, ¬); | 2048 | type = filter_parse_regex(glob, strlen(glob), &search, ¬); |
2072 | len = strlen(search); | 2049 | len = strlen(search); |
2073 | 2050 | ||
2074 | /* we do not support '!' for function probes */ | 2051 | /* we do not support '!' for function probes */ |
@@ -2222,15 +2199,15 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
2222 | ret = ftrace_process_regex(parser->buffer, | 2199 | ret = ftrace_process_regex(parser->buffer, |
2223 | parser->idx, enable); | 2200 | parser->idx, enable); |
2224 | if (ret) | 2201 | if (ret) |
2225 | goto out; | 2202 | goto out_unlock; |
2226 | 2203 | ||
2227 | trace_parser_clear(parser); | 2204 | trace_parser_clear(parser); |
2228 | } | 2205 | } |
2229 | 2206 | ||
2230 | ret = read; | 2207 | ret = read; |
2231 | 2208 | out_unlock: | |
2232 | mutex_unlock(&ftrace_regex_lock); | 2209 | mutex_unlock(&ftrace_regex_lock); |
2233 | out: | 2210 | |
2234 | return ret; | 2211 | return ret; |
2235 | } | 2212 | } |
2236 | 2213 | ||
@@ -2312,6 +2289,32 @@ static int __init set_ftrace_filter(char *str) | |||
2312 | } | 2289 | } |
2313 | __setup("ftrace_filter=", set_ftrace_filter); | 2290 | __setup("ftrace_filter=", set_ftrace_filter); |
2314 | 2291 | ||
2292 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
2293 | static char ftrace_graph_buf[FTRACE_FILTER_SIZE] __initdata; | ||
2294 | static int __init set_graph_function(char *str) | ||
2295 | { | ||
2296 | strlcpy(ftrace_graph_buf, str, FTRACE_FILTER_SIZE); | ||
2297 | return 1; | ||
2298 | } | ||
2299 | __setup("ftrace_graph_filter=", set_graph_function); | ||
2300 | |||
2301 | static void __init set_ftrace_early_graph(char *buf) | ||
2302 | { | ||
2303 | int ret; | ||
2304 | char *func; | ||
2305 | |||
2306 | while (buf) { | ||
2307 | func = strsep(&buf, ","); | ||
2308 | /* we allow only one expression at a time */ | ||
2309 | ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count, | ||
2310 | func); | ||
2311 | if (ret) | ||
2312 | printk(KERN_DEBUG "ftrace: function %s not " | ||
2313 | "traceable\n", func); | ||
2314 | } | ||
2315 | } | ||
2316 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
2317 | |||
2315 | static void __init set_ftrace_early_filter(char *buf, int enable) | 2318 | static void __init set_ftrace_early_filter(char *buf, int enable) |
2316 | { | 2319 | { |
2317 | char *func; | 2320 | char *func; |
@@ -2328,6 +2331,10 @@ static void __init set_ftrace_early_filters(void) | |||
2328 | set_ftrace_early_filter(ftrace_filter_buf, 1); | 2331 | set_ftrace_early_filter(ftrace_filter_buf, 1); |
2329 | if (ftrace_notrace_buf[0]) | 2332 | if (ftrace_notrace_buf[0]) |
2330 | set_ftrace_early_filter(ftrace_notrace_buf, 0); | 2333 | set_ftrace_early_filter(ftrace_notrace_buf, 0); |
2334 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
2335 | if (ftrace_graph_buf[0]) | ||
2336 | set_ftrace_early_graph(ftrace_graph_buf); | ||
2337 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
2331 | } | 2338 | } |
2332 | 2339 | ||
2333 | static int | 2340 | static int |
@@ -2513,7 +2520,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer) | |||
2513 | return -ENODEV; | 2520 | return -ENODEV; |
2514 | 2521 | ||
2515 | /* decode regex */ | 2522 | /* decode regex */ |
2516 | type = ftrace_setup_glob(buffer, strlen(buffer), &search, ¬); | 2523 | type = filter_parse_regex(buffer, strlen(buffer), &search, ¬); |
2517 | if (not) | 2524 | if (not) |
2518 | return -EINVAL; | 2525 | return -EINVAL; |
2519 | 2526 | ||
@@ -2624,7 +2631,7 @@ static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer) | |||
2624 | return 0; | 2631 | return 0; |
2625 | } | 2632 | } |
2626 | 2633 | ||
2627 | static int ftrace_convert_nops(struct module *mod, | 2634 | static int ftrace_process_locs(struct module *mod, |
2628 | unsigned long *start, | 2635 | unsigned long *start, |
2629 | unsigned long *end) | 2636 | unsigned long *end) |
2630 | { | 2637 | { |
@@ -2684,7 +2691,7 @@ static void ftrace_init_module(struct module *mod, | |||
2684 | { | 2691 | { |
2685 | if (ftrace_disabled || start == end) | 2692 | if (ftrace_disabled || start == end) |
2686 | return; | 2693 | return; |
2687 | ftrace_convert_nops(mod, start, end); | 2694 | ftrace_process_locs(mod, start, end); |
2688 | } | 2695 | } |
2689 | 2696 | ||
2690 | static int ftrace_module_notify(struct notifier_block *self, | 2697 | static int ftrace_module_notify(struct notifier_block *self, |
@@ -2745,7 +2752,7 @@ void __init ftrace_init(void) | |||
2745 | 2752 | ||
2746 | last_ftrace_enabled = ftrace_enabled = 1; | 2753 | last_ftrace_enabled = ftrace_enabled = 1; |
2747 | 2754 | ||
2748 | ret = ftrace_convert_nops(NULL, | 2755 | ret = ftrace_process_locs(NULL, |
2749 | __start_mcount_loc, | 2756 | __start_mcount_loc, |
2750 | __stop_mcount_loc); | 2757 | __stop_mcount_loc); |
2751 | 2758 | ||
@@ -2778,23 +2785,6 @@ static inline void ftrace_startup_enable(int command) { } | |||
2778 | # define ftrace_shutdown_sysctl() do { } while (0) | 2785 | # define ftrace_shutdown_sysctl() do { } while (0) |
2779 | #endif /* CONFIG_DYNAMIC_FTRACE */ | 2786 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
2780 | 2787 | ||
2781 | static ssize_t | ||
2782 | ftrace_pid_read(struct file *file, char __user *ubuf, | ||
2783 | size_t cnt, loff_t *ppos) | ||
2784 | { | ||
2785 | char buf[64]; | ||
2786 | int r; | ||
2787 | |||
2788 | if (ftrace_pid_trace == ftrace_swapper_pid) | ||
2789 | r = sprintf(buf, "swapper tasks\n"); | ||
2790 | else if (ftrace_pid_trace) | ||
2791 | r = sprintf(buf, "%u\n", pid_vnr(ftrace_pid_trace)); | ||
2792 | else | ||
2793 | r = sprintf(buf, "no pid\n"); | ||
2794 | |||
2795 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | ||
2796 | } | ||
2797 | |||
2798 | static void clear_ftrace_swapper(void) | 2788 | static void clear_ftrace_swapper(void) |
2799 | { | 2789 | { |
2800 | struct task_struct *p; | 2790 | struct task_struct *p; |
@@ -2845,14 +2835,12 @@ static void set_ftrace_pid(struct pid *pid) | |||
2845 | rcu_read_unlock(); | 2835 | rcu_read_unlock(); |
2846 | } | 2836 | } |
2847 | 2837 | ||
2848 | static void clear_ftrace_pid_task(struct pid **pid) | 2838 | static void clear_ftrace_pid_task(struct pid *pid) |
2849 | { | 2839 | { |
2850 | if (*pid == ftrace_swapper_pid) | 2840 | if (pid == ftrace_swapper_pid) |
2851 | clear_ftrace_swapper(); | 2841 | clear_ftrace_swapper(); |
2852 | else | 2842 | else |
2853 | clear_ftrace_pid(*pid); | 2843 | clear_ftrace_pid(pid); |
2854 | |||
2855 | *pid = NULL; | ||
2856 | } | 2844 | } |
2857 | 2845 | ||
2858 | static void set_ftrace_pid_task(struct pid *pid) | 2846 | static void set_ftrace_pid_task(struct pid *pid) |
@@ -2863,74 +2851,184 @@ static void set_ftrace_pid_task(struct pid *pid) | |||
2863 | set_ftrace_pid(pid); | 2851 | set_ftrace_pid(pid); |
2864 | } | 2852 | } |
2865 | 2853 | ||
2866 | static ssize_t | 2854 | static int ftrace_pid_add(int p) |
2867 | ftrace_pid_write(struct file *filp, const char __user *ubuf, | ||
2868 | size_t cnt, loff_t *ppos) | ||
2869 | { | 2855 | { |
2870 | struct pid *pid; | 2856 | struct pid *pid; |
2871 | char buf[64]; | 2857 | struct ftrace_pid *fpid; |
2872 | long val; | 2858 | int ret = -EINVAL; |
2873 | int ret; | ||
2874 | 2859 | ||
2875 | if (cnt >= sizeof(buf)) | 2860 | mutex_lock(&ftrace_lock); |
2876 | return -EINVAL; | ||
2877 | 2861 | ||
2878 | if (copy_from_user(&buf, ubuf, cnt)) | 2862 | if (!p) |
2879 | return -EFAULT; | 2863 | pid = ftrace_swapper_pid; |
2864 | else | ||
2865 | pid = find_get_pid(p); | ||
2880 | 2866 | ||
2881 | buf[cnt] = 0; | 2867 | if (!pid) |
2868 | goto out; | ||
2882 | 2869 | ||
2883 | ret = strict_strtol(buf, 10, &val); | 2870 | ret = 0; |
2884 | if (ret < 0) | ||
2885 | return ret; | ||
2886 | 2871 | ||
2887 | mutex_lock(&ftrace_lock); | 2872 | list_for_each_entry(fpid, &ftrace_pids, list) |
2888 | if (val < 0) { | 2873 | if (fpid->pid == pid) |
2889 | /* disable pid tracing */ | 2874 | goto out_put; |
2890 | if (!ftrace_pid_trace) | ||
2891 | goto out; | ||
2892 | 2875 | ||
2893 | clear_ftrace_pid_task(&ftrace_pid_trace); | 2876 | ret = -ENOMEM; |
2894 | 2877 | ||
2895 | } else { | 2878 | fpid = kmalloc(sizeof(*fpid), GFP_KERNEL); |
2896 | /* swapper task is special */ | 2879 | if (!fpid) |
2897 | if (!val) { | 2880 | goto out_put; |
2898 | pid = ftrace_swapper_pid; | ||
2899 | if (pid == ftrace_pid_trace) | ||
2900 | goto out; | ||
2901 | } else { | ||
2902 | pid = find_get_pid(val); | ||
2903 | 2881 | ||
2904 | if (pid == ftrace_pid_trace) { | 2882 | list_add(&fpid->list, &ftrace_pids); |
2905 | put_pid(pid); | 2883 | fpid->pid = pid; |
2906 | goto out; | ||
2907 | } | ||
2908 | } | ||
2909 | 2884 | ||
2910 | if (ftrace_pid_trace) | 2885 | set_ftrace_pid_task(pid); |
2911 | clear_ftrace_pid_task(&ftrace_pid_trace); | ||
2912 | 2886 | ||
2913 | if (!pid) | 2887 | ftrace_update_pid_func(); |
2914 | goto out; | 2888 | ftrace_startup_enable(0); |
2889 | |||
2890 | mutex_unlock(&ftrace_lock); | ||
2891 | return 0; | ||
2892 | |||
2893 | out_put: | ||
2894 | if (pid != ftrace_swapper_pid) | ||
2895 | put_pid(pid); | ||
2896 | |||
2897 | out: | ||
2898 | mutex_unlock(&ftrace_lock); | ||
2899 | return ret; | ||
2900 | } | ||
2901 | |||
2902 | static void ftrace_pid_reset(void) | ||
2903 | { | ||
2904 | struct ftrace_pid *fpid, *safe; | ||
2905 | |||
2906 | mutex_lock(&ftrace_lock); | ||
2907 | list_for_each_entry_safe(fpid, safe, &ftrace_pids, list) { | ||
2908 | struct pid *pid = fpid->pid; | ||
2915 | 2909 | ||
2916 | ftrace_pid_trace = pid; | 2910 | clear_ftrace_pid_task(pid); |
2917 | 2911 | ||
2918 | set_ftrace_pid_task(ftrace_pid_trace); | 2912 | list_del(&fpid->list); |
2913 | kfree(fpid); | ||
2919 | } | 2914 | } |
2920 | 2915 | ||
2921 | /* update the function call */ | ||
2922 | ftrace_update_pid_func(); | 2916 | ftrace_update_pid_func(); |
2923 | ftrace_startup_enable(0); | 2917 | ftrace_startup_enable(0); |
2924 | 2918 | ||
2925 | out: | ||
2926 | mutex_unlock(&ftrace_lock); | 2919 | mutex_unlock(&ftrace_lock); |
2920 | } | ||
2927 | 2921 | ||
2928 | return cnt; | 2922 | static void *fpid_start(struct seq_file *m, loff_t *pos) |
2923 | { | ||
2924 | mutex_lock(&ftrace_lock); | ||
2925 | |||
2926 | if (list_empty(&ftrace_pids) && (!*pos)) | ||
2927 | return (void *) 1; | ||
2928 | |||
2929 | return seq_list_start(&ftrace_pids, *pos); | ||
2930 | } | ||
2931 | |||
2932 | static void *fpid_next(struct seq_file *m, void *v, loff_t *pos) | ||
2933 | { | ||
2934 | if (v == (void *)1) | ||
2935 | return NULL; | ||
2936 | |||
2937 | return seq_list_next(v, &ftrace_pids, pos); | ||
2938 | } | ||
2939 | |||
2940 | static void fpid_stop(struct seq_file *m, void *p) | ||
2941 | { | ||
2942 | mutex_unlock(&ftrace_lock); | ||
2943 | } | ||
2944 | |||
2945 | static int fpid_show(struct seq_file *m, void *v) | ||
2946 | { | ||
2947 | const struct ftrace_pid *fpid = list_entry(v, struct ftrace_pid, list); | ||
2948 | |||
2949 | if (v == (void *)1) { | ||
2950 | seq_printf(m, "no pid\n"); | ||
2951 | return 0; | ||
2952 | } | ||
2953 | |||
2954 | if (fpid->pid == ftrace_swapper_pid) | ||
2955 | seq_printf(m, "swapper tasks\n"); | ||
2956 | else | ||
2957 | seq_printf(m, "%u\n", pid_vnr(fpid->pid)); | ||
2958 | |||
2959 | return 0; | ||
2960 | } | ||
2961 | |||
2962 | static const struct seq_operations ftrace_pid_sops = { | ||
2963 | .start = fpid_start, | ||
2964 | .next = fpid_next, | ||
2965 | .stop = fpid_stop, | ||
2966 | .show = fpid_show, | ||
2967 | }; | ||
2968 | |||
2969 | static int | ||
2970 | ftrace_pid_open(struct inode *inode, struct file *file) | ||
2971 | { | ||
2972 | int ret = 0; | ||
2973 | |||
2974 | if ((file->f_mode & FMODE_WRITE) && | ||
2975 | (file->f_flags & O_TRUNC)) | ||
2976 | ftrace_pid_reset(); | ||
2977 | |||
2978 | if (file->f_mode & FMODE_READ) | ||
2979 | ret = seq_open(file, &ftrace_pid_sops); | ||
2980 | |||
2981 | return ret; | ||
2982 | } | ||
2983 | |||
2984 | static ssize_t | ||
2985 | ftrace_pid_write(struct file *filp, const char __user *ubuf, | ||
2986 | size_t cnt, loff_t *ppos) | ||
2987 | { | ||
2988 | char buf[64], *tmp; | ||
2989 | long val; | ||
2990 | int ret; | ||
2991 | |||
2992 | if (cnt >= sizeof(buf)) | ||
2993 | return -EINVAL; | ||
2994 | |||
2995 | if (copy_from_user(&buf, ubuf, cnt)) | ||
2996 | return -EFAULT; | ||
2997 | |||
2998 | buf[cnt] = 0; | ||
2999 | |||
3000 | /* | ||
3001 | * Allow "echo > set_ftrace_pid" or "echo -n '' > set_ftrace_pid" | ||
3002 | * to clean the filter quietly. | ||
3003 | */ | ||
3004 | tmp = strstrip(buf); | ||
3005 | if (strlen(tmp) == 0) | ||
3006 | return 1; | ||
3007 | |||
3008 | ret = strict_strtol(tmp, 10, &val); | ||
3009 | if (ret < 0) | ||
3010 | return ret; | ||
3011 | |||
3012 | ret = ftrace_pid_add(val); | ||
3013 | |||
3014 | return ret ? ret : cnt; | ||
3015 | } | ||
3016 | |||
3017 | static int | ||
3018 | ftrace_pid_release(struct inode *inode, struct file *file) | ||
3019 | { | ||
3020 | if (file->f_mode & FMODE_READ) | ||
3021 | seq_release(inode, file); | ||
3022 | |||
3023 | return 0; | ||
2929 | } | 3024 | } |
2930 | 3025 | ||
2931 | static const struct file_operations ftrace_pid_fops = { | 3026 | static const struct file_operations ftrace_pid_fops = { |
2932 | .read = ftrace_pid_read, | 3027 | .open = ftrace_pid_open, |
2933 | .write = ftrace_pid_write, | 3028 | .write = ftrace_pid_write, |
3029 | .read = seq_read, | ||
3030 | .llseek = seq_lseek, | ||
3031 | .release = ftrace_pid_release, | ||
2934 | }; | 3032 | }; |
2935 | 3033 | ||
2936 | static __init int ftrace_init_debugfs(void) | 3034 | static __init int ftrace_init_debugfs(void) |
@@ -3293,4 +3391,3 @@ void ftrace_graph_stop(void) | |||
3293 | ftrace_stop(); | 3391 | ftrace_stop(); |
3294 | } | 3392 | } |
3295 | #endif | 3393 | #endif |
3296 | |||