Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1500165 > unrolled thread

[PATCH 0/9] perf/jit: various improvements

Started byStephane Eranian <eranian@google.com>
First post2016-10-13 13:10 +0200
Last post2016-10-24 21:00 +0200
Articles 20 on this page of 23 — 6 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/9] perf/jit: various improvements Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
    [PATCH 1/9] perf/jit: improve error messages from JVMTI Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
      Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI Nilay Vaish <nilayvaish@gmail.com> - 2016-10-13 22:30 +0200
        Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 13:20 +0200
          Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI Stephane Eranian <eranian@google.com> - 2016-10-14 15:30 +0200
            Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 17:30 +0200
              Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI Stephane Eranian <eranian@google.com> - 2016-10-17 16:00 +0200
      [tip:perf/core] perf jit: Improve error messages from JVMTI tip-bot for Stephane Eranian <tipbot@zytor.com> - 2016-10-24 21:10 +0200
    [PATCH 5/9] perf/jit: do not assume pgoff is zero Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
      [tip:perf/core] perf jit: Do not assume pgoff is zero tip-bot for Stefano Sanfilippo <tipbot@zytor.com> - 2016-10-24 21:10 +0200
    [PATCH 8/9] perf/jit: Check JITHEADER_VERSION Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
      [tip:perf/core] perf jit: Check JITHEADER_VERSION tip-bot for Stefano Sanfilippo <tipbot@zytor.com> - 2016-10-24 21:10 +0200
    [PATCH 3/9] perf/jit: remove unecessary padding in jitdump file Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
      [tip:perf/core] perf jit: Remove unecessary padding in jitdump file tip-bot for Stephane Eranian <tipbot@zytor.com> - 2016-10-24 21:00 +0200
    [PATCH 6/9] perf/jit: add unwinding support Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
      [tip:perf/core] perf jit: Add unwinding support tip-bot for Stefano Sanfilippo <tipbot@zytor.com> - 2016-10-24 21:10 +0200
    [PATCH 2/9] perf/jit: enable jitdump support without dwarf Stephane Eranian <eranian@google.com> - 2016-10-13 13:10 +0200
      Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-13 20:20 +0200
        Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-13 21:00 +0200
          Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-13 21:20 +0200
            Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-13 21:50 +0200
        Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-13 21:40 +0200
      [tip:perf/core] perf jit: Enable jitdump support without dwarf tip-bot for Maciej Debski <tipbot@zytor.com> - 2016-10-24 21:00 +0200

Page 1 of 2  [1] 2  Next page →


#1500165 — [PATCH 0/9] perf/jit: various improvements

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 0/9] perf/jit: various improvements
Message-ID<srM3D-2I3-3@gated-at.bofh.it>
From: Stephane Eranian <eranian@gmail.com>

This patch series provides several important enhancements to the perf jit code
profiling support. The following is changed:
 - enable building pref jitdump support without DWARF (Maciej)
 - Add Exception Handling (EH) Frame record type to support unwinding
 - remove useless padding of data in jitdump file
 - provide a specification document for the jitdump format to help jit runtime developers add support

Note that the runtime needs to emit the unwind information. This is not supported for openJDK via JVMTI.

Thanks to Maciej, Stefano, and Ross for their contributions.

Maciej Debski (1):
  perf/jit: enable jitdump support without dwarf

Stefano Sanfilippo (5):
  perf/jit: make perf skip unknown records
  perf/jit: do not assume pgoff is zero
  perf/jit: add unwinding support
  perf/jit: generate .eh_frame/.eh_frame_hdr in DSO
  perf/jit: Check JITHEADER_VERSION

Stephane Eranian (3):
  perf/jit: improve error messages from JVMTI
  perf/jit: remove unecessary padding in jitdump file
  perf/jit: add jitdump format specification document

 tools/perf/Documentation/jitdump-specification.txt | 170 +++++++++++++++++++++
 tools/perf/Makefile.config                         |   2 -
 tools/perf/jvmti/jvmti_agent.c                     |  38 +----
 tools/perf/jvmti/libjvmti.c                        |  37 +++--
 tools/perf/util/Build                              |   2 +-
 tools/perf/util/genelf.c                           | 109 ++++++++++++-
 tools/perf/util/genelf.h                           |   5 +-
 tools/perf/util/jitdump.c                          |  80 ++++++++--
 tools/perf/util/jitdump.h                          |  12 ++
 tools/perf/util/unwind-libunwind-local.c           |   4 +-
 10 files changed, 393 insertions(+), 66 deletions(-)
 create mode 100644 tools/perf/Documentation/jitdump-specification.txt

-- 
1.9.1

[toc] | [next] | [standalone]


#1500166 — [PATCH 1/9] perf/jit: improve error messages from JVMTI

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 1/9] perf/jit: improve error messages from JVMTI
Message-ID<srM3D-2I3-17@gated-at.bofh.it>
In reply to#1500165
This patch improves the usefulness of error messages
generated by the JVMTI interfac.e This can help identify
the root cause of a problem by printing the actual error
code. The patch adds a new helper function called print_error().

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/jvmti/libjvmti.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index ac12e4b91a92..2d9bc04b79a8 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -12,6 +12,17 @@
 static int has_line_numbers;
 void *jvmti_agent;
 
+static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret)
+{
+	char *err_msg = NULL;
+	jvmtiError err;
+	err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg);
+	if (err == JVMTI_ERROR_NONE) {
+		warnx("%s failed with %s", msg, err_msg);
+		(*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
+	}
+}
+
 static jvmtiError
 do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
 		    jvmti_line_info_t *tab, jint *nr)
@@ -22,8 +33,10 @@ do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
 	jvmtiError ret;
 
 	ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab);
-	if (ret != JVMTI_ERROR_NONE)
+	if (ret != JVMTI_ERROR_NONE) {
+		print_error(jvmti, "GetLineNumberTable", ret);
 		return ret;
+	}
 
 	for (i = 0; i < nr_lines; i++) {
 		if (loc_tab[i].start_location < bci) {
@@ -71,6 +84,8 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, jvmti_line_info_t **
 					/* free what was allocated for nothing */
 					(*jvmti)->Deallocate(jvmti, (unsigned char *)lne);
 					nr_total += (int)nr;
+				} else {
+					print_error(jvmti, "GetLineNumberTable", ret);
 				}
 			}
 		}
@@ -130,7 +145,7 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
 	ret = (*jvmti)->GetMethodDeclaringClass(jvmti, method,
 						&decl_class);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: cannot get declaring class");
+		print_error(jvmti, "GetMethodDeclaringClass", ret);
 		return;
 	}
 
@@ -144,21 +159,21 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
 
 	ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: cannot get source filename ret=%d", ret);
+		print_error(jvmti, "GetSourceFileName", ret);
 		goto error;
 	}
 
 	ret = (*jvmti)->GetClassSignature(jvmti, decl_class,
 					  &class_sign, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: getclassignature failed");
+		print_error(jvmti, "GetClassSignature", ret);
 		goto error;
 	}
 
 	ret = (*jvmti)->GetMethodName(jvmti, method, &func_name,
 				      &func_sign, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: failed getmethodname");
+		print_error(jvmti, "GetMethodName", ret);
 		goto error;
 	}
 
@@ -253,7 +268,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused)
 
 	ret = (*jvmti)->AddCapabilities(jvmti, &caps1);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: acquire compiled_method capability failed");
+		print_error(jvmti, "AddCapabilities", ret);
 		return -1;
 	}
 	ret = (*jvmti)->GetJLocationFormat(jvmti, &format);
@@ -264,7 +279,9 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused)
 		ret = (*jvmti)->AddCapabilities(jvmti, &caps1);
                 if (ret == JVMTI_ERROR_NONE)
                         has_line_numbers = 1;
-        }
+        } else if (ret != JVMTI_ERROR_NONE)
+		print_error(jvmti, "GetJLocationFormat", ret);
+
 
 	memset(&cb, 0, sizeof(cb));
 
@@ -273,21 +290,21 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused)
 
 	ret = (*jvmti)->SetEventCallbacks(jvmti, &cb, sizeof(cb));
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: cannot set event callbacks");
+		print_error(jvmti, "SetEventCallbacks", ret);
 		return -1;
 	}
 
 	ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 			JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: setnotification failed for method_load");
+		print_error(jvmti, "SetEventNotificationMode(METHOD_LOAD)", ret);
 		return -1;
 	}
 
 	ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 			JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: setnotification failed on code_generated");
+		print_error(jvmti, "SetEventNotificationMode(CODE_GENERATED)", ret);
 		return -1;
 	}
 	return 0;
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1500541 — Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI

FromNilay Vaish <nilayvaish@gmail.com>
Date2016-10-13 22:30 +0200
SubjectRe: [PATCH 1/9] perf/jit: improve error messages from JVMTI
Message-ID<srUNz-8lw-1@gated-at.bofh.it>
In reply to#1500166
On 13 October 2016 at 05:59, Stephane Eranian <eranian@google.com> wrote:
> diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
> index ac12e4b91a92..2d9bc04b79a8 100644
> --- a/tools/perf/jvmti/libjvmti.c
> +++ b/tools/perf/jvmti/libjvmti.c
> @@ -12,6 +12,17 @@
>  static int has_line_numbers;
>  void *jvmti_agent;
>
> +static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret)
> +{
> +       char *err_msg = NULL;
> +       jvmtiError err;
> +       err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg);
> +       if (err == JVMTI_ERROR_NONE) {
> +               warnx("%s failed with %s", msg, err_msg);
> +               (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
> +       }
> +}

Do we not need to release the memory for err_msg if the condition for
the 'if' statement evaluates to false?  Is it that we are going to
kill the process, so no need to release the memory?

--
Nilay

[toc] | [prev] | [next] | [standalone]


#1500832 — Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-14 13:20 +0200
SubjectRe: [PATCH 1/9] perf/jit: improve error messages from JVMTI
Message-ID<ss8GS-zD-1@gated-at.bofh.it>
In reply to#1500541
Em Thu, Oct 13, 2016 at 03:05:40PM -0500, Nilay Vaish escreveu:
> On 13 October 2016 at 05:59, Stephane Eranian <eranian@google.com> wrote:
> > +++ b/tools/perf/jvmti/libjvmti.c
> > @@ -12,6 +12,17 @@
> > +static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret)
> > +{
> > +       char *err_msg = NULL;
> > +       jvmtiError err;
> > +       err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg);
> > +       if (err == JVMTI_ERROR_NONE) {
> > +               warnx("%s failed with %s", msg, err_msg);
> > +               (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
> > +       }
> > +}
> 
> Do we not need to release the memory for err_msg if the condition for
> the 'if' statement evaluates to false?  Is it that we are going to
> kill the process, so no need to release the memory?

I guess that print_error() is called only when an error was returned
somewhere, that ret parameter, then if there was no error
(JVMTI_ERROR_NONE) in translating that numeric code to an string,
err_msg, it can then be used with warnx() (the main purpose of
print_error()) and then deallocated.

For err != JVMTI_ERROR_NONE it silently goes back to the caller that
expected it to print something.

I.e. probably it should have an else clause, something like:

	if (err == JVMTI_ERROR_NONE) {
		warnx("%s failed with %s", msg, err_msg);
		(*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
	} else {
		warnx("%s failed with an unknown error %d", msg, (int)ret);
	}

Stephane?

- Arnaldo

[toc] | [prev] | [next] | [standalone]


#1500977 — Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI

FromStephane Eranian <eranian@google.com>
Date2016-10-14 15:30 +0200
SubjectRe: [PATCH 1/9] perf/jit: improve error messages from JVMTI
Message-ID<ssaIF-1MD-5@gated-at.bofh.it>
In reply to#1500832
On Fri, Oct 14, 2016 at 4:13 AM, Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> Em Thu, Oct 13, 2016 at 03:05:40PM -0500, Nilay Vaish escreveu:
>> On 13 October 2016 at 05:59, Stephane Eranian <eranian@google.com> wrote:
>> > +++ b/tools/perf/jvmti/libjvmti.c
>> > @@ -12,6 +12,17 @@
>> > +static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret)
>> > +{
>> > +       char *err_msg = NULL;
>> > +       jvmtiError err;
>> > +       err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg);
>> > +       if (err == JVMTI_ERROR_NONE) {
>> > +               warnx("%s failed with %s", msg, err_msg);
>> > +               (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
>> > +       }
>> > +}
>>
>> Do we not need to release the memory for err_msg if the condition for
>> the 'if' statement evaluates to false?  Is it that we are going to
>> kill the process, so no need to release the memory?
>
> I guess that print_error() is called only when an error was returned
> somewhere, that ret parameter, then if there was no error
> (JVMTI_ERROR_NONE) in translating that numeric code to an string,
> err_msg, it can then be used with warnx() (the main purpose of
> print_error()) and then deallocated.
>
> For err != JVMTI_ERROR_NONE it silently goes back to the caller that
> expected it to print something.
>
> I.e. probably it should have an else clause, something like:
>
>         if (err == JVMTI_ERROR_NONE) {
>                 warnx("%s failed with %s", msg, err_msg);
>                 (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
>         } else {
>                 warnx("%s failed with an unknown error %d", msg, (int)ret);
>         }
>
> Stephane?
>'I will fix all of the comments over the week-end. I am away from office today.

> - Arnaldo

[toc] | [prev] | [next] | [standalone]


#1501059 — Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-14 17:30 +0200
SubjectRe: [PATCH 1/9] perf/jit: improve error messages from JVMTI
Message-ID<sscAO-33Q-19@gated-at.bofh.it>
In reply to#1500977
Em Fri, Oct 14, 2016 at 05:57:25AM -0700, Stephane Eranian escreveu:
> On Fri, Oct 14, 2016 at 4:13 AM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > Em Thu, Oct 13, 2016 at 03:05:40PM -0500, Nilay Vaish escreveu:
> >> Do we not need to release the memory for err_msg if the condition for
> >> the 'if' statement evaluates to false?  Is it that we are going to
> >> kill the process, so no need to release the memory?

> > I guess that print_error() is called only when an error was returned
> > somewhere, that ret parameter, then if there was no error
> > (JVMTI_ERROR_NONE) in translating that numeric code to an string,
> > err_msg, it can then be used with warnx() (the main purpose of
> > print_error()) and then deallocated.
> >
> > For err != JVMTI_ERROR_NONE it silently goes back to the caller that
> > expected it to print something.
> >
> > I.e. probably it should have an else clause, something like:
> >
> >         if (err == JVMTI_ERROR_NONE) {
> >                 warnx("%s failed with %s", msg, err_msg);
> >                 (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
> >         } else {
> >                 warnx("%s failed with an unknown error %d", msg, (int)ret);
> >         }
> >
> > Stephane?
> I will fix all of the comments over the week-end. I am away from office today.

I have almost all of them fixed, will fix this one too, if you agree
with the analysis.

- Arnaldo

[toc] | [prev] | [next] | [standalone]


#1501978 — Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI

FromStephane Eranian <eranian@google.com>
Date2016-10-17 16:00 +0200
SubjectRe: [PATCH 1/9] perf/jit: improve error messages from JVMTI
Message-ID<stgCl-4aL-9@gated-at.bofh.it>
In reply to#1501059
On Fri, Oct 14, 2016 at 8:20 AM, Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> Em Fri, Oct 14, 2016 at 05:57:25AM -0700, Stephane Eranian escreveu:
>> On Fri, Oct 14, 2016 at 4:13 AM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>> > Em Thu, Oct 13, 2016 at 03:05:40PM -0500, Nilay Vaish escreveu:
>> >> Do we not need to release the memory for err_msg if the condition for
>> >> the 'if' statement evaluates to false?  Is it that we are going to
>> >> kill the process, so no need to release the memory?
>
>> > I guess that print_error() is called only when an error was returned
>> > somewhere, that ret parameter, then if there was no error
>> > (JVMTI_ERROR_NONE) in translating that numeric code to an string,
>> > err_msg, it can then be used with warnx() (the main purpose of
>> > print_error()) and then deallocated.
>> >
>> > For err != JVMTI_ERROR_NONE it silently goes back to the caller that
>> > expected it to print something.
>> >
>> > I.e. probably it should have an else clause, something like:
>> >
>> >         if (err == JVMTI_ERROR_NONE) {
>> >                 warnx("%s failed with %s", msg, err_msg);
>> >                 (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
>> >         } else {
>> >                 warnx("%s failed with an unknown error %d", msg, (int)ret);
>> >         }
>> >
>> > Stephane?
>> I will fix all of the comments over the week-end. I am away from office today.
>
> I have almost all of them fixed, will fix this one too, if you agree
> with the analysis.
>
Ok, the proposed fix is correct.
Thanks for fixing issues.

Now, I am tracking down another issue with the injection of jitdump.
It seems something goes wrong with ordering and timestamps and some
valid jitdump samples are not symbolized. It is not clear what is
causing this yet. It may be the issue raised by Adrian a while ago
about the finished_round processing.


> - Arnaldo

[toc] | [prev] | [next] | [standalone]


#1507629 — [tip:perf/core] perf jit: Improve error messages from JVMTI

Fromtip-bot for Stephane Eranian <tipbot@zytor.com>
Date2016-10-24 21:10 +0200
Subject[tip:perf/core] perf jit: Improve error messages from JVMTI
Message-ID<svSNc-3nI-49@gated-at.bofh.it>
In reply to#1500166
Commit-ID:  cdd75e3b0d1e668bc498f18f0ea8353f9f955114
Gitweb:     http://git.kernel.org/tip/cdd75e3b0d1e668bc498f18f0ea8353f9f955114
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 13 Oct 2016 03:59:35 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 24 Oct 2016 11:07:37 -0300

perf jit: Improve error messages from JVMTI

This patch improves the usefulness of error messages generated by the
JVMTI interfac.e This can help identify the root cause of a problem by
printing the actual error code. The patch adds a new helper function
called print_error().

Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1476356383-30100-2-git-send-email-eranian@google.com
[ Handle failure to convert numeric error to a string in print_error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/jvmti/libjvmti.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index ac12e4b..5612641 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -12,6 +12,19 @@
 static int has_line_numbers;
 void *jvmti_agent;
 
+static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret)
+{
+	char *err_msg = NULL;
+	jvmtiError err;
+	err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg);
+	if (err == JVMTI_ERROR_NONE) {
+		warnx("%s failed with %s", msg, err_msg);
+		(*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg);
+	} else {
+		warnx("%s failed with an unknown error %d", msg, ret);
+	}
+}
+
 static jvmtiError
 do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
 		    jvmti_line_info_t *tab, jint *nr)
@@ -22,8 +35,10 @@ do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
 	jvmtiError ret;
 
 	ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab);
