Skip to content

Commit ca57982

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.10-2020-11-28' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tool fixes from Arnaldo Carvalho de Melo: - Fix die_entrypc() when DW_AT_ranges DWARF attribute not available - Cope with broken DWARF (missing DW_AT_declaration) generated by some recent gcc versions - Do not generate CGROUP metadata events when not asked to in 'perf record' - Use proper CPU for shadow stats in 'perf stat' - Update copy of libbpf's hashmap.c, silencing tools/perf build warning - Fix return value in 'perf diff' * tag 'perf-tools-fixes-for-v5.10-2020-11-28' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf probe: Change function definition check due to broken DWARF perf probe: Fix to die_entrypc() returns error correctly perf stat: Use proper cpu for shadow stats perf record: Synthesize cgroup events only if needed perf diff: Fix error return value in __cmd_diff() perf tools: Update copy of libbpf's hashmap.c
2 parents 67f34fa + a9ffd04 commit ca57982

6 files changed

Lines changed: 43 additions & 15 deletions

File tree

tools/perf/builtin-diff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,10 @@ static int __cmd_diff(void)
12221222
if (compute == COMPUTE_STREAM) {
12231223
d->evlist_streams = evlist__create_streams(
12241224
d->session->evlist, 5);
1225-
if (!d->evlist_streams)
1225+
if (!d->evlist_streams) {
1226+
ret = -ENOMEM;
12261227
goto out_delete;
1228+
}
12271229
}
12281230
}
12291231

tools/perf/util/dwarf-aux.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,25 @@ bool die_is_signed_type(Dwarf_Die *tp_die)
356356
bool die_is_func_def(Dwarf_Die *dw_die)
357357
{
358358
Dwarf_Attribute attr;
359+
Dwarf_Addr addr = 0;
360+
361+
if (dwarf_tag(dw_die) != DW_TAG_subprogram)
362+
return false;
363+
364+
if (dwarf_attr(dw_die, DW_AT_declaration, &attr))
365+
return false;
359366

360-
return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
361-
dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
367+
/*
368+
* DW_AT_declaration can be lost from function declaration
369+
* by gcc's bug #97060.
370+
* So we need to check this subprogram DIE has DW_AT_inline
371+
* or an entry address.
372+
*/
373+
if (!dwarf_attr(dw_die, DW_AT_inline, &attr) &&
374+
die_entrypc(dw_die, &addr) < 0)
375+
return false;
376+
377+
return true;
362378
}
363379

364380
/**
@@ -373,13 +389,21 @@ bool die_is_func_def(Dwarf_Die *dw_die)
373389
int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr)
374390
{
375391
Dwarf_Addr base, end;
392+
Dwarf_Attribute attr;
376393

377394
if (!addr)
378395
return -EINVAL;
379396

380397
if (dwarf_entrypc(dw_die, addr) == 0)
381398
return 0;
382399

400+
/*
401+
* Since the dwarf_ranges() will return 0 if there is no
402+
* DW_AT_ranges attribute, we should check it first.
403+
*/
404+
if (!dwarf_attr(dw_die, DW_AT_ranges, &attr))
405+
return -ENOENT;
406+
383407
return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0;
384408
}
385409

tools/perf/util/hashmap.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
static inline size_t hash_bits(size_t h, int bits)
1616
{
1717
/* shuffle bits and return requested number of upper bits */
18+
if (bits == 0)
19+
return 0;
20+
1821
#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
1922
/* LP64 case */
2023
return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
@@ -174,17 +177,17 @@ bool hashmap__find(const struct hashmap *map, const void *key, void **value);
174177
* @key: key to iterate entries for
175178
*/
176179
#define hashmap__for_each_key_entry(map, cur, _key) \
177-
for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\
178-
map->cap_bits); \
179-
map->buckets ? map->buckets[bkt] : NULL; }); \
180+
for (cur = map->buckets \
181+
? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
182+
: NULL; \
180183
cur; \
181184
cur = cur->next) \
182185
if (map->equal_fn(cur->key, (_key), map->ctx))
183186

184187
#define hashmap__for_each_key_entry_safe(map, cur, tmp, _key) \
185-
for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\
186-
map->cap_bits); \
187-
cur = map->buckets ? map->buckets[bkt] : NULL; }); \
188+
for (cur = map->buckets \
189+
? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
190+
: NULL; \
188191
cur && ({ tmp = cur->next; true; }); \
189192
cur = tmp) \
190193
if (map->equal_fn(cur->key, (_key), map->ctx))

tools/perf/util/probe-finder.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,8 +1885,7 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
18851885
if (lr->file && strtailcmp(lr->file, dwarf_decl_file(sp_die)))
18861886
return DWARF_CB_OK;
18871887

1888-
if (die_is_func_def(sp_die) &&
1889-
die_match_name(sp_die, lr->function)) {
1888+
if (die_match_name(sp_die, lr->function) && die_is_func_def(sp_die)) {
18901889
lf->fname = dwarf_decl_file(sp_die);
18911890
dwarf_decl_line(sp_die, &lr->offset);
18921891
pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);

tools/perf/util/stat-display.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,10 @@ static int first_shadow_cpu(struct perf_stat_config *config,
324324
struct evlist *evlist = evsel->evlist;
325325
int i;
326326

327-
if (!config->aggr_get_id)
328-
return 0;
329-
330327
if (config->aggr_mode == AGGR_NONE)
331328
return id;
332329

333-
if (config->aggr_mode == AGGR_GLOBAL)
330+
if (!config->aggr_get_id)
334331
return 0;
335332

336333
for (i = 0; i < evsel__nr_cpus(evsel); i++) {

tools/perf/util/synthetic-events.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
563563
char cgrp_root[PATH_MAX];
564564
size_t mount_len; /* length of mount point in the path */
565565

566+
if (!tool || !tool->cgroup_events)
567+
return 0;
568+
566569
if (cgroupfs_find_mountpoint(cgrp_root, PATH_MAX, "perf_event") < 0) {
567570
pr_debug("cannot find cgroup mount point\n");
568571
return -1;

0 commit comments

Comments
 (0)