Skip to content

Commit 9f87498

Browse files
olsajiriacmel
authored andcommitted
perf tools: Add refcnt into struct mem_info
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>
1 parent 915b4e2 commit 9f87498

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎tools/perf/util/hist.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists,
536536
* This mem info was allocated from sample__resolve_mem
537537
* and will not be used anymore.
538538
*/
539-
zfree(&entry->mem_info);
539+
mem_info__zput(entry->mem_info);
540540

541541
/* If the map of an existing hist_entry has
542542
* become out-of-date due to an exec() or
@@ -1139,7 +1139,7 @@ void hist_entry__delete(struct hist_entry *he)
11391139
if (he->mem_info) {
11401140
map__zput(he->mem_info->iaddr.map);
11411141
map__zput(he->mem_info->daddr.map);
1142-
zfree(&he->mem_info);
1142+
mem_info__zput(he->mem_info);
11431143
}
11441144

11451145
zfree(&he->stat_acc);

‎tools/perf/util/machine.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ static void ip__resolve_data(struct thread *thread,
16971697
struct mem_info *sample__resolve_mem(struct perf_sample *sample,
16981698
struct addr_location *al)
16991699
{
1700-
struct mem_info *mi = zalloc(sizeof(*mi));
1700+
struct mem_info *mi = mem_info__new();
17011701

17021702
if (!mi)
17031703
return NULL;

‎tools/perf/util/symbol.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,3 +2221,25 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,
22212221
free(bf);
22222222
return 0;
22232223
}
2224+
2225+
struct mem_info *mem_info__get(struct mem_info *mi)
2226+
{
2227+
if (mi)
2228+
refcount_inc(&mi->refcnt);
2229+
return mi;
2230+
}
2231+
2232+
void mem_info__put(struct mem_info *mi)
2233+
{
2234+
if (mi && refcount_dec_and_test(&mi->refcnt))
2235+
free(mi);
2236+
}
2237+
2238+
struct mem_info *mem_info__new(void)
2239+
{
2240+
struct mem_info *mi = zalloc(sizeof(*mi));
2241+
2242+
if (mi)
2243+
refcount_set(&mi->refcnt, 1);
2244+
return mi;
2245+
}

‎tools/perf/util/symbol.h‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ struct branch_info {
200200
};
201201

202202
struct mem_info {
203-
struct addr_map_symbol iaddr;
204-
struct addr_map_symbol daddr;
205-
union perf_mem_data_src data_src;
203+
struct addr_map_symbol iaddr;
204+
struct addr_map_symbol daddr;
205+
union perf_mem_data_src data_src;
206+
refcount_t refcnt;
206207
};
207208

208209
struct addr_location {
@@ -389,4 +390,16 @@ int sdt_notes__get_count(struct list_head *start);
389390
#define SDT_NOTE_NAME "stapsdt"
390391
#define NR_ADDR 3
391392

393+
struct mem_info *mem_info__new(void);
394+
struct mem_info *mem_info__get(struct mem_info *mi);
395+
void mem_info__put(struct mem_info *mi);
396+
397+
static inline void __mem_info__zput(struct mem_info **mi)
398+
{
399+
mem_info__put(*mi);
400+
*mi = NULL;
401+
}
402+
403+
#define mem_info__zput(mi) __mem_info__zput(&mi)
404+
392405
#endif /* __PERF_SYMBOL */

0 commit comments

Comments
 (0)