Commit ca579827 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'perf-tools-fixes-for-v5.10-2020-11-28' of...

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
parents 67f34fa8 a9ffd048
......@@ -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;
}
}
}
......
......@@ -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;
}
/**
......@@ -373,6 +389,7 @@ 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;
......@@ -380,6 +397,13 @@ int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr)
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;
}
......
......@@ -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);
......@@ -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))
......
......@@ -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);
......
......@@ -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++) {
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment