Skip to content

Commit db82627

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "Mostly tooling fixes and some late tooling updates, plus two perf related printk message fixes" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf tests bpf: Use SyS_epoll_wait alias perf tests: objdump output can contain multi byte chunks perf record: Add --sample-cpu option perf hists: Introduce output_resort_cb method perf tools: Move config/Makefile into Makefile.config perf tests: Add test for bitmap_scnprintf function tools lib: Add bitmap_and function tools lib: Add bitmap_scnprintf function tools lib: Add bitmap_alloc function tools lib traceevent: Ignore generated library files perf tools: Fix build failure on perl script context perf/core: Change log level for duration warning to KERN_INFO perf annotate: Plug filename string leak perf annotate: Introduce strerror for handling symbol__disassemble() errors perf annotate: Rename symbol__annotate() to symbol__disassemble() perf/x86: Modify error message in virtualized environment perf target: str_error_r() always returns the buffer it receives perf annotate: Use pipe + fork instead of popen perf evsel: Introduce constructor for cycles event
2 parents c98f582 + f282f7a commit db82627

File tree

28 files changed

+402
-111
lines changed

28 files changed

+402
-111
lines changed

arch/x86/events/core.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,13 @@ static bool check_hw_exists(void)
263263
return true;
264264

265265
msr_fail:
266-
pr_cont("Broken PMU hardware detected, using software events only.\n");
267-
printk("%sFailed to access perfctr msr (MSR %x is %Lx)\n",
268-
boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR,
269-
reg, val_new);
266+
if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
267+
pr_cont("PMU not available due to virtualization, using software events only.\n");
268+
} else {
269+
pr_cont("Broken PMU hardware detected, using software events only.\n");
270+
pr_err("Failed to access perfctr msr (MSR %x is %Lx)\n",
271+
reg, val_new);
272+
}
270273

271274
return false;
272275
}

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static u64 __report_allowed;
448448

449449
static void perf_duration_warn(struct irq_work *w)
450450
{
451-
printk_ratelimited(KERN_WARNING
451+
printk_ratelimited(KERN_INFO
452452
"perf: interrupt took too long (%lld > %lld), lowering "
453453
"kernel.perf_event_max_sample_rate to %d\n",
454454
__report_avg, __report_allowed,

tools/include/linux/bitmap.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33

44
#include <string.h>
55
#include <linux/bitops.h>
6+
#include <stdlib.h>
67

78
#define DECLARE_BITMAP(name,bits) \
89
unsigned long name[BITS_TO_LONGS(bits)]
910

1011
int __bitmap_weight(const unsigned long *bitmap, int bits);
1112
void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
1213
const unsigned long *bitmap2, int bits);
14+
int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
15+
const unsigned long *bitmap2, unsigned int bits);
1316

1417
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
1518

@@ -65,4 +68,38 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
6568
return (old & mask) != 0;
6669
}
6770

71+
/**
72+
* bitmap_alloc - Allocate bitmap
73+
* @nr: Bit to set
74+
*/
75+
static inline unsigned long *bitmap_alloc(int nbits)
76+
{
77+
return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long));
78+
}
79+
80+
/*
81+
* bitmap_scnprintf - print bitmap list into buffer
82+
* @bitmap: bitmap
83+
* @nbits: size of bitmap
84+
* @buf: buffer to store output
85+
* @size: size of @buf
86+
*/
87+
size_t bitmap_scnprintf(unsigned long *bitmap, int nbits,
88+
char *buf, size_t size);
89+
90+
/**
91+
* bitmap_and - Do logical and on bitmaps
92+
* @dst: resulting bitmap
93+
* @src1: operand 1
94+
* @src2: operand 2
95+
* @nbits: size of bitmap
96+
*/
97+
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
98+
const unsigned long *src2, unsigned int nbits)
99+
{
100+
if (small_const_nbits(nbits))
101+
return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
102+
return __bitmap_and(dst, src1, src2, nbits);
103+
}
104+
68105
#endif /* _PERF_BITOPS_H */

tools/lib/bitmap.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,47 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
2929
for (k = 0; k < nr; k++)
3030
dst[k] = bitmap1[k] | bitmap2[k];
3131
}
32+
33+
size_t bitmap_scnprintf(unsigned long *bitmap, int nbits,
34+
char *buf, size_t size)
35+
{
36+
/* current bit is 'cur', most recently seen range is [rbot, rtop] */
37+
int cur, rbot, rtop;
38+
bool first = true;
39+
size_t ret = 0;
40+
41+
rbot = cur = find_first_bit(bitmap, nbits);
42+
while (cur < nbits) {
43+
rtop = cur;
44+
cur = find_next_bit(bitmap, nbits, cur + 1);
45+
if (cur < nbits && cur <= rtop + 1)
46+
continue;
47+
48+
if (!first)
49+
ret += scnprintf(buf + ret, size - ret, ",");
50+
51+
first = false;
52+
53+
ret += scnprintf(buf + ret, size - ret, "%d", rbot);
54+
if (rbot < rtop)
55+
ret += scnprintf(buf + ret, size - ret, "-%d", rtop);
56+
57+
rbot = cur;
58+
}
59+
return ret;
60+
}
61+
62+
int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
63+
const unsigned long *bitmap2, unsigned int bits)
64+
{
65+
unsigned int k;
66+
unsigned int lim = bits/BITS_PER_LONG;
67+
unsigned long result = 0;
68+
69+
for (k = 0; k < lim; k++)
70+
result |= (dst[k] = bitmap1[k] & bitmap2[k]);
71+
if (bits % BITS_PER_LONG)
72+
result |= (dst[k] = bitmap1[k] & bitmap2[k] &
73+
BITMAP_LAST_WORD_MASK(bits));
74+
return result != 0;
75+
}

