Skip to content

Commit 277d6f1

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo-4.11-20170213' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: New features: - Introduce the 'delta-abs' 'perf diff' compute method, that orders the histogram entries by the absolute value of the percentage delta for a function in two perf.data files, i.e. the functions that changed the most (increase or decrease in samples) comes first (Namhyung Kim) User visible changes: - Improve message about tweaking the kernel.perf_event_paranoid setting, telling how to make the change permanent by editing /etc/sysctl.conf (Arnaldo Carvalho de Melo) Infrastructure changes: - Introduce linux/compiler-gcc.h as a counterpart to the kernel's, initially containing the definition of __fallthrough, more to come (__maybe_unused, etc) (Arnaldo Carvalho de Melo) - Fixes for problems uncovered by building tools/perf with clang, such as always true tests of arrays against NULL and variables that sometimes were used without being initialized (Arnaldo Carvalho de Melo, Steven Rostedt) - Before loading a new ELF, clear global variables set by the samples/bpf loader (Mickaël Salaün) - Ignore already processed ELF sections in the samples/bpf loader (Mickaël Salaün) - Fix compile error in the scripting code with some perl5 versions (Wang YanQing) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents 210f400 + a734fb5 commit 277d6f1

23 files changed

+145
-29
lines changed

samples/bpf/bpf_load.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ int load_bpf_file(char *path)
277277
Elf_Data *data, *data_prog, *symbols = NULL;
278278
char *shname, *shname_prog;
279279

280+
/* reset global variables */
281+
kern_version = 0;
282+
memset(license, 0, sizeof(license));
283+
memset(processed_sec, 0, sizeof(processed_sec));
284+
280285
if (elf_version(EV_CURRENT) == EV_NONE)
281286
return 1;
282287

@@ -328,6 +333,8 @@ int load_bpf_file(char *path)
328333

329334
/* load programs that need map fixup (relocations) */
330335
for (i = 1; i < ehdr.e_shnum; i++) {
336+
if (processed_sec[i])
337+
continue;
331338

332339
if (get_sec(elf, i, &ehdr, &shname, &shdr, &data))
333340
continue;

samples/bpf/tracex5_kern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/version.h>
99
#include <uapi/linux/bpf.h>
1010
#include <uapi/linux/seccomp.h>
11+
#include <uapi/linux/unistd.h>
1112
#include "bpf_helpers.h"
1213

1314
#define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F

tools/include/linux/compiler-gcc.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _TOOLS_LINUX_COMPILER_H_
2+
#error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
3+
#endif
4+
5+
/*
6+
* Common definitions for all gcc versions go here.
7+
*/
8+
#define GCC_VERSION (__GNUC__ * 10000 \
9+
+ __GNUC_MINOR__ * 100 \
10+
+ __GNUC_PATCHLEVEL__)
11+
12+
#if GCC_VERSION >= 70000 && !defined(__CHECKER__)
13+
# define __fallthrough __attribute__ ((fallthrough))
14+
#endif

tools/include/linux/compiler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef _TOOLS_LINUX_COMPILER_H_
22
#define _TOOLS_LINUX_COMPILER_H_
33

4+
#ifdef __GNUC__
5+
#include <linux/compiler-gcc.h>
6+
#endif
7+
48
/* Optimization barrier */
59
/* The "volatile" is due to gcc bugs */
610
#define barrier() __asm__ __volatile__("": : :"memory")
@@ -128,11 +132,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
128132

129133

130134
#ifndef __fallthrough
131-
# if defined(__GNUC__) && __GNUC__ >= 7
132-
# define __fallthrough __attribute__ ((fallthrough))
133-
# else
134-
# define __fallthrough
135-
# endif
135+
# define __fallthrough
136136
#endif
137137

138138
#endif /* _TOOLS_LINUX_COMPILER_H */

tools/lib/traceevent/kbuffer-parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ static unsigned int old_update_pointers(struct kbuffer *kbuf)
315315
extend += delta;
316316
delta = extend;
317317
ptr += 4;
318+
length = 0;
318319
break;
319320

320321
case OLD_RINGBUF_TYPE_TIME_STAMP:

