linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	kernel-team@lge.com, Masami Hiramatsu <mhiramat@kernel.org>,
	Andi Kleen <andi@firstfloor.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH/RFC 6/9] perf symbols: Use already loaded module dso when loading kcore
Date: Fri, 23 Jun 2017 14:48:24 +0900	[thread overview]
Message-ID: <20170623054827.3828-7-namhyung@kernel.org> (raw)
In-Reply-To: <20170623054827.3828-1-namhyung@kernel.org>

Even every module has loaded onto same addresses, some modules can be
changed and reloaded.  In that case it needs to access to the old module
in the build-id cache.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/symbol.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index ce79a51f25bf..fe46eb782297 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1155,6 +1155,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	int err, fd;
 	char kcore_filename[PATH_MAX];
 	struct symbol *sym;
+	struct map_groups old_mg;
 
 	if (!kmaps)
 		return -EINVAL;
@@ -1196,15 +1197,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		goto out_err;
 	}
 
-	/* Remove old maps */
-	old_map = map_groups__first(kmaps, map->type);
-	while (old_map) {
-		struct map *next = map_groups__next(old_map);
-
-		if (old_map != map)
-			map_groups__remove(kmaps, old_map);
-		old_map = next;
-	}
+	old_mg = *kmaps;
+	kmaps->maps[map->type].entries = RB_ROOT;
 
 	/* Find the kernel map using the first symbol */
 	sym = dso__first_symbol(dso, map->type);
@@ -1223,24 +1217,31 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	while (!list_empty(&md.maps)) {
 		new_map = list_entry(md.maps.next, struct map, node);
 		list_del_init(&new_map->node);
-		if (new_map == replacement_map) {
-			map->start	= new_map->start;
-			map->end	= new_map->end;
-			map->pgoff	= new_map->pgoff;
-			map->map_ip	= new_map->map_ip;
-			map->unmap_ip	= new_map->unmap_ip;
-			/* Ensure maps are correctly ordered */
-			map__get(map);
-			map_groups__remove(kmaps, map);
-			map_groups__insert(kmaps, map);
-			map__put(map);
-		} else {
-			map_groups__insert(kmaps, new_map);
+
+		map_groups__insert(kmaps, new_map);
+
+		if (new_map != replacement_map) {
+			old_map = map_groups__find(&old_mg, new_map->type, new_map->start);
+			if (old_map && dso__loaded(old_map->dso, old_map->type)) {
+				new_map->pgoff = old_map->pgoff;
+
+				dso__put(new_map->dso);
+				new_map->dso = dso__get(old_map->dso);
+			}
 		}
 
 		map__put(new_map);
 	}
 
+	/* Remove old maps */
+	old_map = map_groups__first(&old_mg, map->type);
+	while (old_map) {
+		struct map *next = map_groups__next(old_map);
+
+		map_groups__remove(&old_mg, old_map);
+		old_map = next;
+	}
+
 	/*
 	 * Set the data type and long name so that kcore can be read via
 	 * dso__data_read_addr().
-- 
2.13.1

  parent reply	other threads:[~2017-06-23  5:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23  5:48 [PATCHSET/RFC 0/9] perf tools: Support out-of-tree modules Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 1/9] perf symbols: Use absolute address to fixup map address Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 2/9] perf tools: Remove duplicate code Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 3/9] perf symbols: Discard symbols in kallsyms for loaded modules Namhyung Kim
2017-06-23 13:51   ` Arnaldo Carvalho de Melo
2017-06-25 13:47     ` Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 4/9] perf symbols: Load kernel module symbols ASAP Namhyung Kim
2017-06-23 14:26   ` Arnaldo Carvalho de Melo
2017-06-25 14:17     ` Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 5/9] perf symbols: Fixup the end address of kernel map properly Namhyung Kim
2017-06-23 14:27   ` Arnaldo Carvalho de Melo
2017-06-25 14:34     ` Namhyung Kim
2017-06-23  5:48 ` Namhyung Kim [this message]
2017-06-23 13:55   ` [PATCH/RFC 6/9] perf symbols: Use already loaded module dso when loading kcore Arnaldo Carvalho de Melo
2017-06-25 13:54     ` Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 7/9] perf tools: Add symbol_conf.use_kcore Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 8/9] perf record: Not use kcore by default Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 9/9] perf record: Add --module-dir option Namhyung Kim
2017-06-23 14:45   ` Arnaldo Carvalho de Melo
2017-06-25 14:43     ` Namhyung Kim

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=20170623054827.3828-7-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=wangnan0@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).