-	if (ret != JVMTI_ERROR_NONE)
+	if (ret != JVMTI_ERROR_NONE) {
+		print_error(jvmti, "GetLineNumberTable", ret);
 		return ret;
+	}
 
 	for (i = 0; i < nr_lines; i++) {
 		if (loc_tab[i].start_location < bci) {
@@ -71,6 +86,8 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, jvmti_line_info_t **
 					/* free what was allocated for nothing */
 					(*jvmti)->Deallocate(jvmti, (unsigned char *)lne);
 					nr_total += (int)nr;
+				} else {
+					print_error(jvmti, "GetLineNumberTable", ret);
 				}
 			}
 		}
@@ -130,7 +147,7 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
 	ret = (*jvmti)->GetMethodDeclaringClass(jvmti, method,
 						&decl_class);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: cannot get declaring class");
+		print_error(jvmti, "GetMethodDeclaringClass", ret);
 		return;
 	}
 
@@ -144,21 +161,21 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
 
 	ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: cannot get source filename ret=%d", ret);
+		print_error(jvmti, "GetSourceFileName", ret);
 		goto error;
 	}
 
 	ret = (*jvmti)->GetClassSignature(jvmti, decl_class,
 					  &class_sign, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: getclassignature failed");
+		print_error(jvmti, "GetClassSignature", ret);
 		goto error;
 	}
 
 	ret = (*jvmti)->GetMethodName(jvmti, method, &func_name,
 				      &func_sign, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: failed getmethodname");
+		print_error(jvmti, "GetMethodName", ret);
 		goto error;
 	}
 
@@ -253,7 +270,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused)
 
 	ret = (*jvmti)->AddCapabilities(jvmti, &caps1);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: acquire compiled_method capability failed");
+		print_error(jvmti, "AddCapabilities", ret);
 		return -1;
 	}
 	ret = (*jvmti)->GetJLocationFormat(jvmti, &format);
@@ -264,7 +281,9 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused)
 		ret = (*jvmti)->AddCapabilities(jvmti, &caps1);
                 if (ret == JVMTI_ERROR_NONE)
                         has_line_numbers = 1;
-        }
+        } else if (ret != JVMTI_ERROR_NONE)
+		print_error(jvmti, "GetJLocationFormat", ret);
+
 
 	memset(&cb, 0, sizeof(cb));
 
@@ -273,21 +292,21 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused)
 
 	ret = (*jvmti)->SetEventCallbacks(jvmti, &cb, sizeof(cb));
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: cannot set event callbacks");
+		print_error(jvmti, "SetEventCallbacks", ret);
 		return -1;
 	}
 
 	ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 			JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: setnotification failed for method_load");
+		print_error(jvmti, "SetEventNotificationMode(METHOD_LOAD)", ret);
 		return -1;
 	}
 
 	ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 			JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL);
 	if (ret != JVMTI_ERROR_NONE) {
-		warnx("jvmti: setnotification failed on code_generated");
+		print_error(jvmti, "SetEventNotificationMode(CODE_GENERATED)", ret);
 		return -1;
 	}
 	return 0;

[toc] | [prev] | [next] | [standalone]


#1500167 — [PATCH 5/9] perf/jit: do not assume pgoff is zero

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 5/9] perf/jit: do not assume pgoff is zero
Message-ID<srM3E-2I3-31@gated-at.bofh.it>
In reply to#1500165
From: Stefano Sanfilippo <ssanfilippo@chromium.org>

When calculating .eh_frame_hdr base and LUT offsets do not
always assume that pgoff is zero.

The assumption is false for DSOs built from the jitdump by
perf inject, because the ELF header did not exist in memory at
sampling time.

Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org>
Signed-off-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/util/unwind-libunwind-local.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 20c2e5743903..6fec84dff3f7 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -357,8 +357,8 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 		di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
 		di.start_ip = map->start;
 		di.end_ip   = map->end;
-		di.u.rti.segbase    = map->start + segbase;
-		di.u.rti.table_data = map->start + table_data;
+		di.u.rti.segbase    = map->start + segbase - map->pgoff;
+		di.u.rti.table_data = map->start + table_data - map->pgoff;
 		di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
 				      / sizeof(unw_word_t);
 		ret = dwarf_search_unwind_table(as, ip, &di, pi,
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1507615 — [tip:perf/core] perf jit: Do not assume pgoff is zero

Fromtip-bot for Stefano Sanfilippo <tipbot@zytor.com>
Date2016-10-24 21:10 +0200
Subject[tip:perf/core] perf jit: Do not assume pgoff is zero
Message-ID<svSNc-3nI-35@gated-at.bofh.it>
In reply to#1500167
Commit-ID:  eac05af2bf33aa9474482f1f19555adfd2cdf69d
Gitweb:     http://git.kernel.org/tip/eac05af2bf33aa9474482f1f19555adfd2cdf69d
Author:     Stefano Sanfilippo <ssanfilippo@chromium.org>
AuthorDate: Thu, 13 Oct 2016 03:59:39 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 24 Oct 2016 11:07:39 -0300

perf jit: Do not assume pgoff is zero

When calculating .eh_frame_hdr base and LUT offsets do not always assume
that pgoff is zero.

The assumption is false for DSOs built from the jitdump by perf inject,
because the ELF header did not exist in memory at sampling time.

Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org>
Signed-off-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Stephane Eranian <eranian@google.com>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1476356383-30100-6-git-send-email-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/unwind-libunwind-local.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 20c2e57..6fec84d 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -357,8 +357,8 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 		di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
 		di.start_ip = map->start;
 		di.end_ip   = map->end;
-		di.u.rti.segbase    = map->start + segbase;
-		di.u.rti.table_data = map->start + table_data;
+		di.u.rti.segbase    = map->start + segbase - map->pgoff;
+		di.u.rti.table_data = map->start + table_data - map->pgoff;
 		di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
 				      / sizeof(unw_word_t);
 		ret = dwarf_search_unwind_table(as, ip, &di, pi,

[toc] | [prev] | [next] | [standalone]


#1500168 — [PATCH 8/9] perf/jit: Check JITHEADER_VERSION

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 8/9] perf/jit: Check JITHEADER_VERSION
Message-ID<srM3E-2I3-47@gated-at.bofh.it>
In reply to#1500165
From: Stefano Sanfilippo <ssanfilippo@chromium.org>

Check the version number when opening a jitdump file.
Accept older versions, but not newer ones.

Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org>
Signed-off-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/util/jitdump.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index c47fba63274b..c5dabb3a81fd 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -180,6 +180,12 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 			header.elf_mach,
 			jd->use_arch_timestamp);
 
