All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf tools: allow map files to specify DSO
@ 2018-05-07 18:24 Josh Hunt
  2018-05-07 18:40 ` Andi Kleen
  0 siblings, 1 reply; 4+ messages in thread
From: Josh Hunt @ 2018-05-07 18:24 UTC (permalink / raw)
  To: mingo, acme
  Cc: peterz, alexander.shishkin, jolsa, namhyung, wangnan0,
	linux-perf-users, linux-kernel, ak, eranian, Josh Hunt

Add the ability to specify a DSO in the /tmp/perf-<PID>.map file.
The DSO should be the first line in the file and readable by the
running user. If a valid DSO is found all other contents of the
file will be ignored. This allows things like callchain unwinding
with DWARF to work.

Suggested-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Josh Hunt <johunt@akamai.com>
---
We have an application which uses huge pages for its text section, but
still needs the ability to do callchain unwinding with DWARF. We use
the perf-<PID>.map file setup to do symbol resolution and that works
great, but callchain unwinding fails.

A few months ago I mentioned this to Wang Nan and he suggested a way
around this problem could be to specify the path of the DSO in the map
file. The attached patch is my initial hack at this. Running with this
patch I can now get full callchain unwinding with DWARF.

FWIW LBR + map file works with callchains, but unfortunately there are
some cases where we still need DWARF.

I submitted an RFC as an earlier draft:
https://lkml.org/lkml/2018/4/24/1070

v2:
1. Rebase RFC patch to
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core
2. Update jit-interface.txt as per Arnaldo's request

 tools/perf/Documentation/jit-interface.txt |  8 +++++---
 tools/perf/util/map.c                      | 32 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/jit-interface.txt b/tools/perf/Documentation/jit-interface.txt
index a8656f564915..8a25b979802f 100644
--- a/tools/perf/Documentation/jit-interface.txt
+++ b/tools/perf/Documentation/jit-interface.txt
@@ -3,13 +3,15 @@ by a JIT.
 
 The JIT has to write a /tmp/perf-%d.map  (%d = pid of process) file
 
-This is a text file.
+This is a text file and can have one of the following formats:
 
-Each line has the following format, fields separated with spaces:
+1) Each line has the following format, fields separated with spaces:
 
 START SIZE symbolname
 
 START and SIZE are hex numbers without 0x.
 symbolname is the rest of the line, so it could contain special characters.
 
-The ownership of the file has to match the process.
+2) A single line with the full pathname of the DSO to use.
+
+For both formats, the ownership of the file has to match the process.
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index c8fe836e4c3c..da3050b18e34 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -139,6 +139,31 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
 	refcount_set(&map->refcnt, 1);
 }
 
+static bool replace_anon(char *mapfilename)
+{
+	FILE *file = NULL;
+	bool ret = false;
+
+	file = fopen(mapfilename, "r");
+	if (file != NULL) {
+		char *line = NULL;
+		size_t line_len, linesz=0;
+
+		line_len = getline(&line, &linesz, file);
+		if (line_len > 0) {
+			line[line_len-1] = '\0'; /* null terminate */
+			if (!access(line, R_OK)) {
+				strlcpy(mapfilename, line, line_len);
+				ret = true;
+			}
+		}
+		free(line);
+		fclose(file);
+	}
+
+	return ret;
+}
+
 struct map *map__new(struct machine *machine, u64 start, u64 len,
 		     u64 pgoff, u32 d_maj, u32 d_min, u64 ino,
 		     u64 ino_gen, u32 prot, u32 flags, char *filename,
@@ -170,6 +195,13 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 			snprintf(newfilename, sizeof(newfilename),
 				 "/tmp/perf-%d.map", nsi->pid);
 			filename = newfilename;
+			/*
+			 * Check to see if map file references DSO to use, if so, use it.
+			 */
+			if (anon && replace_anon(newfilename)) {
+				anon = 0;
+				filename = newfilename;
+			}
 		}
 
 		if (android) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] perf tools: allow map files to specify DSO
  2018-05-07 18:24 [PATCH v2] perf tools: allow map files to specify DSO Josh Hunt
@ 2018-05-07 18:40 ` Andi Kleen
  2018-05-07 21:30   ` Josh Hunt
  0 siblings, 1 reply; 4+ messages in thread
From: Andi Kleen @ 2018-05-07 18:40 UTC (permalink / raw)
  To: Josh Hunt
  Cc: mingo, acme, peterz, alexander.shishkin, jolsa, namhyung,
	wangnan0, linux-perf-users, linux-kernel, eranian

On Mon, May 07, 2018 at 02:24:16PM -0400, Josh Hunt wrote:
> Add the ability to specify a DSO in the /tmp/perf-<PID>.map file.
> The DSO should be the first line in the file and readable by the
> running user. If a valid DSO is found all other contents of the
> file will be ignored. This allows things like callchain unwinding
> with DWARF to work.

FWIW it's ok, but also obsolete with Kirill's large-pages-in-tmpfs
work in newer kernels. With that you can just copy the executable into
a 2MB tmpfs and disable the manual huge page copying and everything
should work as usually.

So essentially it's only a hack for old kernels and old binaries.

But doesn't hurt I guess.

-Andi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] perf tools: allow map files to specify DSO
  2018-05-07 18:40 ` Andi Kleen
