Skip to content

Commit 134e6a0

Browse files
committed
tracing: Show number of constants profiled in likely profiler
Now that constants are traced, it is useful to see the number of constants that are traced in the likely/unlikely profiler in order to know if they should be ignored or not. The likely/unlikely will display a number after the "correct" number if a "constant" count exists. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent d45ae1f commit 134e6a0

2 files changed

Lines changed: 65 additions & 18 deletions

File tree

‎include/linux/compiler.h‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,32 @@ struct ftrace_branch_data {
101101
};
102102
};
103103

104+
struct ftrace_likely_data {
105+
struct ftrace_branch_data data;
106+
unsigned long constant;
107+
};
108+
104109
/*
105110
* Note: DISABLE_BRANCH_PROFILING can be used by special lowlevel code
106111
* to disable branch tracing on a per file basis.
107112
*/
108113
#if defined(CONFIG_TRACE_BRANCH_PROFILING) \
109114
&& !defined(DISABLE_BRANCH_PROFILING) && !defined(__CHECKER__)
110-
void ftrace_likely_update(struct ftrace_branch_data *f, int val,
115+
void ftrace_likely_update(struct ftrace_likely_data *f, int val,
111116
int expect, int is_constant);
112117

113118
#define likely_notrace(x) __builtin_expect(!!(x), 1)
114119
#define unlikely_notrace(x) __builtin_expect(!!(x), 0)
115120

116121
#define __branch_check__(x, expect, is_constant) ({ \
117122
int ______r; \
118-
static struct ftrace_branch_data \
123+
static struct ftrace_likely_data \
119124
__attribute__((__aligned__(4))) \
120125
__attribute__((section("_ftrace_annotated_branch"))) \
121126
______f = { \
122-
.func = __func__, \
123-
.file = __FILE__, \
124-
.line = __LINE__, \
127+
.data.func = __func__, \
128+
.data.file = __FILE__, \
129+
.data.line = __LINE__, \
125130
}; \
126131
______r = __builtin_expect(!!(x), expect); \
127132
ftrace_likely_update(&______f, ______r, \

‎kernel/trace/trace_branch.c‎

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,27 @@ void trace_likely_condition(struct ftrace_branch_data *f, int val, int expect)
200200
}
201201
#endif /* CONFIG_BRANCH_TRACER */
202202

203-
void ftrace_likely_update(struct ftrace_branch_data *f, int val,
203+
void ftrace_likely_update(struct ftrace_likely_data *f, int val,
204204
int expect, int is_constant)
205205
{
206206
/* A constant is always correct */
207-
if (is_constant)
207+
if (is_constant) {
208+
f->constant++;
208209
val = expect;
210+
}
209211
/*
210212
* I would love to have a trace point here instead, but the
211213
* trace point code is so inundated with unlikely and likely
212214
* conditions that the recursive nightmare that exists is too
213215
* much to try to get working. At least for now.
214216
*/
215-
trace_likely_condition(f, val, expect);
217+
trace_likely_condition(&f->data, val, expect);
216218

217219
/* FIXME: Make this atomic! */
218220
if (val == expect)
219-
f->correct++;
221+
f->data.correct++;
220222
else
221-
f->incorrect++;
223+
f->data.incorrect++;
222224
}
223225
EXPORT_SYMBOL(ftrace_likely_update);
224226

@@ -249,29 +251,60 @@ static inline long get_incorrect_percent(struct ftrace_branch_data *p)
249251
return percent;
250252
}
251253

252-
static int branch_stat_show(struct seq_file *m, void *v)
254+
static const char *branch_stat_process_file(struct ftrace_branch_data *p)
253255
{
254-
struct ftrace_branch_data *p = v;
255256
const char *f;
256-
long percent;
257257

258258
/* Only print the file, not the path */
259259
f = p->file + strlen(p->file);
260260
while (f >= p->file && *f != '/')
261261
f--;
262-
f++;
262+
return ++f;
263+
}
264+
265+
static void branch_stat_show(struct seq_file *m,
266+
struct ftrace_branch_data *p, const char *f)
267+
{
268+
long percent;
263269

264270
/*
265271
* The miss is overlayed on correct, and hit on incorrect.
266272
*/
267273
percent = get_incorrect_percent(p);
268274

269-
seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
270275
if (percent < 0)
271276
seq_puts(m, " X ");
272277
else
273278
seq_printf(m, "%3ld ", percent);
279+
274280
seq_printf(m, "%-30.30s %-20.20s %d\n", p->func, f, p->line);
281+
}
282+
283+
static int branch_stat_show_normal(struct seq_file *m,
284+
struct ftrace_branch_data *p, const char *f)
285+
{
286+
seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
287+
branch_stat_show(m, p, f);
288+
return 0;
289+
}
290+
291+
static int annotate_branch_stat_show(struct seq_file *m, void *v)
292+
{
293+
struct ftrace_likely_data *p = v;
294+
const char *f;
295+
int l;
296+
297+
f = branch_stat_process_file(&p->data);
298+
299+
if (!p->constant)
300+
return branch_stat_show_normal(m, &p->data, f);
301+
302+
l = snprintf(NULL, 0, "/%lu", p->constant);
303+
l = l > 8 ? 0 : 8 - l;
304+
305+
seq_printf(m, "%8lu/%lu %*lu ",
306+
p->data.correct, p->constant, l, p->data.incorrect);
307+
branch_stat_show(m, &p->data, f);
275308
return 0;
276309
}
277310

@@ -283,7 +316,7 @@ static void *annotated_branch_stat_start(struct tracer_stat *trace)
283316
static void *
284317
annotated_branch_stat_next(void *v, int idx)
285318
{
286-
struct ftrace_branch_data *p = v;
319+
struct ftrace_likely_data *p = v;
287320

288321
++p;
289322

@@ -332,7 +365,7 @@ static struct tracer_stat annotated_branch_stats = {
332365
.stat_next = annotated_branch_stat_next,
333366
.stat_cmp = annotated_branch_stat_cmp,
334367
.stat_headers = annotated_branch_stat_headers,
335-
.stat_show = branch_stat_show
368+
.stat_show = annotate_branch_stat_show
336369
};
337370

338371
__init static int init_annotated_branch_stats(void)
@@ -383,12 +416,21 @@ all_branch_stat_next(void *v, int idx)
383416
return p;
384417
}
385418

419+
static int all_branch_stat_show(struct seq_file *m, void *v)
420+
{
421+
struct ftrace_branch_data *p = v;
422+
const char *f;
423+
424+
f = branch_stat_process_file(p);
425+
return branch_stat_show_normal(m, p, f);
426+
}
427+
386428
static struct tracer_stat all_branch_stats = {
387429
.name = "branch_all",
388430
.stat_start = all_branch_stat_start,
389431
.stat_next = all_branch_stat_next,
390432
.stat_headers = all_branch_stat_headers,
391-
.stat_show = branch_stat_show
433+
.stat_show = all_branch_stat_show
392434
};
393435

394436
__init static int all_annotated_branch_stats(void)

0 commit comments

Comments
 (0)