All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	David Ahern <dsahern@gmail.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 05/19] perf tools: Add refcnt into struct mem_info
Date: Wed,  7 Mar 2018 16:50:06 +0100	[thread overview]
Message-ID: <20180307155020.32613-6-jolsa@kernel.org> (raw)
In-Reply-To: <20180307155020.32613-1-jolsa@kernel.org>

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.

Link: http://lkml.kernel.org/n/tip-vwr82ygpfv4kisaxfyopaef6@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/hist.c    |  4 ++--
 tools/perf/util/machine.c |  2 +-
 tools/perf/util/symbol.c  | 22 ++++++++++++++++++++++
 tools/perf/util/symbol.h  | 19 ++++++++++++++++---
 4 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 44a8456cea10..7d968892ee39 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -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
@@ -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);
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 12b7427444a3..d46c98d6dedd 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -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__aloc();
 
 	if (!mi)
 		return NULL;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index a1a312d99f30..117cd25cd21a 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -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__aloc(void)
+{
+	struct mem_info *mi = zalloc(sizeof(*mi));
+
+	if (mi)
+		refcount_set(&mi->refcnt, 1);
+	return mi;
+}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 0563f33c1eb3..7e3ac7f35d63 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -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 {
@@ -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__aloc(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 */
-- 
2.13.6

  parent reply	other threads:[~2018-03-07 15:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 15:50 [PATCH 00/19] perf tools: Assorted fixes Jiri Olsa
2018-03-07 15:50 ` [PATCH 01/19] perf report: Fix the output for stdio events list Jiri Olsa
2018-03-09  8:51   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 02/19] perf report: Display perf.data header info Jiri Olsa
2018-03-09  8:52   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 03/19] perf record: Move machine variable down the function Jiri Olsa
2018-03-09  8:52   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 04/19] perf record: Remove progname from struct record Jiri Olsa
2018-03-09  8:53   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` Jiri Olsa [this message]
2018-03-07 18:56   ` [PATCH 05/19] perf tools: Add refcnt into struct mem_info Arnaldo Carvalho de Melo
2018-03-08 10:59     ` Jiri Olsa
2018-03-09  8:53   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 06/19] perf c2c: Use mem_info refcnt logic Jiri Olsa
2018-03-09  8:54   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 07/19] perf tools: Add MEM_TOPOLOGY feature to perf data file Jiri Olsa
2018-03-07 19:28   ` Arnaldo Carvalho de Melo
2018-03-09  8:54   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 08/19] perf tools: Add mem2node object Jiri Olsa
2018-03-07 19:27   ` Arnaldo Carvalho de Melo
2018-03-08 11:03     ` Jiri Olsa
2018-03-08 12:58       ` Arnaldo Carvalho de Melo
2018-03-08 13:00         ` Arnaldo Carvalho de Melo
2018-03-08 13:18         ` Jiri Olsa
2018-03-07 15:50 ` [PATCH 09/19] perf tests: Add mem2node object test Jiri Olsa
2018-03-07 15:50 ` [PATCH 10/19] perf c2c record: Record physical addresses in samples Jiri Olsa
2018-03-07 15:50 ` [PATCH 11/19] perf c2c report: Make calc_width work with struct c2c_hist_entry Jiri Olsa
2018-03-07 15:50 ` [PATCH 12/19] perf c2c report: Call calc_width only for displayed entries Jiri Olsa
2018-03-07 15:50 ` [PATCH 13/19] perf c2c report: Display node for cacheline address Jiri Olsa
2018-03-07 15:50 ` [PATCH 14/19] perf c2c report: Add span header over cacheline data Jiri Olsa
2018-03-07 15:50 ` [PATCH 15/19] perf c2c report: Add cacheline address count column Jiri Olsa
2018-03-07 15:50 ` [PATCH 16/19] perf tools: Update tags with .cpp files Jiri Olsa
2018-03-07 19:28   ` Arnaldo Carvalho de Melo
2018-03-09  8:55   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 17/19] perf build: Add llvm/clang/cxx make tests into FEATURE_TESTS_EXTRA Jiri Olsa
2018-03-09  8:55   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 18/19] perf build: Add llvm/clang make targets to FILES Jiri Olsa
2018-03-09  8:56   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-07 15:50 ` [PATCH 19/19] perf build: Force llvm/clang test compile output to .make.output Jiri Olsa
2018-03-07 19:30   ` Arnaldo Carvalho de Melo
2018-03-09  8:56   ` [tip:perf/core] " tip-bot for Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180307155020.32613-6-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.