+	if (header.version > JITHEADER_VERSION) {
+	  pr_err("wrong jitdump version %u, expected " STR(JITHEADER_VERSION),
+		 header.version);
+	  goto error;
+	}
+
 	if (header.flags & JITDUMP_FLAGS_RESERVED) {
 		pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
 		       (unsigned long long)header.flags & JITDUMP_FLAGS_RESERVED);
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1507618 — [tip:perf/core] perf jit: Check JITHEADER_VERSION

Fromtip-bot for Stefano Sanfilippo <tipbot@zytor.com>
Date2016-10-24 21:10 +0200
Subject[tip:perf/core] perf jit: Check JITHEADER_VERSION
Message-ID<svSNb-3nI-21@gated-at.bofh.it>
In reply to#1500168
Commit-ID:  6760d77b708571b925e2dd2b61f847cbee6e0f21
Gitweb:     http://git.kernel.org/tip/6760d77b708571b925e2dd2b61f847cbee6e0f21
Author:     Stefano Sanfilippo <ssanfilippo@chromium.org>
AuthorDate: Thu, 13 Oct 2016 03:59:42 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 24 Oct 2016 11:07:40 -0300

perf jit: Check JITHEADER_VERSION

Check the version number when opening a jitdump file.  Accept older
versions, but not newer ones.

Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org>
Signed-off-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Stephane Eranian <eranian@google.com>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1476356383-30100-9-git-send-email-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/jitdump.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 6a2688d..c9a941e 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -180,6 +180,12 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 			header.elf_mach,
 			jd->use_arch_timestamp);
 
+	if (header.version > JITHEADER_VERSION) {
+		pr_err("wrong jitdump version %u, expected " STR(JITHEADER_VERSION),
+			header.version);
+		goto error;
+	}
+
 	if (header.flags & JITDUMP_FLAGS_RESERVED) {
 		pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
 		       (unsigned long long)header.flags & JITDUMP_FLAGS_RESERVED);

[toc] | [prev] | [next] | [standalone]


#1500172 — [PATCH 3/9] perf/jit: remove unecessary padding in jitdump file

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 3/9] perf/jit: remove unecessary padding in jitdump file
Message-ID<srM3E-2I3-39@gated-at.bofh.it>
In reply to#1500165
This patch removes all the string padding generated in
the jitdump file. There are nonecessary and were adding
unecessary complexity. Modern processors can handle unaligned
accesses quite well. The perf.data/jitdump file are always
postp-processed, no need to add extra complexity for no real
gain.

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/jvmti/jvmti_agent.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 55daefff0d54..e9651a9d670e 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -44,11 +44,6 @@
 static char jit_path[PATH_MAX];
 static void *marker_addr;
 
