Skip to content

Commit

Permalink
Merge tag 'perf-tools-fixes-for-v5.10-2020-11-28' of git://git.kernel…
Browse files Browse the repository at this point in the history
….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
  • Loading branch information
torvalds committed Nov 28, 2020
2 parents 67f34fa + a9ffd04 commit ca57982
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
4 changes: 3 additions & 1 deletion tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,10 @@ static int __cmd_diff(void)
if (compute == COMPUTE_STREAM) {
d->evlist_streams = evlist__create_streams(
d->session->evlist, 5);
if (!d->evlist_streams)
if (!d->evlist_streams) {
ret = -ENOMEM;
goto out_delete;
}
}
}

Expand Down
28 changes: 26 additions & 2 deletions tools/perf/util/dwarf-aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,25 @@ bool die_is_signed_type(Dwarf_Die *tp_die)
bool die_is_func_def(Dwarf_Die *dw_die)
{
Dwarf_Attribute attr;
Dwarf_Addr addr = 0;

if (dwarf_tag(dw_die) != DW_TAG_subprogram)
return false;

if (dwarf_attr(dw_die, DW_AT_declaration, &attr))
return false;

return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
/*
* DW_AT_declaration can be lost from function declaration
* by gcc's bug #97060.
* So we need to check this subprogram DIE has DW_AT_inline
* or an entry address.
*/
if (!dwarf_attr(dw_die, DW_AT_inline, &attr) &&
die_entrypc(dw_die, &addr) < 0)
return false;

return true;
}

/**
Expand All @@ -373,13 +389,21 @@ bool die_is_func_def(Dwarf_Die *dw_die)
int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr)
{
Dwarf_Addr base, end;
Dwarf_Attribute attr;

if (!addr)
return -EINVAL;

if (dwarf_entrypc(dw_die, addr) == 0)
return 0;

/*
* Since the dwarf_ranges() will return 0 if there is no
* DW_AT_ranges attribute, we should check it first.
*/
if (!dwarf_attr(dw_die, DW_AT_ranges, &attr))
return -ENOENT;

return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0;
}

Expand Down
15 changes: 9 additions & 6 deletions tools/perf/util/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
static inline size_t hash_bits(size_t h, int bits)
{
/* shuffle bits and return requested number of upper bits */
if (bits == 0)
return 0;

#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
/* LP64 case */
return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
Expand Down Expand Up @@ -174,17 +177,17 @@ bool hashmap__find(const struct hashmap *map, const void *key, void **value);
* @key: key to iterate entries for
*/
#define hashmap__for_each_key_entry(map, cur, _key) \
for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\
map->cap_bits); \
map->buckets ? map->buckets[bkt] : NULL; }); \
for (cur = map->buckets \
? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
: NULL; \
cur; \
cur = cur->next) \
if (map->equal_fn(cur->key, (_key), map->ctx))

#define hashmap__for_each_key_entry_safe(map, cur, tmp, _key) \
for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\
map->cap_bits); \
cur = map->buckets ? map->buckets[bkt] : NULL; }); \
for (cur = map->buckets \
? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
: NULL; \
cur && ({ tmp = cur->next; true; }); \
cur = tmp) \
if (map->equal_fn(cur->key, (_key), map->ctx))
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/probe-finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,8 +1885,7 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
if (lr->file && strtailcmp(lr->file, dwarf_decl_file(sp_die)))
return DWARF_CB_OK;

if (die_is_func_def(sp_die) &&
die_match_name(sp_die, lr->function)) {
if (die_match_name(sp_die, lr->function) && die_is_func_def(sp_die)) {
lf->fname = dwarf_decl_file(sp_die);
dwarf_decl_line(sp_die, &lr->offset);
pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
Expand Down
5 changes: 1 addition & 4 deletions tools/perf/util/stat-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,10 @@ static int first_shadow_cpu(struct perf_stat_config *config,
struct evlist *evlist = evsel->evlist;
int i;

if (!config->aggr_get_id)
return 0;

if (config->aggr_mode == AGGR_NONE)
return id;

if (config->aggr_mode == AGGR_GLOBAL)
if (!config->aggr_get_id)
return 0;

for (i = 0; i < evsel__nr_cpus(evsel); i++) {
Expand Down
3 changes: 3 additions & 0 deletions tools/perf/util/synthetic-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
char cgrp_root[PATH_MAX];
size_t mount_len; /* length of mount point in the path */

if (!tool || !tool->cgroup_events)
return 0;

if (cgroupfs_find_mountpoint(cgrp_root, PATH_MAX, "perf_event") < 0) {
pr_debug("cannot find cgroup mount point\n");
return -1;
Expand Down

0 comments on commit ca57982

Please sign in to comment.