tools/lib/traceevent/plugin_function.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int function_handler(struct trace_seq *s, struct pevent_record *record,
130130
unsigned long long pfunction;
131131
const char *func;
132132
const char *parent;
133-
int index;
133+
int index = 0;
134134

135135
if (pevent_get_field_val(s, event, "ip", record, &function, 1))
136136
return trace_seq_putc(s, '!');

tools/perf/Documentation/perf-config.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,18 @@ record.*::
498498
But if this option is 'no-cache', it will not update the build-id cache.
499499
'skip' skips post-processing and does not update the cache.
500500

501+
diff.*::
502+
diff.order::
503+
This option sets the number of columns to sort the result.
504+
The default is 0, which means sorting by baseline.
505+
Setting it to 1 will sort the result by delta (or other
506+
compute method selected).
507+
508+
diff.compute::
509+
This options sets the method for computing the diff result.
510+
Possible values are 'delta', 'delta-abs', 'ratio' and
511+
'wdiff'. Default is 'delta'.
512+
501513
SEE ALSO
502514
--------
503515
linkperf:perf[1]

tools/perf/Documentation/perf-diff.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ OPTIONS
8686

8787
-c::
8888
--compute::
89-
Differential computation selection - delta,ratio,wdiff (default is delta).
90-
See COMPARISON METHODS section for more info.
89+
Differential computation selection - delta, ratio, wdiff, delta-abs
90+
(default is delta-abs). Default can be changed using diff.compute
91+
config option. See COMPARISON METHODS section for more info.
9192

9293
-p::
9394
--period::
@@ -99,7 +100,11 @@ OPTIONS
99100

100101
-o::
101102
--order::
102-
Specify compute sorting column number.
103+
Specify compute sorting column number. 0 means sorting by baseline
104+
overhead and 1 (default) means sorting by computed value of column 1
105+
(data from the first file other base baseline). Values more than 1
106+
can be used only if enough data files are provided.
107+
The default value can be set using the diff.order config option.
103108

104109
--percentage::
105110
Determine how to display the overhead percentage of filtered entries.
@@ -181,6 +186,10 @@ with:
181186
relative to how entries are filtered. Use --percentage=absolute to
182187
prevent such fluctuation.
183188

189+
delta-abs
190+
~~~~~~~~~
191+
Same as 'delta` method, but sort the result with the absolute values.
192+
184193
ratio
185194
~~~~~
186195
If specified the 'Ratio' column is displayed with value 'r' computed as:

tools/perf/MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ tools/include/asm-generic/bitops.h
6161
tools/include/linux/atomic.h
6262
tools/include/linux/bitops.h
6363
tools/include/linux/compiler.h
64+
tools/include/linux/compiler-gcc.h
6465
tools/include/linux/coresight-pmu.h
6566
tools/include/linux/filter.h
6667
tools/include/linux/hash.h

tools/perf/builtin-diff.c

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "util/symbol.h"
1818
#include "util/util.h"
1919
#include "util/data.h"
20+
#include "util/config.h"
2021

2122
#include <stdlib.h>
2223
#include <math.h>
@@ -30,6 +31,7 @@ enum {
3031
PERF_HPP_DIFF__RATIO,
3132
PERF_HPP_DIFF__WEIGHTED_DIFF,
3233
PERF_HPP_DIFF__FORMULA,
34+
PERF_HPP_DIFF__DELTA_ABS,
3335

3436
PERF_HPP_DIFF__MAX_INDEX
3537
};
@@ -64,7 +66,7 @@ static bool force;
6466
static bool show_period;
6567
static bool show_formula;
6668
static bool show_baseline_only;
67-
static unsigned int sort_compute;
69+
static unsigned int sort_compute = 1;
6870

6971
static s64 compute_wdiff_w1;
7072
static s64 compute_wdiff_w2;
@@ -73,19 +75,22 @@ enum {
7375
COMPUTE_DELTA,
7476
COMPUTE_RATIO,
7577
COMPUTE_WEIGHTED_DIFF,
78+
COMPUTE_DELTA_ABS,
7679
COMPUTE_MAX,
7780
};
7881

7982
const char *compute_names[COMPUTE_MAX] = {
8083
[COMPUTE_DELTA] = "delta",
84+
[COMPUTE_DELTA_ABS] = "delta-abs",
8185
[COMPUTE_RATIO] = "ratio",
8286
[COMPUTE_WEIGHTED_DIFF] = "wdiff",
8387
};
8488

85-
static int compute;
89+
static int compute = COMPUTE_DELTA_ABS;
8690

8791
static int compute_2_hpp[COMPUTE_MAX] = {
8892
[COMPUTE_DELTA] = PERF_HPP_DIFF__DELTA,
93+
[COMPUTE_DELTA_ABS] = PERF_HPP_DIFF__DELTA_ABS,
8994
[COMPUTE_RATIO] = PERF_HPP_DIFF__RATIO,
9095
[COMPUTE_WEIGHTED_DIFF] = PERF_HPP_DIFF__WEIGHTED_DIFF,
9196
};
@@ -111,6 +116,10 @@ static struct header_column {
111116
.name = "Delta",
112117
.width = 7,
113118
},
119+
[PERF_HPP_DIFF__DELTA_ABS] = {
120+
.name = "Delta Abs",
121+
.width = 7,
122+
},
114123
[PERF_HPP_DIFF__RATIO] = {
115124
.name = "Ratio",
116125
.width = 14,
@@ -298,6 +307,7 @@ static int formula_fprintf(struct hist_entry *he, struct hist_entry *pair,
298307
{
299308
switch (compute) {
300309
case COMPUTE_DELTA:
310+
case COMPUTE_DELTA_ABS:
301311
return formula_delta(he, pair, buf, size);
302312
case COMPUTE_RATIO:
303313
return formula_ratio(he, pair, buf, size);
@@ -461,6 +471,7 @@ static void hists__precompute(struct hists *hists)
461471

462472
switch (compute) {
463473
case COMPUTE_DELTA:
474+
case COMPUTE_DELTA_ABS:
464475
compute_delta(he, pair);
465476
break;
466477
case COMPUTE_RATIO:
@@ -498,6 +509,13 @@ __hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
498509

499510
return cmp_doubles(l, r);
500511
}
512+
case COMPUTE_DELTA_ABS:
513+
{
514+
double l = fabs(left->diff.period_ratio_delta);
515+
double r = fabs(right->diff.period_ratio_delta);
516+
517+
return cmp_doubles(l, r);
518+
}
501519
case COMPUTE_RATIO:
502520
{
503521
double l = left->diff.period_ratio;
@@ -564,7 +582,7 @@ hist_entry__cmp_compute_idx(struct hist_entry *left, struct hist_entry *right,
564582
if (!p_left || !p_right)
565583
return p_left ? -1 : 1;
566584

567-
if (c != COMPUTE_DELTA) {
585+
if (c != COMPUTE_DELTA && c != COMPUTE_DELTA_ABS) {
568586
/*
569587
* The delta can be computed without the baseline, but
570588
* others are not. Put those entries which have no
@@ -606,6 +624,15 @@ hist_entry__cmp_delta(struct perf_hpp_fmt *fmt,
606624
return hist_entry__cmp_compute(right, left, COMPUTE_DELTA, d->idx);
607625
}
608626

627+
static int64_t
628+
hist_entry__cmp_delta_abs(struct perf_hpp_fmt *fmt,
629+
struct hist_entry *left, struct hist_entry *right)
630+
{
631+
struct data__file *d = fmt_to_data_file(fmt);
632+
633+
return hist_entry__cmp_compute(right, left, COMPUTE_DELTA_ABS, d->idx);
634+
}
635+
609636
static int64_t
610637
hist_entry__cmp_ratio(struct perf_hpp_fmt *fmt,
611638
struct hist_entry *left, struct hist_entry *right)
@@ -632,6 +659,14 @@ hist_entry__cmp_delta_idx(struct perf_hpp_fmt *fmt __maybe_unused,
632659
sort_compute);
633660
}
634661

662+
static int64_t
663+
hist_entry__cmp_delta_abs_idx(struct perf_hpp_fmt *fmt __maybe_unused,
664+
struct hist_entry *left, struct hist_entry *right)
665+
{
666+
return hist_entry__cmp_compute_idx(right, left, COMPUTE_DELTA_ABS,
667+
sort_compute);
668+
}
669+
635670
static int64_t
636671
hist_entry__cmp_ratio_idx(struct perf_hpp_fmt *fmt __maybe_unused,
637672
struct hist_entry *left, struct hist_entry *right)
@@ -775,7 +810,7 @@ static const struct option options[] = {
775810
OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
776811
"Show only items with match in baseline"),
777812
OPT_CALLBACK('c', "compute", &compute,
778-
"delta,ratio,wdiff:w1,w2 (default delta)",
813+
"delta,delta-abs,ratio,wdiff:w1,w2 (default delta-abs)",
779814
"Entries differential computation selection",
780815
setup_compute),
781816
OPT_BOOLEAN('p', "period", &show_period,
@@ -945,6 +980,7 @@ hpp__entry_pair(struct hist_entry *he, struct hist_entry *pair,
945980

946981
switch (idx) {
947982
case PERF_HPP_DIFF__DELTA:
983+
case PERF_HPP_DIFF__DELTA_ABS:
948984
if (pair->diff.computed)
949985
diff = pair->diff.period_ratio_delta;
950986
else
@@ -1118,6 +1154,10 @@ static void data__hpp_register(struct data__file *d, int idx)
11181154
fmt->color = hpp__color_wdiff;
11191155
fmt->sort = hist_entry__cmp_wdiff;
11201156
break;
1157+
case PERF_HPP_DIFF__DELTA_ABS:
1158+
fmt->color = hpp__color_delta;
1159+
fmt->sort = hist_entry__cmp_delta_abs;
1160+
break;
11211161
default:
11221162
fmt->sort = hist_entry__cmp_nop;
11231163
break;
@@ -1195,6 +1235,9 @@ static int ui_init(void)
11951235
case COMPUTE_WEIGHTED_DIFF:
11961236
fmt->sort = hist_entry__cmp_wdiff_idx;
11971237
break;
1238+
case COMPUTE_DELTA_ABS:
1239+
fmt->sort = hist_entry__cmp_delta_abs_idx;
1240+
break;
11981241
default:
11991242
BUG_ON(1);
12001243
}
@@ -1249,13 +1292,40 @@ static int data_init(int argc, const char **argv)
12491292
return 0;
12501293
}
12511294

1295+
static int diff__config(const char *var, const char *value,
1296+
void *cb __maybe_unused)
1297+
{
1298+
if (!strcmp(var, "diff.order")) {
1299+
sort_compute = perf_config_int(var, value);
1300+
return 0;
1301+
}
1302+
if (!strcmp(var, "diff.compute")) {
1303+
if (!strcmp(value, "delta")) {
1304+
compute = COMPUTE_DELTA;
1305+
} else if (!strcmp(value, "delta-abs")) {
1306+
compute = COMPUTE_DELTA_ABS;
1307+
} else if (!strcmp(value, "ratio")) {
1308+
compute = COMPUTE_RATIO;
1309+
} else if (!strcmp(value, "wdiff")) {
1310+
compute = COMPUTE_WEIGHTED_DIFF;
1311+
} else {
1312+
pr_err("Invalid compute method: %s\n", value);
1313+
return -1;
1314+
}
1315+
}
1316+
1317+
return 0;
1318+
}
1319+
12521320
int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
12531321
{
12541322
int ret = hists__init();
12551323

12561324
if (ret < 0)
12571325
return ret;
12581326

1327+
perf_config(diff__config, NULL);
1328+
12591329
argc = parse_options(argc, argv, options, diff_usage, 0);
12601330

12611331
if (symbol__init(NULL) < 0)

tools/perf/builtin-kmem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
10651065

10661066
data = rb_entry(next, struct page_stat, node);
10671067
sym = machine__find_kernel_function(machine, data->callsite, &map);
1068-
if (sym && sym->name)
1068+
if (sym)
10691069
caller = sym->name;
10701070
else
10711071
scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite);
@@ -1107,7 +1107,7 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
11071107

11081108
data = rb_entry(next, struct page_stat, node);
11091109
sym = machine__find_kernel_function(machine, data->callsite, &map);
1110-
if (sym && sym->name)
1110+
if (sym)
11111111
caller = sym->name;
11121112
else
11131113
scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite);

tools/perf/builtin-record.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ static int record__mmap(struct record *rec)
418418

419419
static int record__open(struct record *rec)
420420
{
421-
char msg[512];
421+
char msg[BUFSIZ];
422422
struct perf_evsel *pos;
423423
struct perf_evlist *evlist = rec->evlist;
424424
struct perf_session *session = rec->session;

tools/perf/builtin-sched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ static void save_task_callchain(struct perf_sched *sched,
20672067
break;
20682068

20692069
sym = node->sym;
2070-
if (sym && sym->name) {
2070+
if (sym) {
20712071
if (!strcmp(sym->name, "schedule") ||
20722072
!strcmp(sym->name, "__schedule") ||
20732073
!strcmp(sym->name, "preempt_schedule"))

0 commit comments

Comments
 (0)