-/*
- * padding buffer
- */
-static const char pad_bytes[7];
-
 static inline pid_t gettid(void)
 {
 	return (pid_t)syscall(__NR_gettid);
@@ -230,7 +225,6 @@ init_arch_timestamp(void)
 
 void *jvmti_open(void)
 {
-	int pad_cnt;
 	char dump_path[PATH_MAX];
 	struct jitheader header;
 	int fd;
@@ -288,10 +282,6 @@ void *jvmti_open(void)
 	header.total_size = sizeof(header);
 	header.pid        = getpid();
 
-	/* calculate amount of padding '\0' */
-	pad_cnt = PADDING_8ALIGNED(header.total_size);
-	header.total_size += pad_cnt;
-
 	header.timestamp = perf_get_timestamp();
 
 	if (use_arch_timestamp)
@@ -301,13 +291,6 @@ void *jvmti_open(void)
 		warn("jvmti: cannot write dumpfile header");
 		goto error;
 	}
-
-	/* write padding '\0' if necessary */
-	if (pad_cnt && !fwrite(pad_bytes, pad_cnt, 1, fp)) {
-		warn("jvmti: cannot write dumpfile header padding");
-		goto error;
-	}
-
 	return fp;
 error:
 	fclose(fp);
@@ -349,7 +332,6 @@ jvmti_write_code(void *agent, char const *sym,
 	static int code_generation = 1;
 	struct jr_code_load rec;
 	size_t sym_len;
-	size_t padding_count;
 	FILE *fp = agent;
 	int ret = -1;
 
@@ -366,8 +348,6 @@ jvmti_write_code(void *agent, char const *sym,
 
 	rec.p.id           = JIT_CODE_LOAD;
 	rec.p.total_size   = sizeof(rec) + sym_len;
-	padding_count      = PADDING_8ALIGNED(rec.p.total_size);
-	rec.p. total_size += padding_count;
 	rec.p.timestamp    = perf_get_timestamp();
 
 	rec.code_size  = size;
@@ -393,9 +373,6 @@ jvmti_write_code(void *agent, char const *sym,
 	ret = fwrite_unlocked(&rec, sizeof(rec), 1, fp);
 	fwrite_unlocked(sym, sym_len, 1, fp);
 
-	if (padding_count)
-		fwrite_unlocked(pad_bytes, padding_count, 1, fp);
-
 	if (code)
 		fwrite_unlocked(code, size, 1, fp);
 
@@ -412,7 +389,6 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
 {
 	struct jr_code_debug_info rec;
 	size_t sret, len, size, flen;
-	size_t padding_count;
 	uint64_t addr;
 	const char *fn = file;
 	FILE *fp = agent;
@@ -443,16 +419,10 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
 	 * int      : line number
 	 * int      : column discriminator
 	 * file[]   : source file name
-	 * padding  : pad to multiple of 8 bytes
 	 */
 	size += nr_lines * sizeof(struct debug_entry);
 	size += flen * nr_lines;
-	/*
-	 * pad to 8 bytes
-	 */
-	padding_count = PADDING_8ALIGNED(size);
-
-	rec.p.total_size = size + padding_count;
+	rec.p.total_size = size;
 
 	/*
 	 * If JVM is multi-threaded, nultiple concurrent calls to agent
@@ -486,12 +456,6 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
 		if (sret != 1)
 			goto error;
 	}
-	if (padding_count) {
-		sret = fwrite_unlocked(pad_bytes, padding_count, 1, fp);
-		if (sret != 1)
-			goto error;
-	}
-
 	funlockfile(fp);
 	return 0;
 error:
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1507592 — [tip:perf/core] perf jit: Remove unecessary padding in jitdump file

Fromtip-bot for Stephane Eranian <tipbot@zytor.com>
Date2016-10-24 21:00 +0200
Subject[tip:perf/core] perf jit: Remove unecessary padding in jitdump file
Message-ID<svSDw-34S-27@gated-at.bofh.it>
In reply to#1500172
Commit-ID:  13b9012ab42ee93dabe8555f2e701ca139180f85
Gitweb:     http://git.kernel.org/tip/13b9012ab42ee93dabe8555f2e701ca139180f85
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 13 Oct 2016 03:59:37 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 24 Oct 2016 11:07:38 -0300

perf jit: Remove unecessary padding in jitdump file

This patch removes all the string padding generated in the jitdump file.
They are not necessary and were adding unnecessary complexity. Modern
processors can handle unaligned accesses quite well. The perf.data/
jitdump file are always post-processed, no need to add extra complexity
for no real gain.

Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1476356383-30100-4-git-send-email-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/jvmti/jvmti_agent.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 55daeff..e9651a9 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -44,11 +44,6 @@
 static char jit_path[PATH_MAX];
 static void *marker_addr;
 
-/*
- * padding buffer
- */
-static const char pad_bytes[7];
-
 static inline pid_t gettid(void)
 {
 	return (pid_t)syscall(__NR_gettid);
@@ -230,7 +225,6 @@ init_arch_timestamp(void)
 
 void *jvmti_open(void)
 {
-	int pad_cnt;
 	char dump_path[PATH_MAX];
 	struct jitheader header;
 	int fd;
@@ -288,10 +282,6 @@ void *jvmti_open(void)
 	header.total_size = sizeof(header);
 	header.pid        = getpid();
 
-	/* calculate amount of padding '\0' */
-	pad_cnt = PADDING_8ALIGNED(header.total_size);
-	header.total_size += pad_cnt;
-
 	header.timestamp = perf_get_timestamp();
 
 	if (use_arch_timestamp)
@@ -301,13 +291,6 @@ void *jvmti_open(void)
 		warn("jvmti: cannot write dumpfile header");
 		goto error;
 	}
-
-	/* write padding '\0' if necessary */
-	if (pad_cnt && !fwrite(pad_bytes, pad_cnt, 1, fp)) {
-		warn("jvmti: cannot write dumpfile header padding");
-		goto error;
-	}
-
 	return fp;
 error:
 	fclose(fp);
@@ -349,7 +332,6 @@ jvmti_write_code(void *agent, char const *sym,
 	static int code_generation = 1;
 	struct jr_code_load rec;
 	size_t sym_len;
-	size_t padding_count;
 	FILE *fp = agent;
 	int ret = -1;
 
@@ -366,8 +348,6 @@ jvmti_write_code(void *agent, char const *sym,
 
 	rec.p.id           = JIT_CODE_LOAD;
 	rec.p.total_size   = sizeof(rec) + sym_len;
-	padding_count      = PADDING_8ALIGNED(rec.p.total_size);
-	rec.p. total_size += padding_count;
 	rec.p.timestamp    = perf_get_timestamp();
 
 	rec.code_size  = size;
@@ -393,9 +373,6 @@ jvmti_write_code(void *agent, char const *sym,
 	ret = fwrite_unlocked(&rec, sizeof(rec), 1, fp);
 	fwrite_unlocked(sym, sym_len, 1, fp);
 
-	if (padding_count)
-		fwrite_unlocked(pad_bytes, padding_count, 1, fp);
-
 	if (code)
 		fwrite_unlocked(code, size, 1, fp);
 
@@ -412,7 +389,6 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
 {
 	struct jr_code_debug_info rec;
 	size_t sret, len, size, flen;
-	size_t padding_count;
 	uint64_t addr;
 	const char *fn = file;
 	FILE *fp = agent;
@@ -443,16 +419,10 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
 	 * int      : line number
 	 * int      : column discriminator
 	 * file[]   : source file name
-	 * padding  : pad to multiple of 8 bytes
 	 */
 	size += nr_lines * sizeof(struct debug_entry);
 	size += flen * nr_lines;
-	/*
-	 * pad to 8 bytes
-	 */
-	padding_count = PADDING_8ALIGNED(size);
-
-	rec.p.total_size = size + padding_count;
+	rec.p.total_size = size;
 
 	/*
 	 * If JVM is multi-threaded, nultiple concurrent calls to agent
@@ -486,12 +456,6 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
 		if (sret != 1)
 			goto error;
 	}
-	if (padding_count) {
-		sret = fwrite_unlocked(pad_bytes, padding_count, 1, fp);
-		if (sret != 1)
-			goto error;
-	}
-
 	funlockfile(fp);
 	return 0;
 error:

[toc] | [prev] | [next] | [standalone]


#1500173 — [PATCH 6/9] perf/jit: add unwinding support

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 6/9] perf/jit: add unwinding support
Message-ID<srM3E-2I3-49@gated-at.bofh.it>
In reply to#1500165
From: Stefano Sanfilippo <ssanfilippo@chromium.org>

This record is intended to provide unwinding information in the
eh_frame format. This is required to unwind JITed code which
does not maintain the frame pointer register during function calls.

The eh_frame unwinding information can be emitted by V8 / Chromium
when the --perf_prof_unwinding_info is passed.

A record of type jr_code_unwinding_info comes before the jr_code_load
it referred to and contains both the .eh_frame and .eh_frame_hdr.

The fields in the header have the following meaning:

  * unwinding_size: size of the eh_frame and eh_frame_hdr, necessary
    for distinguishing the content from the padding.

  * eh_frame_hdr_size: as the name says.

  * mapped_size: size of the payload that was in memory at runtime.
    typically unwinding_size if the .eh_frame_hdr and .eh_frame were
    mapped, or 0 if they weren't. It should always be the former case,
    since the .eh_frame is guaranteed to be mapped in memory. However,
    certain JITs might want to inject an .eh_frame_hdr with an empty LUT
    to trigger fp-based unwinding fallback in libunwind. The only part
    of the .eh_frame_hdr that libunwind reads from remote memory is the
    LUT, and since there is none, mapping the unwinding info in memory
    is not necessary, and 0 in this field signifies that it wasn't.
    This practical hack allows to save bytes in code memory for those
    JIT compilers that might or might not maintain a valid frame pointer.

The payload that follows is assumed to contain first the .eh_frame and
then the .eh_header_hdr, with no padding between the two.

Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org>
Signed-off-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/util/jitdump.c | 57 ++++++++++++++++++++++++++++++++++++++++++++---
 tools/perf/util/jitdump.h | 12 ++++++++++
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 5db2feb90060..fdddeca26545 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -37,6 +37,10 @@ struct jit_buf_desc {
 	bool		 needs_bswap; /* handles cross-endianess */
 	bool		 use_arch_timestamp;
 	void		 *debug_data;
+	void		 *unwinding_data;
+	uint64_t	 unwinding_size;
+	uint64_t	 unwinding_mapped_size;
+	uint64_t         eh_frame_hdr_size;
 	size_t		 nr_debug_entries;
 	uint32_t         code_load_count;
 	u64		 bytes_written;
@@ -295,6 +299,13 @@ jit_get_next_entry(struct jit_buf_desc *jd)
 			}
 		}
 		break;
+	case JIT_CODE_UNWINDING_INFO:
+		if (jd->needs_bswap) {
+			jr->unwinding.unwinding_size = bswap_64(jr->unwinding.unwinding_size);
+			jr->unwinding.eh_frame_hdr_size = bswap_64(jr->unwinding.eh_frame_hdr_size);
+			jr->unwinding.mapped_size = bswap_64(jr->unwinding.mapped_size);
+		}
+		break;
 	case JIT_CODE_CLOSE:
 		break;
 	case JIT_CODE_LOAD:
@@ -370,7 +381,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 	u16 idr_size;
 	const char *sym;
 	uint32_t count;
-	int ret, csize;
+	int ret, csize, usize;
 	pid_t pid, tid;
 	struct {
 		u32 pid, tid;
@@ -380,6 +391,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 	pid   = jr->load.pid;
 	tid   = jr->load.tid;
 	csize = jr->load.code_size;
+	usize = jd->unwinding_mapped_size;
 	addr  = jr->load.code_addr;
 	sym   = (void *)((unsigned long)jr + sizeof(jr->load));
 	code  = (unsigned long)jr + jr->load.p.total_size - csize;
@@ -408,6 +420,14 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		jd->nr_debug_entries = 0;
 	}
 
+	if (jd->unwinding_data && jd->eh_frame_hdr_size) {
+		free(jd->unwinding_data);
+		jd->unwinding_data = NULL;
+		jd->eh_frame_hdr_size = 0;
+		jd->unwinding_mapped_size = 0;
+		jd->unwinding_size = 0;
+	}
+
 	if (ret) {
 		free(event);
 		return -1;
@@ -422,7 +442,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 
 	event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
 	event->mmap2.start = addr;
-	event->mmap2.len   = csize;
+	event->mmap2.len   = usize ? ALIGN_8(csize) + usize : csize;
 	event->mmap2.pid   = pid;
 	event->mmap2.tid   = tid;
 	event->mmap2.ino   = st.st_ino;
@@ -473,6 +493,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 	char *filename;
 	size_t size;
 	struct stat st;
+	int usize;
 	u16 idr_size;
 	int ret;
 	pid_t pid, tid;
@@ -483,6 +504,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 
 	pid = jr->move.pid;
 	tid =  jr->move.tid;
+	usize = jd->unwinding_mapped_size;
 	idr_size = jd->machine->id_hdr_size;
 
 	/*
@@ -511,7 +533,8 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 			(sizeof(event->mmap2.filename) - size) + idr_size);
 	event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
 	event->mmap2.start = jr->move.new_code_addr;
-	event->mmap2.len   = jr->move.code_size;
+	event->mmap2.len   = usize ? ALIGN_8(jr->move.code_size) + usize
+				   : jr->move.code_size;
 	event->mmap2.pid   = pid;
 	event->mmap2.tid   = tid;
 	event->mmap2.ino   = st.st_ino;
@@ -578,6 +601,31 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)
 }
 
 static int
+jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)
+{
+	void *unwinding_data;
+	uint32_t unwinding_data_size;
+
+	if (!(jd && jr))
+		return -1;
+
+	unwinding_data_size  = jr->prefix.total_size - sizeof(jr->unwinding);
+	unwinding_data = malloc(unwinding_data_size);
+	if (!unwinding_data)
+		return -1;
+
+	memcpy(unwinding_data, &jr->unwinding.unwinding_data,
+	       unwinding_data_size);
+
+	jd->eh_frame_hdr_size = jr->unwinding.eh_frame_hdr_size;
+	jd->unwinding_size = jr->unwinding.unwinding_size;
+	jd->unwinding_mapped_size = jr->unwinding.mapped_size;
+	jd->unwinding_data = unwinding_data;
+
+	return 0;
+}
+
+static int
 jit_process_dump(struct jit_buf_desc *jd)
 {
 	union jr_entry *jr;
@@ -594,6 +642,9 @@ jit_process_dump(struct jit_buf_desc *jd)
 		case JIT_CODE_DEBUG_INFO:
 			ret = jit_repipe_debug_info(jd, jr);
 			break;
+		case JIT_CODE_UNWINDING_INFO:
+			ret = jit_repipe_unwinding_info(jd, jr);
+			break;
 		default:
 			ret = 0;
 			continue;
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index bcacd20d0c1c..c6b9b67f43bf 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -19,6 +19,7 @@
 #define JITHEADER_MAGIC_SW	0x4454694A
 
 #define PADDING_8ALIGNED(x) ((((x) + 7) & 7) ^ 7)
+#define ALIGN_8(x) (((x) + 7) & (~7))
 
 #define JITHEADER_VERSION 1
 
@@ -48,6 +49,7 @@ enum jit_record_type {
         JIT_CODE_MOVE           = 1,
 	JIT_CODE_DEBUG_INFO	= 2,
 	JIT_CODE_CLOSE		= 3,
+	JIT_CODE_UNWINDING_INFO	= 4,
 
 	JIT_CODE_MAX,
 };
@@ -101,12 +103,22 @@ struct jr_code_debug_info {
 	struct debug_entry entries[0];
 };
 
+struct jr_code_unwinding_info {
+	struct jr_prefix p;
+
+	uint64_t unwinding_size;
+	uint64_t eh_frame_hdr_size;
+	uint64_t mapped_size;
+	const char unwinding_data[0];
+};
+
 union jr_entry {
         struct jr_code_debug_info info;
         struct jr_code_close close;
         struct jr_code_load load;
         struct jr_code_move move;
         struct jr_prefix prefix;
+        struct jr_code_unwinding_info unwinding;
 };
 
 static inline struct debug_entry *
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1507621 — [tip:perf/core] perf jit: Add unwinding support

Fromtip-bot for Stefano Sanfilippo <tipbot@zytor.com>
Date2016-10-24 21:10 +0200
Subject[tip:perf/core] perf jit: Add unwinding support
Message-ID<svSNb-3nI-27@gated-at.bofh.it>
In reply to#1500173
Commit-ID:  0284fecd13b6db3ecd4c2b1bf3e72b105edce24b
Gitweb:     http://git.kernel.org/tip/0284fecd13b6db3ecd4c2b1bf3e72b105edce24b
Author:     Stefano Sanfilippo <ssanfilippo@chromium.org>
AuthorDate: Thu, 13 Oct 2016 03:59:40 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 24 Oct 2016 11:07:39 -0300

perf jit: Add unwinding support

This record is intended to provide unwinding information in the
eh_frame format. This is required to unwind JITed code which
does not maintain the frame pointer register during function calls.

The eh_frame unwinding information can be emitted by V8 / Chromium
when the --perf_prof_unwinding_info is passed.

A record of type jr_code_unwinding_info comes before the jr_code_load
it referred to and contains both the .eh_frame and .eh_frame_hdr.

The fields in the header have the following meaning:

  * unwinding_size: size of the eh_frame and eh_frame_hdr, necessary
    for distinguishing the content from the padding.

  * eh_frame_hdr_size: as the name says.

  * mapped_size: size of the payload that was in memory at runtime.
    typically unwinding_size if the .eh_frame_hdr and .eh_frame were
    mapped, or 0 if they weren't. It should always be the former case,
    since the .eh_frame is guaranteed to be mapped in memory. However,
    certain JITs might want to inject an .eh_frame_hdr with an empty LUT
    to trigger fp-based unwinding fallback in libunwind. The only part
    of the .eh_frame_hdr that libunwind reads from remote memory is the
    LUT, and since there is none, mapping the unwinding info in memory
    is not necessary, and 0 in this field signifies that it wasn't.
    This practical hack allows to save bytes in code memory for those
    JIT compilers that might or might not maintain a valid frame pointer.

The payload that follows is assumed to contain first the .eh_frame and
then the .eh_header_hdr, with no padding between the two.

Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org>
Signed-off-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Stephane Eranian <eranian@google.com>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1476356383-30100-7-git-send-email-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/jitdump.c | 57 ++++++++++++++++++++++++++++++++++++++++++++---
 tools/perf/util/jitdump.h | 12 ++++++++++
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 75b66bb..9bae66c 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -37,6 +37,10 @@ struct jit_buf_desc {
 	bool		 needs_bswap; /* handles cross-endianess */
 	bool		 use_arch_timestamp;
 	void		 *debug_data;
+	void		 *unwinding_data;
+	uint64_t	 unwinding_size;
+	uint64_t	 unwinding_mapped_size;
+	uint64_t         eh_frame_hdr_size;
 	size_t		 nr_debug_entries;
 	uint32_t         code_load_count;
 	u64		 bytes_written;
@@ -295,6 +299,13 @@ jit_get_next_entry(struct jit_buf_desc *jd)
 			}
 		}
 		break;
+	case JIT_CODE_UNWINDING_INFO:
+		if (jd->needs_bswap) {
+			jr->unwinding.unwinding_size = bswap_64(jr->unwinding.unwinding_size);
+			jr->unwinding.eh_frame_hdr_size = bswap_64(jr->unwinding.eh_frame_hdr_size);
+			jr->unwinding.mapped_size = bswap_64(jr->unwinding.mapped_size);
+		}
+		break;
 	case JIT_CODE_CLOSE:
 		break;
 	case JIT_CODE_LOAD:
@@ -370,7 +381,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 	u16 idr_size;
 	const char *sym;
 	uint32_t count;
-	int ret, csize;
+	int ret, csize, usize;
 	pid_t pid, tid;
 	struct {
 		u32 pid, tid;
@@ -380,6 +391,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 	pid   = jr->load.pid;
 	tid   = jr->load.tid;
 	csize = jr->load.code_size;
+	usize = jd->unwinding_mapped_size;
 	addr  = jr->load.code_addr;
 	sym   = (void *)((unsigned long)jr + sizeof(jr->load));
 	code  = (unsigned long)jr + jr->load.p.total_size - csize;
@@ -408,6 +420,14 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		jd->nr_debug_entries = 0;
 	}
 
+	if (jd->unwinding_data && jd->eh_frame_hdr_size) {
+		free(jd->unwinding_data);
+		jd->unwinding_data = NULL;
+		jd->eh_frame_hdr_size = 0;
+		jd->unwinding_mapped_size = 0;
+		jd->unwinding_size = 0;
+	}
+
 	if (ret) {
 		free(event);
 		return -1;
@@ -422,7 +442,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 
 	event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
 	event->mmap2.start = addr;
-	event->mmap2.len   = csize;
+	event->mmap2.len   = usize ? ALIGN_8(csize) + usize : csize;
 	event->mmap2.pid   = pid;
 	event->mmap2.tid   = tid;
 	event->mmap2.ino   = st.st_ino;
@@ -473,6 +493,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 	char *filename;
 	size_t size;
 	struct stat st;
+	int usize;
 	u16 idr_size;
 	int ret;
 	pid_t pid, tid;
@@ -483,6 +504,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 
 	pid = jr->move.pid;
 	tid =  jr->move.tid;
+	usize = jd->unwinding_mapped_size;
 	idr_size = jd->machine->id_hdr_size;
 
 	/*
@@ -511,7 +533,8 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 			(sizeof(event->mmap2.filename) - size) + idr_size);
 	event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
 	event->mmap2.start = jr->move.new_code_addr;
-	event->mmap2.len   = jr->move.code_size;
+	event->mmap2.len   = usize ? ALIGN_8(jr->move.code_size) + usize
+				   : jr->move.code_size;
 	event->mmap2.pid   = pid;
 	event->mmap2.tid   = tid;
 	event->mmap2.ino   = st.st_ino;
@@ -578,6 +601,31 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)
 }
 
 static int
+jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)
+{
+	void *unwinding_data;
+	uint32_t unwinding_data_size;
+
+	if (!(jd && jr))
+		return -1;
+
+	unwinding_data_size  = jr->prefix.total_size - sizeof(jr->unwinding);
+	unwinding_data = malloc(unwinding_data_size);
+	if (!unwinding_data)
+		return -1;
+
+	memcpy(unwinding_data, &jr->unwinding.unwinding_data,
+	       unwinding_data_size);
+
+	jd->eh_frame_hdr_size = jr->unwinding.eh_frame_hdr_size;
+	jd->unwinding_size = jr->unwinding.unwinding_size;
+	jd->unwinding_mapped_size = jr->unwinding.mapped_size;
+	jd->unwinding_data = unwinding_data;
+
+	return 0;
+}
+
+static int
 jit_process_dump(struct jit_buf_desc *jd)
 {
 	union jr_entry *jr;
@@ -594,6 +642,9 @@ jit_process_dump(struct jit_buf_desc *jd)
 		case JIT_CODE_DEBUG_INFO:
 			ret = jit_repipe_debug_info(jd, jr);
 			break;
+		case JIT_CODE_UNWINDING_INFO:
+			ret = jit_repipe_unwinding_info(jd, jr);
+			break;
 		default:
 			ret = 0;
 			continue;
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index bcacd20..c6b9b67 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -19,6 +19,7 @@
 #define JITHEADER_MAGIC_SW	0x4454694A
 
 #define PADDING_8ALIGNED(x) ((((x) + 7) & 7) ^ 7)
+#define ALIGN_8(x) (((x) + 7) & (~7))
 
 #define JITHEADER_VERSION 1
 
@@ -48,6 +49,7 @@ enum jit_record_type {
         JIT_CODE_MOVE           = 1,
 	JIT_CODE_DEBUG_INFO	= 2,
 	JIT_CODE_CLOSE		= 3,
+	JIT_CODE_UNWINDING_INFO	= 4,
 
 	JIT_CODE_MAX,
 };
@@ -101,12 +103,22 @@ struct jr_code_debug_info {
 	struct debug_entry entries[0];
 };
 
+struct jr_code_unwinding_info {
+	struct jr_prefix p;
+
+	uint64_t unwinding_size;
+	uint64_t eh_frame_hdr_size;
+	uint64_t mapped_size;
+	const char unwinding_data[0];
+};
+
 union jr_entry {
         struct jr_code_debug_info info;
         struct jr_code_close close;
         struct jr_code_load load;
         struct jr_code_move move;
         struct jr_prefix prefix;
+        struct jr_code_unwinding_info unwinding;
 };
 
 static inline struct debug_entry *

[toc] | [prev] | [next] | [standalone]


#1500175 — [PATCH 2/9] perf/jit: enable jitdump support without dwarf

FromStephane Eranian <eranian@google.com>
Date2016-10-13 13:10 +0200
Subject[PATCH 2/9] perf/jit: enable jitdump support without dwarf
Message-ID<srM3E-2I3-51@gated-at.bofh.it>
In reply to#1500165
From: Maciej Debski <maciejd@google.com>

This patch modifies the build dependencies on the jitdump
support in perf. As it stands jitdump was wrongfully made dependent
100% on using DWARF. However, the dwarf dependency, only exist if
generating the source line table in genelf_debug.c. The rest of the
support does not need DWARF.

This patch removes the dependency on DWARF for the entire jitdump
support. It keeps it only for the genelf_debug.c support.

Signed-off-by: Maciej Debski <maciejd@google.com>
Reviewed-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/Makefile.config | 2 --
 tools/perf/util/Build      | 2 +-
 tools/perf/util/genelf.c   | 9 +++++++--
 tools/perf/util/genelf.h   | 2 ++
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 72edf83d76b7..8cfc310d4358 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -366,10 +366,8 @@ ifndef NO_SDT
 endif
 
 ifdef PERF_HAVE_JITDUMP
-  ifndef NO_DWARF
     $(call detected,CONFIG_JITDUMP)
     CFLAGS += -DHAVE_JITDUMP
-  endif
 endif
 
 ifeq ($(ARCH),powerpc)
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index eb60e613d795..1dc67efad634 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -120,7 +120,7 @@ libperf-y += demangle-rust.o
 ifdef CONFIG_JITDUMP
 libperf-$(CONFIG_LIBELF) += jitdump.o
 libperf-$(CONFIG_LIBELF) += genelf.o
-libperf-$(CONFIG_LIBELF) += genelf_debug.o
+libperf-$(CONFIG_DWARF) += genelf_debug.o
 endif
 
 CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
index c1ef805c6a8f..14a73acc549c 100644
--- a/tools/perf/util/genelf.c
+++ b/tools/perf/util/genelf.c
@@ -19,7 +19,9 @@
 #include <limits.h>
 #include <fcntl.h>
 #include <err.h>
+#ifdef HAVE_DWARF_SUPPORT
 #include <dwarf.h>
+#endif
 
 #include "perf.h"
 #include "genelf.h"
@@ -157,7 +159,7 @@ gen_build_id(struct buildid_note *note, unsigned long load_addr, const void *cod
 int
 jit_write_elf(int fd, uint64_t load_addr, const char *sym,
 	      const void *code, int csize,
-	      void *debug, int nr_debug_entries)
+	      void *debug __maybe_unused, int nr_debug_entries __maybe_unused)
 {
 	Elf *e;
 	Elf_Data *d;
@@ -386,11 +388,14 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
 	shdr->sh_size = sizeof(bnote);
 	shdr->sh_entsize = 0;
 
+#ifdef HAVE_DWARF_SUPPORT
 	if (debug && nr_debug_entries) {
 		retval = jit_add_debug_info(e, load_addr, debug, nr_debug_entries);
 		if (retval)
 			goto error;
-	} else {
+	} else
+#endif
+	{
 		if (elf_update(e, ELF_C_WRITE) < 0) {
 			warnx("elf_update 4 failed");
 			goto error;
diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
index 2fbeb59c4bdd..5c933ac71451 100644
--- a/tools/perf/util/genelf.h
+++ b/tools/perf/util/genelf.h
@@ -4,8 +4,10 @@
 /* genelf.c */
 int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
 		  const void *code, int csize, void *debug, int nr_debug_entries);
+#ifdef HAVE_DWARF_SUPPORT
 /* genelf_debug.c */
 int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
+#endif
 
 #if   defined(__arm__)
 #define GEN_ELF_ARCH	EM_ARM
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1500492 — Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-13 20:20 +0200
SubjectRe: [PATCH 2/9] perf/jit: enable jitdump support without dwarf
Message-ID<srSLM-78p-15@gated-at.bofh.it>
In reply to#1500175
Em Thu, Oct 13, 2016 at 03:59:36AM -0700, Stephane Eranian escreveu:
> From: Maciej Debski <maciejd@google.com>
> 
> This patch modifies the build dependencies on the jitdump
> support in perf. As it stands jitdump was wrongfully made dependent
> 100% on using DWARF. However, the dwarf dependency, only exist if
> generating the source line table in genelf_debug.c. The rest of the
> support does not need DWARF.
> 
> This patch removes the dependency on DWARF for the entire jitdump
> support. It keeps it only for the genelf_debug.c support.

Please add a:

Fixes: e12b202f8fb9 ("perf jitdump: Build only on supported archs")

Next time, so that scripts can pick patches for stable kernels, etc.

Adding it this time.

Thanks,

- Arnaldo

 
> Signed-off-by: Maciej Debski <maciejd@google.com>
> Reviewed-by: Stephane Eranian <eranian@google.com>
> ---
>  tools/perf/Makefile.config | 2 --
>  tools/perf/util/Build      | 2 +-
>  tools/perf/util/genelf.c   | 9 +++++++--
>  tools/perf/util/genelf.h   | 2 ++
>  4 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 72edf83d76b7..8cfc310d4358 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -366,10 +366,8 @@ ifndef NO_SDT
>  endif
>  
>  ifdef PERF_HAVE_JITDUMP
> -  ifndef NO_DWARF
>      $(call detected,CONFIG_JITDUMP)
>      CFLAGS += -DHAVE_JITDUMP
> -  endif
>  endif
>  
>  ifeq ($(ARCH),powerpc)
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index eb60e613d795..1dc67efad634 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -120,7 +120,7 @@ libperf-y += demangle-rust.o
>  ifdef CONFIG_JITDUMP
>  libperf-$(CONFIG_LIBELF) += jitdump.o
>  libperf-$(CONFIG_LIBELF) += genelf.o
> -libperf-$(CONFIG_LIBELF) += genelf_debug.o
> +libperf-$(CONFIG_DWARF) += genelf_debug.o
>  endif
>  
>  CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
> diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
> index c1ef805c6a8f..14a73acc549c 100644
> --- a/tools/perf/util/genelf.c
> +++ b/tools/perf/util/genelf.c
> @@ -19,7 +19,9 @@
>  #include <limits.h>
>  #include <fcntl.h>
>  #include <err.h>
> +#ifdef HAVE_DWARF_SUPPORT
>  #include <dwarf.h>
> +#endif
>  
>  #include "perf.h"
>  #include "genelf.h"
> @@ -157,7 +159,7 @@ gen_build_id(struct buildid_note *note, unsigned long load_addr, const void *cod
>  int
>  jit_write_elf(int fd, uint64_t load_addr, const char *sym,
>  	      const void *code, int csize,
> -	      void *debug, int nr_debug_entries)
> +	      void *debug __maybe_unused, int nr_debug_entries __maybe_unused)
>  {
>  	Elf *e;
>  	Elf_Data *d;
> @@ -386,11 +388,14 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
>  	shdr->sh_size = sizeof(bnote);
>  	shdr->sh_entsize = 0;
>  
> +#ifdef HAVE_DWARF_SUPPORT
>  	if (debug && nr_debug_entries) {
>  		retval = jit_add_debug_info(e, load_addr, debug, nr_debug_entries);
>  		if (retval)
>  			goto error;
> -	} else {
> +	} else
> +#endif
> +	{
>  		if (elf_update(e, ELF_C_WRITE) < 0) {
>  			warnx("elf_update 4 failed");
>  			goto error;
> diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
> index 2fbeb59c4bdd..5c933ac71451 100644
> --- a/tools/perf/util/genelf.h
> +++ b/tools/perf/util/genelf.h
> @@ -4,8 +4,10 @@
>  /* genelf.c */
>  int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
>  		  const void *code, int csize, void *debug, int nr_debug_entries);
> +#ifdef HAVE_DWARF_SUPPORT
>  /* genelf_debug.c */
>  int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
> +#endif
>  
>  #if   defined(__arm__)
>  #define GEN_ELF_ARCH	EM_ARM
> -- 
> 1.9.1

[toc] | [prev] | [next] | [standalone]


#1500500 — Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-13 21:00 +0200
SubjectRe: [PATCH 2/9] perf/jit: enable jitdump support without dwarf
Message-ID<srTot-7lC-5@gated-at.bofh.it>
In reply to#1500492
Em Thu, Oct 13, 2016 at 03:37:42PM -0300, Arnaldo Carvalho de Melo escreveu:
> I'm trying to figure this out...

So, building with:

make -C tools/perf LDFLAGS=-static O=/tmp/build/perf install-bin

I get:

[acme@jouet linux]$ grep libelf /tmp/build/perf/FEATURE-DUMP 
feature-libelf=0
feature-libelf-getphdrnum=0
feature-libelf-gelf_getnote=0
feature-libelf-getshdrstrndx=0
feature-libelf-mmap=0
[acme@jouet linux]$

And jitdump is only linked if:

[acme@jouet linux]$ grep jitdump tools/perf/*/Build
tools/perf/util/Build:libperf-$(CONFIG_LIBELF) += jitdump.o
[acme@jouet linux]$ 

But:

#ifdef HAVE_JITDUMP
static int perf_event__jit_repipe_mmap(struct perf_tool *tool,
.
.
.
        ret = jit_process(inject->session, &inject->output, machine,
                          event->mmap.filename, sample->pid, &n);
.
.
.
#endif

So we need:

[acme@jouet linux]$ git diff
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 8cfc310d4358..cffdd9cf3ebf 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -366,8 +366,10 @@ ifndef NO_SDT
 endif
 
 ifdef PERF_HAVE_JITDUMP
+  ifndef NO_LIBELF
     $(call detected,CONFIG_JITDUMP)
     CFLAGS += -DHAVE_JITDUMP
+  endif
 endif
 
 ifeq ($(ARCH),powerpc)
[acme@jouet linux]$ 

To get that fixed.

Please let me know if this suits your needs.

I'll now try building with elfutils static libraries to see if in that case it
all gets linked.

- Arnaldo

[toc] | [prev] | [next] | [standalone]


#1500508 — Re: [PATCH 2/9] perf/jit: enable jitdump support without dwarf

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-13 21:20 +0200
SubjectRe: [PATCH 2/9] perf/jit: enable jitdump support without dwarf
Message-ID<srTHQ-7Il-19@gated-at.bofh.it>
In reply to#1500500
Em Thu, Oct 13, 2016 at 03:51:35PM -0300, Arnaldo Carvalho de Melo escreveu:
> So we need:
> 
> [acme@jouet linux]$ git diff
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 8cfc310d4358..cffdd9cf3ebf 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -366,8 +366,10 @@ ifndef NO_SDT
>  endif
>  
>  ifdef PERF_HAVE_JITDUMP
> +  ifndef NO_LIBELF
>      $(call detected,CONFIG_JITDUMP)
>      CFLAGS += -DHAVE_JITDUMP
> +  endif
>  endif
>  
>  ifeq ($(ARCH),powerpc)
> [acme@jouet linux]$ 
> 
> To get that fixed.
> 
> Please let me know if this suits your needs.
> 
> I'll now try building with elfutils static libraries to see if in that case it
> all gets linked.

After installing these packages, on fedora, i.e. installing what is
needed to statically link against libelf:

  elfutils-devel-static
  elfutils-libelf-devel-static
  zlib-static

Then it all works, libelf is statically linked and we also statically
link the jitdump code:

  $ make -C tools/perf LDFLAGS=-static O=/tmp/build/perf install-bin
  $ grep libelf /tmp/build/perf/FEATURE-DUMP 
  feature-libelf=1
  feature-libelf-getphdrnum=1
  feature-libelf-gelf_getnote=1
  feature-libelf-getshdrstrndx=1
  feature-libelf-mmap=1
  $
  
And:

[acme@jouet linux]$ size /tmp/build/perf/perf
   text	   data	    bss	    dec	    hex	filename
4478822	 581702	23919240	28979764	1ba3234	/tmp/build/perf/perf
[acme@jouet linux]$ 
[acme@jouet linux]$ file /tmp/build/perf/perf
/tmp/build/perf/perf: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=c2950590a0f24d76baa0ce4896414e5d523fefba, not stripped
[acme@jouet linux]$ 
[acme@jouet linux]$ nm /tmp/build/perf/perf | grep jit
00000000005007f0 T jit_process
0000000000501920 T jit_write_elf
0000000000431a50 t perf_event__jit_repipe_mmap
0000000000431b20 t perf_event__jit_repipe_mmap2
[acme@jouet linux]$ 

- Arnaldo

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | linux.kernel


csiph-web