Skip to content

Commit f282f7a

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo-20160803' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: New features: - Add --sample-cpu to 'perf record', to explicitely ask for sampling the CPU (Jiri Olsa) Fixes: - Fix processing of multi byte chunks in objdump output, fixing disassemble processing for annotation on at least ARM64 (Jan Stancek) - Use SyS_epoll_wait in a BPF 'perf test' entry instead of sys_epoll_wait, that is not present in the DWARF info in vmlinux files (Arnaldo Carvalho de Melo) - Add -wno-shadow when processing files using perl headers, fixing the build on Fedora Rawhide and Arch Linux (Namhyung Kim) Infrastructure changes: - Annotate prep work to better catch and report errors related to using objdump to disassemble DSOs (Arnaldo Carvalho de Melo) - Add 'alloc', 'scnprintf' and 'and' methods for bitmap processing (Jiri Olsa) - Add nested output resorting callback in hists processing (Jiri Olsa) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents 0d87d7e + c369e0a commit f282f7a

File tree

26 files changed

+394
-106
lines changed

26 files changed

+394
-106
lines changed

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
},

tools/perf/tests/code-reading.c

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,44 +33,86 @@ static unsigned int hex(char c)
3333
return c - 'A' + 10;
3434
}
3535

36-
static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
37-
size_t len)
36+
static size_t read_objdump_chunk(const char **line, unsigned char **buf,
37+
size_t *buf_len)
3838
{
39-
const char *p;
40-
size_t i, j = 0;
41-
42-
/* Skip to a colon */
43-
p = strchr(line, ':');
44-
if (!p)
45-
return 0;
46-
i = p + 1 - line;
39+
size_t bytes_read = 0;
40+
unsigned char *chunk_start = *buf;
4741

4842
/* Read bytes */
49-
while (j < len) {
43+
while (*buf_len > 0) {
5044
char c1, c2;
5145

52-
/* Skip spaces */
53-
for (; i < line_len; i++) {
54-
if (!isspace(line[i]))
55-
break;
56-
}
5746
/* Get 2 hex digits */
58-
if (i >= line_len || !isxdigit(line[i]))
47+
c1 = *(*line)++;
48+
if (!isxdigit(c1))
5949
break;
60-
c1 = line[i++];
61-
if (i >= line_len || !isxdigit(line[i]))
50+
c2 = *(*line)++;
51+
if (!isxdigit(c2))
6252
break;
63-
c2 = line[i++];
64-
/* Followed by a space */
65-
if (i < line_len && line[i] && !isspace(line[i]))
53+
54+
/* Store byte and advance buf */
55+
**buf = (hex(c1) << 4) | hex(c2);
56+
(*buf)++;
57+
(*buf_len)--;
58+
bytes_read++;
59+
60+
/* End of chunk? */
61+
if (isspace(**line))
6662
break;
67-
/* Store byte */
68-
*(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
69-
buf += 1;
70-
j++;
7163
}
64+
65+
/*
66+
* objdump will display raw insn as LE if code endian
67+
* is LE and bytes_per_chunk > 1. In that case reverse
68+
* the chunk we just read.
69+
*
70+
* see disassemble_bytes() at binutils/objdump.c for details
71+
* how objdump chooses display endian)
72+
*/
73+
if (bytes_read > 1 && !bigendian()) {
74+
unsigned char *chunk_end = chunk_start + bytes_read - 1;
75+
unsigned char tmp;
76+
77+
while (chunk_start < chunk_end) {
78+
tmp = *chunk_start;
79+
*chunk_start = *chunk_end;
80+
*chunk_end = tmp;
81+
chunk_start++;
82+
chunk_end--;
83+
}
84+
}
85+
86+
return bytes_read;
87+
}
88+
89+
static size_t read_objdump_line(const char *line, unsigned char *buf,
90+
size_t buf_len)
91+
{
92+
const char *p;
93+
size_t ret, bytes_read = 0;
94+
95+
/* Skip to a colon */
96+
p = strchr(line, ':');
97+
if (!p)
98+
return 0;
99+
p++;
100+
101+
/* Skip initial spaces */
102+
while (*p) {
103+
if (!isspace(*p))
104+
break;
105+
p++;
106+
}
107+
108+
do {
109+
ret = read_objdump_chunk(&p, &buf, &buf_len);
110+
bytes_read += ret;
111+
p++;
112+
} while (ret > 0);
113+
72114
/* return number of successfully read bytes */
73-
return j;
115+
return bytes_read;
74116
}
75117

76118
static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
@@ -95,7 +137,7 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
95137
}
96138

97139
/* read objdump data into temporary buffer */
98-
read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
140+
read_bytes = read_objdump_line(line, tmp, sizeof(tmp));
99141
if (!read_bytes)
100142
continue;
101143

@@ -152,7 +194,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
152194

153195
ret = read_objdump_output(f, buf, &len, addr);
154196
if (len) {
155-
pr_debug("objdump read too few bytes\n");
197+
pr_debug("objdump read too few bytes: %zd\n", len);
156198
if (!ret)
157199
ret = len;
158200
}

0 commit comments

Comments
 (0)