blob: eff099123aa2717df7da6be4f26d34294fdd1e3d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Steven Rostedt1f0d69a2008-11-12 00:14:39 -05002/*
3 * unlikely profiler
4 *
5 * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com>
6 */
7#include <linux/kallsyms.h>
8#include <linux/seq_file.h>
9#include <linux/spinlock.h>
Frederic Weisbecker65c6dc62008-11-29 04:12:46 +010010#include <linux/irqflags.h>
Steven Rostedt1f0d69a2008-11-12 00:14:39 -050011#include <linux/uaccess.h>
12#include <linux/module.h>
13#include <linux/ftrace.h>
14#include <linux/hash.h>
15#include <linux/fs.h>
16#include <asm/local.h>
Steven Rostedtf633cef2008-12-23 23:24:13 -050017
Steven Rostedt1f0d69a2008-11-12 00:14:39 -050018#include "trace.h"
Frederic Weisbecker002bb862009-01-10 11:34:13 -080019#include "trace_stat.h"
Steven Rostedtf633cef2008-12-23 23:24:13 -050020#include "trace_output.h"
Steven Rostedt1f0d69a2008-11-12 00:14:39 -050021
Steven Rostedt2ed84ee2008-11-12 15:24:24 -050022#ifdef CONFIG_BRANCH_TRACER
Steven Rostedt52f232c2008-11-12 00:14:40 -050023
Frederic Weisbecker002bb862009-01-10 11:34:13 -080024static struct tracer branch_trace;
Steven Rostedt9f029e82008-11-12 15:24:24 -050025static int branch_tracing_enabled __read_mostly;
26static DEFINE_MUTEX(branch_tracing_mutex);
Frederic Weisbeckere302cf32008-12-27 23:25:38 +010027
Steven Rostedt9f029e82008-11-12 15:24:24 -050028static struct trace_array *branch_tracer;
Steven Rostedt52f232c2008-11-12 00:14:40 -050029
30static void
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -050031probe_likely_condition(struct ftrace_likely_data *f, int val, int expect)
Steven Rostedt52f232c2008-11-12 00:14:40 -050032{
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -040033 struct trace_event_call *call = &event_branch;
Steven Rostedt9f029e82008-11-12 15:24:24 -050034 struct trace_array *tr = branch_tracer;
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -050035 struct trace_buffer *buffer;
Steven Rostedta7603ff2012-08-06 16:24:11 -040036 struct trace_array_cpu *data;
Steven Rostedt52f232c2008-11-12 00:14:40 -050037 struct ring_buffer_event *event;
Steven Rostedt9f029e82008-11-12 15:24:24 -050038 struct trace_branch *entry;
Arnaldo Carvalho de Melo0a987752009-02-05 16:12:56 -020039 unsigned long flags;
Steven Rostedt (Red Hat)6224beb2015-07-07 15:05:03 -040040 int pc;
Steven Rostedt52f232c2008-11-12 00:14:40 -050041 const char *p;
42
Steven Rostedt (Red Hat)6224beb2015-07-07 15:05:03 -040043 if (current->trace_recursion & TRACE_BRANCH_BIT)
44 return;
45
Steven Rostedt52f232c2008-11-12 00:14:40 -050046 /*
47 * I would love to save just the ftrace_likely_data pointer, but
48 * this code can also be used by modules. Ugly things can happen
49 * if the module is unloaded, and then we go and read the
50 * pointer. This is slower, but much safer.
51 */
52
53 if (unlikely(!tr))
54 return;
55
Steven Rostedt (Red Hat)6224beb2015-07-07 15:05:03 -040056 raw_local_irq_save(flags);
57 current->trace_recursion |= TRACE_BRANCH_BIT;
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -050058 data = this_cpu_ptr(tr->array_buffer.data);
Steven Rostedt (Red Hat)6224beb2015-07-07 15:05:03 -040059 if (atomic_read(&data->disabled))
Steven Rostedt52f232c2008-11-12 00:14:40 -050060 goto out;
61
Arnaldo Carvalho de Melo51a763d2009-02-05 16:14:13 -020062 pc = preempt_count();
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -050063 buffer = tr->array_buffer.buffer;
Steven Rostedt8f6e8a32009-10-07 21:53:41 -040064 event = trace_buffer_lock_reserve(buffer, TRACE_BRANCH,
Arnaldo Carvalho de Melo51a763d2009-02-05 16:14:13 -020065 sizeof(*entry), flags, pc);
Steven Rostedt52f232c2008-11-12 00:14:40 -050066 if (!event)
67 goto out;
68
Steven Rostedt52f232c2008-11-12 00:14:40 -050069 entry = ring_buffer_event_data(event);
Steven Rostedt52f232c2008-11-12 00:14:40 -050070
71 /* Strip off the path, only save the file */
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -050072 p = f->data.file + strlen(f->data.file);
73 while (p >= f->data.file && *p != '/')
Steven Rostedt52f232c2008-11-12 00:14:40 -050074 p--;
75 p++;
76
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -050077 strncpy(entry->func, f->data.func, TRACE_FUNC_SIZE);
Steven Rostedt52f232c2008-11-12 00:14:40 -050078 strncpy(entry->file, p, TRACE_FILE_SIZE);
79 entry->func[TRACE_FUNC_SIZE] = 0;
80 entry->file[TRACE_FILE_SIZE] = 0;
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -050081 entry->constant = f->constant;
82 entry->line = f->data.line;
Steven Rostedt52f232c2008-11-12 00:14:40 -050083 entry->correct = val == expect;
84
Tom Zanussif306cc82013-10-24 08:34:17 -050085 if (!call_filter_check_discard(call, entry, buffer, event))
Steven Rostedt (Red Hat)52ffabe32016-11-23 20:28:38 -050086 trace_buffer_unlock_commit_nostack(buffer, event);
Steven Rostedt52f232c2008-11-12 00:14:40 -050087
88 out:
Steven Rostedt (Red Hat)6224beb2015-07-07 15:05:03 -040089 current->trace_recursion &= ~TRACE_BRANCH_BIT;
90 raw_local_irq_restore(flags);
Steven Rostedt52f232c2008-11-12 00:14:40 -050091}
92
93static inline
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -050094void trace_likely_condition(struct ftrace_likely_data *f, int val, int expect)
Steven Rostedt52f232c2008-11-12 00:14:40 -050095{
Steven Rostedt9f029e82008-11-12 15:24:24 -050096 if (!branch_tracing_enabled)
Steven Rostedt52f232c2008-11-12 00:14:40 -050097 return;
98
99 probe_likely_condition(f, val, expect);
100}
101
Steven Rostedt9f029e82008-11-12 15:24:24 -0500102int enable_branch_tracing(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500103{
Steven Rostedt9f029e82008-11-12 15:24:24 -0500104 mutex_lock(&branch_tracing_mutex);
105 branch_tracer = tr;
Steven Rostedt52f232c2008-11-12 00:14:40 -0500106 /*
107 * Must be seen before enabling. The reader is a condition
108 * where we do not need a matching rmb()
109 */
110 smp_wmb();
Steven Rostedt9f029e82008-11-12 15:24:24 -0500111 branch_tracing_enabled++;
112 mutex_unlock(&branch_tracing_mutex);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500113
Wenji Huangf54fc982009-02-10 01:02:46 -0500114 return 0;
Steven Rostedt52f232c2008-11-12 00:14:40 -0500115}
116
Steven Rostedt9f029e82008-11-12 15:24:24 -0500117void disable_branch_tracing(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500118{
Steven Rostedt9f029e82008-11-12 15:24:24 -0500119 mutex_lock(&branch_tracing_mutex);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500120
Steven Rostedt9f029e82008-11-12 15:24:24 -0500121 if (!branch_tracing_enabled)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500122 goto out_unlock;
123
Steven Rostedt9f029e82008-11-12 15:24:24 -0500124 branch_tracing_enabled--;
Steven Rostedt52f232c2008-11-12 00:14:40 -0500125
126 out_unlock:
Steven Rostedt9f029e82008-11-12 15:24:24 -0500127 mutex_unlock(&branch_tracing_mutex);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500128}
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500129
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100130static int branch_trace_init(struct trace_array *tr)
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500131{
Dmitry Safonov30616922015-10-16 16:04:49 +0300132 return enable_branch_tracing(tr);
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500133}
134
135static void branch_trace_reset(struct trace_array *tr)
136{
Dmitry Safonov30616922015-10-16 16:04:49 +0300137 disable_branch_tracing();
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500138}
139
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200140static enum print_line_t trace_branch_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400141 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500142{
143 struct trace_branch *field;
144
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200145 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500146
Steven Rostedt (Red Hat)7d40f672014-11-12 13:19:06 -0500147 trace_seq_printf(&iter->seq, "[%s] %s:%s:%d\n",
148 field->correct ? " ok " : " MISS ",
149 field->func,
150 field->file,
151 field->line);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500152
Steven Rostedt (Red Hat)7d40f672014-11-12 13:19:06 -0500153 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500154}
155
Zhaolei557055b2009-04-13 16:02:34 +0800156static void branch_print_header(struct seq_file *s)
157{
158 seq_puts(s, "# TASK-PID CPU# TIMESTAMP CORRECT"
Rasmus Villemoesd79ac282014-11-08 21:42:11 +0100159 " FUNC:FILE:LINE\n"
160 "# | | | | | "
161 " |\n");
Zhaolei557055b2009-04-13 16:02:34 +0800162}
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100163
Steven Rostedta9a57762010-04-22 18:46:14 -0400164static struct trace_event_functions trace_branch_funcs = {
165 .trace = trace_branch_print,
166};
167
Steven Rostedtf633cef2008-12-23 23:24:13 -0500168static struct trace_event trace_branch_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400169 .type = TRACE_BRANCH,
Steven Rostedta9a57762010-04-22 18:46:14 -0400170 .funcs = &trace_branch_funcs,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500171};
172
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800173static struct tracer branch_trace __read_mostly =
174{
175 .name = "branch",
176 .init = branch_trace_init,
177 .reset = branch_trace_reset,
178#ifdef CONFIG_FTRACE_SELFTEST
179 .selftest = trace_selftest_startup_branch,
180#endif /* CONFIG_FTRACE_SELFTEST */
Zhaolei557055b2009-04-13 16:02:34 +0800181 .print_header = branch_print_header,
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800182};
183
184__init static int init_branch_tracer(void)
185{
186 int ret;
187
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400188 ret = register_trace_event(&trace_branch_event);
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800189 if (!ret) {
190 printk(KERN_WARNING "Warning: could not register "
191 "branch events\n");
192 return 1;
193 }
194 return register_tracer(&branch_trace);
195}
Steven Rostedt6f415672012-10-05 12:13:07 -0400196core_initcall(init_branch_tracer);
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800197
Steven Rostedt52f232c2008-11-12 00:14:40 -0500198#else
199static inline
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -0500200void trace_likely_condition(struct ftrace_likely_data *f, int val, int expect)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500201{
202}
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500203#endif /* CONFIG_BRANCH_TRACER */
Steven Rostedt52f232c2008-11-12 00:14:40 -0500204
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500205void ftrace_likely_update(struct ftrace_likely_data *f, int val,
Steven Rostedt (VMware)d45ae1f2017-01-17 12:29:35 -0500206 int expect, int is_constant)
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500207{
Peter Zijlstra4a6c91f2019-03-07 11:09:13 +0100208 unsigned long flags = user_access_save();
209
Steven Rostedt (VMware)d45ae1f2017-01-17 12:29:35 -0500210 /* A constant is always correct */
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500211 if (is_constant) {
212 f->constant++;
Steven Rostedt (VMware)d45ae1f2017-01-17 12:29:35 -0500213 val = expect;
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500214 }
Steven Rostedt52f232c2008-11-12 00:14:40 -0500215 /*
216 * I would love to have a trace point here instead, but the
217 * trace point code is so inundated with unlikely and likely
218 * conditions that the recursive nightmare that exists is too
219 * much to try to get working. At least for now.
220 */
Steven Rostedt (VMware)068f5302017-01-19 08:57:41 -0500221 trace_likely_condition(f, val, expect);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500222
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500223 /* FIXME: Make this atomic! */
224 if (val == expect)
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500225 f->data.correct++;
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500226 else
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500227 f->data.incorrect++;
Peter Zijlstra4a6c91f2019-03-07 11:09:13 +0100228
229 user_access_restore(flags);
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500230}
231EXPORT_SYMBOL(ftrace_likely_update);
232
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100233extern unsigned long __start_annotated_branch_profile[];
234extern unsigned long __stop_annotated_branch_profile[];
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500235
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100236static int annotated_branch_stat_headers(struct seq_file *m)
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500237{
Rasmus Villemoesd79ac282014-11-08 21:42:11 +0100238 seq_puts(m, " correct incorrect % "
239 " Function "
Rasmus Villemoesfa6f0cc2014-11-08 21:42:10 +0100240 " File Line\n"
241 " ------- --------- - "
242 " -------- "
243 " ---- ----\n");
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100244 return 0;
245}
246
Andy Shevchenko80042c82019-10-07 16:56:56 +0300247static inline long get_incorrect_percent(const struct ftrace_branch_data *p)
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100248{
249 long percent;
250
251 if (p->correct) {
252 percent = p->incorrect * 100;
253 percent /= p->correct + p->incorrect;
254 } else
255 percent = p->incorrect ? 100 : -1;
256
257 return percent;
258}
259
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500260static const char *branch_stat_process_file(struct ftrace_branch_data *p)
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100261{
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100262 const char *f;
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500263
264 /* Only print the file, not the path */
265 f = p->file + strlen(p->file);
266 while (f >= p->file && *f != '/')
267 f--;
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500268 return ++f;
269}
270
271static void branch_stat_show(struct seq_file *m,
272 struct ftrace_branch_data *p, const char *f)
273{
274 long percent;
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500275
Steven Rostedt2bcd5212008-11-21 01:30:54 -0500276 /*
277 * The miss is overlayed on correct, and hit on incorrect.
278 */
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100279 percent = get_incorrect_percent(p);
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500280
Steven Rostedtbac28bf2008-11-21 01:51:53 -0500281 if (percent < 0)
Rasmus Villemoesfa6f0cc2014-11-08 21:42:10 +0100282 seq_puts(m, " X ");
Steven Rostedtbac28bf2008-11-21 01:51:53 -0500283 else
284 seq_printf(m, "%3ld ", percent);
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500285
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500286 seq_printf(m, "%-30.30s %-20.20s %d\n", p->func, f, p->line);
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500287}
288
289static int branch_stat_show_normal(struct seq_file *m,
290 struct ftrace_branch_data *p, const char *f)
291{
292 seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
293 branch_stat_show(m, p, f);
294 return 0;
295}
296
297static int annotate_branch_stat_show(struct seq_file *m, void *v)
298{
299 struct ftrace_likely_data *p = v;
300 const char *f;
301 int l;
302
303 f = branch_stat_process_file(&p->data);
304
305 if (!p->constant)
306 return branch_stat_show_normal(m, &p->data, f);
307
308 l = snprintf(NULL, 0, "/%lu", p->constant);
309 l = l > 8 ? 0 : 8 - l;
310
311 seq_printf(m, "%8lu/%lu %*lu ",
312 p->data.correct, p->constant, l, p->data.incorrect);
313 branch_stat_show(m, &p->data, f);
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500314 return 0;
315}
316
Steven Rostedt42548002009-03-24 13:38:36 -0400317static void *annotated_branch_stat_start(struct tracer_stat *trace)
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500318{
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100319 return __start_annotated_branch_profile;
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500320}
321
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100322static void *
323annotated_branch_stat_next(void *v, int idx)
324{
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500325 struct ftrace_likely_data *p = v;
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100326
327 ++p;
328
329 if ((void *)p >= (void *)__stop_annotated_branch_profile)
330 return NULL;
331
332 return p;
333}
334
Andy Shevchenko80042c82019-10-07 16:56:56 +0300335static int annotated_branch_stat_cmp(const void *p1, const void *p2)
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100336{
Andy Shevchenko80042c82019-10-07 16:56:56 +0300337 const struct ftrace_branch_data *a = p1;
338 const struct ftrace_branch_data *b = p2;
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100339
340 long percent_a, percent_b;
341
342 percent_a = get_incorrect_percent(a);
343 percent_b = get_incorrect_percent(b);
344
345 if (percent_a < percent_b)
346 return -1;
347 if (percent_a > percent_b)
348 return 1;
Steven Rostedtede55c92010-01-27 11:25:54 -0500349
350 if (a->incorrect < b->incorrect)
351 return -1;
352 if (a->incorrect > b->incorrect)
353 return 1;
354
355 /*
356 * Since the above shows worse (incorrect) cases
357 * first, we continue that by showing best (correct)
358 * cases last.
359 */
360 if (a->correct > b->correct)
361 return -1;
362 if (a->correct < b->correct)
363 return 1;
364
365 return 0;
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100366}
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500367
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800368static struct tracer_stat annotated_branch_stats = {
369 .name = "branch_annotated",
370 .stat_start = annotated_branch_stat_start,
371 .stat_next = annotated_branch_stat_next,
372 .stat_cmp = annotated_branch_stat_cmp,
373 .stat_headers = annotated_branch_stat_headers,
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500374 .stat_show = annotate_branch_stat_show
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800375};
376
377__init static int init_annotated_branch_stats(void)
378{
379 int ret;
380
381 ret = register_stat_tracer(&annotated_branch_stats);
382 if (!ret) {
383 printk(KERN_WARNING "Warning: could not register "
384 "annotated branches stats\n");
385 return 1;
386 }
387 return 0;
388}
389fs_initcall(init_annotated_branch_stats);
390
Steven Rostedt2bcd5212008-11-21 01:30:54 -0500391#ifdef CONFIG_PROFILE_ALL_BRANCHES
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100392
Steven Rostedt2bcd5212008-11-21 01:30:54 -0500393extern unsigned long __start_branch_profile[];
394extern unsigned long __stop_branch_profile[];
395
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100396static int all_branch_stat_headers(struct seq_file *m)
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500397{
Rasmus Villemoesd79ac282014-11-08 21:42:11 +0100398 seq_puts(m, " miss hit % "
399 " Function "
Rasmus Villemoesfa6f0cc2014-11-08 21:42:10 +0100400 " File Line\n"
401 " ------- --------- - "
402 " -------- "
403 " ---- ----\n");
Steven Rostedt1f0d69a2008-11-12 00:14:39 -0500404 return 0;
405}
406
Steven Rostedt42548002009-03-24 13:38:36 -0400407static void *all_branch_stat_start(struct tracer_stat *trace)
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100408{
409 return __start_branch_profile;
410}
411
412static void *
413all_branch_stat_next(void *v, int idx)
414{
415 struct ftrace_branch_data *p = v;
416
417 ++p;
418
419 if ((void *)p >= (void *)__stop_branch_profile)
420 return NULL;
421
422 return p;
423}
424
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500425static int all_branch_stat_show(struct seq_file *m, void *v)
426{
427 struct ftrace_branch_data *p = v;
428 const char *f;
429
430 f = branch_stat_process_file(p);
431 return branch_stat_show_normal(m, p, f);
432}
433
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800434static struct tracer_stat all_branch_stats = {
435 .name = "branch_all",
Frederic Weisbecker034939b2009-01-08 10:03:56 -0800436 .stat_start = all_branch_stat_start,
437 .stat_next = all_branch_stat_next,
438 .stat_headers = all_branch_stat_headers,
Steven Rostedt (VMware)134e6a02017-01-19 08:57:14 -0500439 .stat_show = all_branch_stat_show
Frederic Weisbecker034939b2009-01-08 10:03:56 -0800440};
Frederic Weisbecker034939b2009-01-08 10:03:56 -0800441
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800442__init static int all_annotated_branch_stats(void)
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100443{
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100444 int ret;
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800445
446 ret = register_stat_tracer(&all_branch_stats);
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100447 if (!ret) {
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800448 printk(KERN_WARNING "Warning: could not register "
449 "all branches stats\n");
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100450 return 1;
451 }
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800452 return 0;
Frederic Weisbeckere302cf32008-12-27 23:25:38 +0100453}
Frederic Weisbecker002bb862009-01-10 11:34:13 -0800454fs_initcall(all_annotated_branch_stats);
455#endif /* CONFIG_PROFILE_ALL_BRANCHES */