tools/lib/traceevent/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
TRACEEVENT-CFLAGS
22
libtraceevent-dynamic-list
3+
libtraceevent.so.*

tools/perf/Documentation/perf-record.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ OPTIONS
192192
--period::
193193
Record the sample period.
194194

195+
--sample-cpu::
196+
Record the sample cpu.
197+
195198
-n::
196199
--no-samples::
197200
Don't sample.
File renamed without changes.

tools/perf/Makefile.perf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
161161
BPF_DIR = $(srctree)/tools/lib/bpf/
162162
SUBCMD_DIR = $(srctree)/tools/lib/subcmd/
163163

164-
# include config/Makefile by default and rule out
164+
# include Makefile.config by default and rule out
165165
# non-config cases
166166
config := 1
167167

@@ -183,7 +183,7 @@ ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump)
183183
FEATURE_TESTS := all
184184
endif
185185
endif
186-
include config/Makefile
186+
include Makefile.config
187187
endif
188188

189189
ifeq ($(config),0)
@@ -706,7 +706,7 @@ $(INSTALL_DOC_TARGETS):
706706
### Cleaning rules
707707

708708
#
709-
# This is here, not in config/Makefile, because config/Makefile does
709+
# This is here, not in Makefile.config, because Makefile.config does
710710
# not get included for the clean target:
711711
#
712712
config-clean:

tools/perf/builtin-record.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,7 @@ struct option __record_options[] = {
14341434
OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat,
14351435
"per thread counts"),
14361436
OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),
1437+
OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"),
14371438
OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
14381439
&record.opts.sample_time_set,
14391440
"Record the sample timestamps"),

tools/perf/builtin-top.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
128128
return err;
129129
}
130130

131-
err = symbol__annotate(sym, map, 0);
131+
err = symbol__disassemble(sym, map, 0);
132132
if (err == 0) {
133133
out_assign:
134134
top->sym_filter_entry = he;
135+
} else {
136+
char msg[BUFSIZ];
137+
symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
138+
pr_err("Couldn't annotate %s: %s\n", sym->name, msg);
135139
}
136140

137141
pthread_mutex_unlock(&notes->lock);

tools/perf/perf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct record_opts {
5252
bool sample_weight;
5353
bool sample_time;
5454
bool sample_time_set;
55+
bool sample_cpu;
5556
bool period;
5657
bool running_time;
5758
bool full_auxtrace;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
libperf-y += Context.o
22

3-
CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs -Wno-undef -Wno-switch-default
3+
CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes
4+
CFLAGS_Context.o += -Wno-unused-parameter -Wno-nested-externs -Wno-undef
5+
CFLAGS_Context.o += -Wno-switch-default -Wno-shadow

tools/perf/tests/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ perf-y += event-times.o
4141
perf-y += backward-ring-buffer.o
4242
perf-y += sdt.o
4343
perf-y += is_printable_array.o
44+
perf-y += bitmap.o
4445

4546
$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
4647
$(call rule_mkdir)

tools/perf/tests/bitmap.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <linux/compiler.h>
2+
#include <linux/bitmap.h>
3+
#include "tests.h"
4+
#include "cpumap.h"
5+
#include "debug.h"
6+
7+
#define NBITS 100
8+
9+
static unsigned long *get_bitmap(const char *str, int nbits)
10+
{
11+
struct cpu_map *map = cpu_map__new(str);
12+
unsigned long *bm = NULL;
13+
int i;
14+
15+
bm = bitmap_alloc(nbits);
16+
17+
if (map && bm) {
18+
bitmap_zero(bm, nbits);
19+
20+
for (i = 0; i < map->nr; i++)
21+
set_bit(map->map[i], bm);
22+
}
23+
24+
if (map)
25+
cpu_map__put(map);
26+
return bm;
27+
}
28+
29+
static int test_bitmap(const char *str)
30+
{
31+
unsigned long *bm = get_bitmap(str, NBITS);
32+
char buf[100];
33+
int ret;
34+
35+
bitmap_scnprintf(bm, NBITS, buf, sizeof(buf));
36+
pr_debug("bitmap: %s\n", buf);
37+
38+
ret = !strcmp(buf, str);
39+
free(bm);
40+
return ret;
41+
}
42+
43+
int test__bitmap_print(int subtest __maybe_unused)
44+
{
45+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
46+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
47+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
48+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
49+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
50+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
51+
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
52+
return 0;
53+
}

tools/perf/tests/bpf-script-example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct bpf_map_def SEC("maps") flip_table = {
3131
.max_entries = 1,
3232
};
3333

34-
SEC("func=sys_epoll_wait")
35-
int bpf_func__sys_epoll_wait(void *ctx)
34+
SEC("func=SyS_epoll_wait")
35+
int bpf_func__SyS_epoll_wait(void *ctx)
3636
{
3737
int ind =0;
3838
int *flag = bpf_map_lookup_elem(&flip_table, &ind);

tools/perf/tests/builtin-test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ static struct test generic_tests[] = {
225225
.desc = "Test is_printable_array function",
226226
.func = test__is_printable_array,
227227
},
228+
{
229+
.desc = "Test bitmap print",
230+
.func = test__bitmap_print,
231+
},
228232
{
229233
.func = NULL,
230234
},

0 commit comments

Comments
 (0)