Skip to content

Commit

Permalink
perf tools: Add refcnt into struct mem_info
Browse files Browse the repository at this point in the history
It's passed along several hists entries in --hierarchy mode, so it's
better we keep track of it.

The current fail I see is that it gets removed in hierarchy --mem-mode
mode, where it's shared in the different hierarchies, but removed from
the template hist entry, so the report crashes.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180307155020.32613-6-jolsa@kernel.org
[ Rename mem_info__aloc() to mem_info__new(), to fix the typo and use the convention for constructors ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Mar 8, 2018
1 parent 915b4e2 commit 9f87498
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists,
* This mem info was allocated from sample__resolve_mem
* and will not be used anymore.
*/
zfree(&entry->mem_info);
mem_info__zput(entry->mem_info);

/* If the map of an existing hist_entry has
* become out-of-date due to an exec() or
Expand Down Expand Up @@ -1139,7 +1139,7 @@ void hist_entry__delete(struct hist_entry *he)
if (he->mem_info) {
map__zput(he->mem_info->iaddr.map);
map__zput(he->mem_info->daddr.map);
zfree(&he->mem_info);
mem_info__zput(he->mem_info);
}

zfree(&he->stat_acc);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ static void ip__resolve_data(struct thread *thread,
struct mem_info *sample__resolve_mem(struct perf_sample *sample,
struct addr_location *al)
{
struct mem_info *mi = zalloc(sizeof(*mi));
struct mem_info *mi = mem_info__new();

if (!mi)
return NULL;
Expand Down
22 changes: 22 additions & 0 deletions tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2221,3 +2221,25 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,
free(bf);
return 0;
}

struct mem_info *mem_info__get(struct mem_info *mi)
{
if (mi)
refcount_inc(&mi->refcnt);
return mi;
}

void mem_info__put(struct mem_info *mi)
{
if (mi && refcount_dec_and_test(&mi->refcnt))
free(mi);
}

struct mem_info *mem_info__new(void)
{
struct mem_info *mi = zalloc(sizeof(*mi));

if (mi)
refcount_set(&mi->refcnt, 1);
return mi;
}
19 changes: 16 additions & 3 deletions tools/perf/util/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ struct branch_info {
};

struct mem_info {
struct addr_map_symbol iaddr;
struct addr_map_symbol daddr;
union perf_mem_data_src data_src;
struct addr_map_symbol iaddr;
struct addr_map_symbol daddr;
union perf_mem_data_src data_src;
refcount_t refcnt;
};

struct addr_location {
Expand Down Expand Up @@ -389,4 +390,16 @@ int sdt_notes__get_count(struct list_head *start);
#define SDT_NOTE_NAME "stapsdt"
#define NR_ADDR 3

struct mem_info *mem_info__new(void);
struct mem_info *mem_info__get(struct mem_info *mi);
void mem_info__put(struct mem_info *mi);

static inline void __mem_info__zput(struct mem_info **mi)
{
mem_info__put(*mi);
*mi = NULL;
}

#define mem_info__zput(mi) __mem_info__zput(&mi)

#endif /* __PERF_SYMBOL */

0 comments on commit 9f87498

Please sign in to comment.