@ 2018-05-07 21:30   ` Josh Hunt
  2018-05-08  0:34     ` Andi Kleen
  0 siblings, 1 reply; 4+ messages in thread
From: Josh Hunt @ 2018-05-07 21:30 UTC (permalink / raw)
  To: Andi Kleen
  Cc: mingo, acme, peterz, alexander.shishkin, jolsa, namhyung,
	wangnan0, linux-perf-users, linux-kernel, eranian

On 05/07/2018 11:40 AM, Andi Kleen wrote:
> On Mon, May 07, 2018 at 02:24:16PM -0400, Josh Hunt wrote:
>> Add the ability to specify a DSO in the /tmp/perf-<PID>.map file.
>> The DSO should be the first line in the file and readable by the
>> running user. If a valid DSO is found all other contents of the
>> file will be ignored. This allows things like callchain unwinding
>> with DWARF to work.
> 
> FWIW it's ok, but also obsolete with Kirill's large-pages-in-tmpfs
> work in newer kernels. With that you can just copy the executable into
> a 2MB tmpfs and disable the manual huge page copying and everything
> should work as usually.
> 
> So essentially it's only a hack for old kernels and old binaries.
> 
> But doesn't hurt I guess.

Ah, very interesting. I wasn't aware of this. Can you point me to some 
more details on this process?

Thanks
Josh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] perf tools: allow map files to specify DSO
  2018-05-07 21:30   ` Josh Hunt
@ 2018-05-08  0:34     ` Andi Kleen
  0 siblings, 0 replies; 4+ messages in thread
From: Andi Kleen @ 2018-05-08  0:34 UTC (permalink / raw)
  To: Josh Hunt
  Cc: mingo, acme, peterz, alexander.shishkin, jolsa, namhyung,
	wangnan0, linux-perf-users, linux-kernel, eranian,
	kirill.shutemov

On Mon, May 07, 2018 at 02:30:32PM -0700, Josh Hunt wrote:
> On 05/07/2018 11:40 AM, Andi Kleen wrote:
> > On Mon, May 07, 2018 at 02:24:16PM -0400, Josh Hunt wrote:
> > > Add the ability to specify a DSO in the /tmp/perf-<PID>.map file.
> > > The DSO should be the first line in the file and readable by the
> > > running user. If a valid DSO is found all other contents of the
> > > file will be ignored. This allows things like callchain unwinding
> > > with DWARF to work.
> > 
> > FWIW it's ok, but also obsolete with Kirill's large-pages-in-tmpfs
> > work in newer kernels. With that you can just copy the executable into
> > a 2MB tmpfs and disable the manual huge page copying and everything
> > should work as usually.
> > 
> > So essentially it's only a hack for old kernels and old binaries.
> > 
> > But doesn't hurt I guess.
> 
> Ah, very interesting. I wasn't aware of this. Can you point me to some more
> details on this process?

See commit 5a6e75f8110c97e2a5488894d4e922187e6cb343

-Andi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-08  0:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-07 18:24 [PATCH v2] perf tools: allow map files to specify DSO Josh Hunt
2018-05-07 18:40 ` Andi Kleen
2018-05-07 21:30   ` Josh Hunt
2018-05-08  0:34     ` Andi Kleen

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.