2016-04-01 03:54:27

by He Kuang

[permalink] [raw]
Subject: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86

Build errors on aarch64:

libperf.a(libperf-in.o): In function `convert_timestamp':
util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
collect2: error: ld returned 1 exit status
Makefile.perf:347: recipe for target 'perf' failed
make[1]: *** [perf] Error 1
Makefile:68: recipe for target 'all' failed
make: *** [all] Error 2

Since tsc conversion functions were moved out from arch dir, move
'tsc.h' out from x86 dir to make it possible to compile for other archs.

Signed-off-by: He Kuang <[email protected]>
---
tools/perf/arch/x86/util/tsc.c | 1 -
tools/perf/arch/x86/util/tsc.h | 17 -----------------
tools/perf/util/Build | 3 +--
tools/perf/util/tsc.h | 11 ++++++++++-
4 files changed, 11 insertions(+), 21 deletions(-)
delete mode 100644 tools/perf/arch/x86/util/tsc.h

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 70ff7c1..357f1b1 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -7,7 +7,6 @@
#include <linux/types.h>
#include "../../util/debug.h"
#include "../../util/tsc.h"
-#include "tsc.h"

int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
struct perf_tsc_conversion *tc)
diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
deleted file mode 100644
index 2edc4d3..0000000
--- a/tools/perf/arch/x86/util/tsc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-
-#include <linux/types.h>
-
-struct perf_tsc_conversion {
- u16 time_shift;
- u32 time_mult;
- u64 time_zero;
-};
-
-struct perf_event_mmap_page;
-
-int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
- struct perf_tsc_conversion *tc);
-
-#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index da48fd8..85ceff3 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
libperf-y += record.o
libperf-y += srcline.o
libperf-y += data.o
-libperf-$(CONFIG_X86) += tsc.o
-libperf-$(CONFIG_AUXTRACE) += tsc.o
+libperf-y += tsc.o
libperf-y += cloexec.o
libperf-y += thread-stack.o
libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index 280ddc0..d5b11e2 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -4,7 +4,16 @@
#include <linux/types.h>

#include "event.h"
-#include "../arch/x86/util/tsc.h"
+
+struct perf_tsc_conversion {
+ u16 time_shift;
+ u32 time_mult;
+ u64 time_zero;
+};
+struct perf_event_mmap_page;
+
+int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
+ struct perf_tsc_conversion *tc);

u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
--
1.8.5.2


2016-04-01 07:17:26

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86

On 01/04/16 06:49, He Kuang wrote:
> Build errors on aarch64:
>
> libperf.a(libperf-in.o): In function `convert_timestamp':
> util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
> collect2: error: ld returned 1 exit status
> Makefile.perf:347: recipe for target 'perf' failed
> make[1]: *** [perf] Error 1
> Makefile:68: recipe for target 'all' failed
> make: *** [all] Error 2

Sorry about that :-(

>
> Since tsc conversion functions were moved out from arch dir, move
> 'tsc.h' out from x86 dir to make it possible to compile for other archs.

So this is the case where data can be collected on x86 and then processed on
another arch.

Originally, it wasn't wanted to be compiled in:

http://marc.info/?l=linux-kernel&m=142445842131011

But that has been causing problems:

http://marc.info/?l=linux-kernel&m=144109627003194

So this seems better.

>
> Signed-off-by: He Kuang <[email protected]>

Acked-by: Adrian Hunter <[email protected]>

> ---
> tools/perf/arch/x86/util/tsc.c | 1 -
> tools/perf/arch/x86/util/tsc.h | 17 -----------------
> tools/perf/util/Build | 3 +--
> tools/perf/util/tsc.h | 11 ++++++++++-
> 4 files changed, 11 insertions(+), 21 deletions(-)
> delete mode 100644 tools/perf/arch/x86/util/tsc.h
>
> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
> index 70ff7c1..357f1b1 100644
> --- a/tools/perf/arch/x86/util/tsc.c
> +++ b/tools/perf/arch/x86/util/tsc.c
> @@ -7,7 +7,6 @@
> #include <linux/types.h>
> #include "../../util/debug.h"
> #include "../../util/tsc.h"
> -#include "tsc.h"
>
> int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> struct perf_tsc_conversion *tc)
> diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
> deleted file mode 100644
> index 2edc4d3..0000000
> --- a/tools/perf/arch/x86/util/tsc.h
> +++ /dev/null
> @@ -1,17 +0,0 @@
> -#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -
> -#include <linux/types.h>
> -
> -struct perf_tsc_conversion {
> - u16 time_shift;
> - u32 time_mult;
> - u64 time_zero;
> -};
> -
> -struct perf_event_mmap_page;
> -
> -int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> - struct perf_tsc_conversion *tc);
> -
> -#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index da48fd8..85ceff3 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
> libperf-y += record.o
> libperf-y += srcline.o
> libperf-y += data.o
> -libperf-$(CONFIG_X86) += tsc.o
> -libperf-$(CONFIG_AUXTRACE) += tsc.o
> +libperf-y += tsc.o
> libperf-y += cloexec.o
> libperf-y += thread-stack.o
> libperf-$(CONFIG_AUXTRACE) += auxtrace.o
> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
> index 280ddc0..d5b11e2 100644
> --- a/tools/perf/util/tsc.h
> +++ b/tools/perf/util/tsc.h
> @@ -4,7 +4,16 @@
> #include <linux/types.h>
>
> #include "event.h"
> -#include "../arch/x86/util/tsc.h"
> +
> +struct perf_tsc_conversion {
> + u16 time_shift;
> + u32 time_mult;
> + u64 time_zero;
> +};
> +struct perf_event_mmap_page;
> +
> +int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> + struct perf_tsc_conversion *tc);
>
> u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
> u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
>

2016-04-01 13:13:20

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86

Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
> Build errors on aarch64:
>
> libperf.a(libperf-in.o): In function `convert_timestamp':
> util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
> collect2: error: ld returned 1 exit status
> Makefile.perf:347: recipe for target 'perf' failed
> make[1]: *** [perf] Error 1
> Makefile:68: recipe for target 'all' failed
> make: *** [all] Error 2

Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
because it needs a package I haven't found in ubuntu:

config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
minimal-ubuntu-x-arm64: Ok

BTW, He, what environment do you use to build for arm64, is it a cross
compile one? Yocto?

- Arnaldo



> Since tsc conversion functions were moved out from arch dir, move
> 'tsc.h' out from x86 dir to make it possible to compile for other archs.
>
> Signed-off-by: He Kuang <[email protected]>
> ---
> tools/perf/arch/x86/util/tsc.c | 1 -
> tools/perf/arch/x86/util/tsc.h | 17 -----------------
> tools/perf/util/Build | 3 +--
> tools/perf/util/tsc.h | 11 ++++++++++-
> 4 files changed, 11 insertions(+), 21 deletions(-)
> delete mode 100644 tools/perf/arch/x86/util/tsc.h
>
> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
> index 70ff7c1..357f1b1 100644
> --- a/tools/perf/arch/x86/util/tsc.c
> +++ b/tools/perf/arch/x86/util/tsc.c
> @@ -7,7 +7,6 @@
> #include <linux/types.h>
> #include "../../util/debug.h"
> #include "../../util/tsc.h"
> -#include "tsc.h"
>
> int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> struct perf_tsc_conversion *tc)
> diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
> deleted file mode 100644
> index 2edc4d3..0000000
> --- a/tools/perf/arch/x86/util/tsc.h
> +++ /dev/null
> @@ -1,17 +0,0 @@
> -#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -
> -#include <linux/types.h>
> -
> -struct perf_tsc_conversion {
> - u16 time_shift;
> - u32 time_mult;
> - u64 time_zero;
> -};
> -
> -struct perf_event_mmap_page;
> -
> -int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> - struct perf_tsc_conversion *tc);
> -
> -#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index da48fd8..85ceff3 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
> libperf-y += record.o
> libperf-y += srcline.o
> libperf-y += data.o
> -libperf-$(CONFIG_X86) += tsc.o
> -libperf-$(CONFIG_AUXTRACE) += tsc.o
> +libperf-y += tsc.o
> libperf-y += cloexec.o
> libperf-y += thread-stack.o
> libperf-$(CONFIG_AUXTRACE) += auxtrace.o
> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
> index 280ddc0..d5b11e2 100644
> --- a/tools/perf/util/tsc.h
> +++ b/tools/perf/util/tsc.h
> @@ -4,7 +4,16 @@
> #include <linux/types.h>
>
> #include "event.h"
> -#include "../arch/x86/util/tsc.h"
> +
> +struct perf_tsc_conversion {
> + u16 time_shift;
> + u32 time_mult;
> + u64 time_zero;
> +};
> +struct perf_event_mmap_page;
> +
> +int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> + struct perf_tsc_conversion *tc);
>
> u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
> u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
> --
> 1.8.5.2

2016-04-01 13:22:30

by He Kuang

[permalink] [raw]
Subject: Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86


hi,
在 2016/4/1 21:13, Arnaldo Carvalho de Melo 写道:
> Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
>> Build errors on aarch64:
>>
>> libperf.a(libperf-in.o): In function `convert_timestamp':
>> util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
>> collect2: error: ld returned 1 exit status
>> Makefile.perf:347: recipe for target 'perf' failed
>> make[1]: *** [perf] Error 1
>> Makefile:68: recipe for target 'all' failed
>> make: *** [all] Error 2
> Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
> because it needs a package I haven't found in ubuntu:
>
> config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
> minimal-ubuntu-x-arm64: Ok
>
> BTW, He, what environment do you use to build for arm64, is it a cross
> compile one? Yocto?

I use buildroot, though my colleague prefers yocto(oxygen).

In my environment, libcrypto is on.
... libcrypto: [ on ]

>
> - Arnaldo
>
>
>
>> Since tsc conversion functions were moved out from arch dir, move
>> 'tsc.h' out from x86 dir to make it possible to compile for other archs.
>>
>> Signed-off-by: He Kuang <[email protected]>
>> ---
>> tools/perf/arch/x86/util/tsc.c | 1 -
>> tools/perf/arch/x86/util/tsc.h | 17 -----------------
>> tools/perf/util/Build | 3 +--
>> tools/perf/util/tsc.h | 11 ++++++++++-
>> 4 files changed, 11 insertions(+), 21 deletions(-)
>> delete mode 100644 tools/perf/arch/x86/util/tsc.h
>>
>> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
>> index 70ff7c1..357f1b1 100644
>> --- a/tools/perf/arch/x86/util/tsc.c
>> +++ b/tools/perf/arch/x86/util/tsc.c
>> @@ -7,7 +7,6 @@
>> #include <linux/types.h>
>> #include "../../util/debug.h"
>> #include "../../util/tsc.h"
>> -#include "tsc.h"
>>
>> int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>> struct perf_tsc_conversion *tc)
>> diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
>> deleted file mode 100644
>> index 2edc4d3..0000000
>> --- a/tools/perf/arch/x86/util/tsc.h
>> +++ /dev/null
>> @@ -1,17 +0,0 @@
>> -#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
>> -#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
>> -
>> -#include <linux/types.h>
>> -
>> -struct perf_tsc_conversion {
>> - u16 time_shift;
>> - u32 time_mult;
>> - u64 time_zero;
>> -};
>> -
>> -struct perf_event_mmap_page;
>> -
>> -int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>> - struct perf_tsc_conversion *tc);
>> -
>> -#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
>> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
>> index da48fd8..85ceff3 100644
>> --- a/tools/perf/util/Build
>> +++ b/tools/perf/util/Build
>> @@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
>> libperf-y += record.o
>> libperf-y += srcline.o
>> libperf-y += data.o
>> -libperf-$(CONFIG_X86) += tsc.o
>> -libperf-$(CONFIG_AUXTRACE) += tsc.o
>> +libperf-y += tsc.o
>> libperf-y += cloexec.o
>> libperf-y += thread-stack.o
>> libperf-$(CONFIG_AUXTRACE) += auxtrace.o
>> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
>> index 280ddc0..d5b11e2 100644
>> --- a/tools/perf/util/tsc.h
>> +++ b/tools/perf/util/tsc.h
>> @@ -4,7 +4,16 @@
>> #include <linux/types.h>
>>
>> #include "event.h"
>> -#include "../arch/x86/util/tsc.h"
>> +
>> +struct perf_tsc_conversion {
>> + u16 time_shift;
>> + u32 time_mult;
>> + u64 time_zero;
>> +};
>> +struct perf_event_mmap_page;
>> +
>> +int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>> + struct perf_tsc_conversion *tc);
>>
>> u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
>> u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
>> --
>> 1.8.5.2


2016-04-01 13:24:13

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86

Em Fri, Apr 01, 2016 at 10:13:12AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
> > Build errors on aarch64:
> >
> > libperf.a(libperf-in.o): In function `convert_timestamp':
> > util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
> > collect2: error: ld returned 1 exit status
> > Makefile.perf:347: recipe for target 'perf' failed
> > make[1]: *** [perf] Error 1
> > Makefile:68: recipe for target 'all' failed
> > make: *** [all] Error 2
>
> Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
> because it needs a package I haven't found in ubuntu:
>
> config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
> minimal-ubuntu-x-arm64: Ok
>
> BTW, He, what environment do you use to build for arm64, is it a cross
> compile one? Yocto?

Adrian, BTW, Ok with this? I'm adding a:

Fixes: d3e58a3b8b3b ("perf jit: Add support for using TSC as a timestamp")

And would appreciate your Acked-by.

Thanks,

- Arnaldo

2016-04-01 13:43:15

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86

On 01/04/16 16:24, Arnaldo Carvalho de Melo wrote:
> Em Fri, Apr 01, 2016 at 10:13:12AM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
>>> Build errors on aarch64:
>>>
>>> libperf.a(libperf-in.o): In function `convert_timestamp':
>>> util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
>>> collect2: error: ld returned 1 exit status
>>> Makefile.perf:347: recipe for target 'perf' failed
>>> make[1]: *** [perf] Error 1
>>> Makefile:68: recipe for target 'all' failed
>>> make: *** [all] Error 2
>>
>> Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
>> because it needs a package I haven't found in ubuntu:
>>
>> config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
>> minimal-ubuntu-x-arm64: Ok
>>
>> BTW, He, what environment do you use to build for arm64, is it a cross
>> compile one? Yocto?
>
> Adrian, BTW, Ok with this? I'm adding a:
>
> Fixes: d3e58a3b8b3b ("perf jit: Add support for using TSC as a timestamp")
>
> And would appreciate your Acked-by.

Sure, already did in http://marc.info/?l=linux-kernel&m=145949505329251

Acked-by: Adrian Hunter <[email protected]>

Subject: [tip:perf/core] perf jit: Add support for using TSC as a timestamp

Commit-ID: 2a28e23049af99e1c810111ef5e56455cafeda45
Gitweb: http://git.kernel.org/tip/2a28e23049af99e1c810111ef5e56455cafeda45
Author: Adrian Hunter <[email protected]>
AuthorDate: Tue, 8 Mar 2016 10:38:50 +0200
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Apr 2016 18:42:55 -0300

perf jit: Add support for using TSC as a timestamp

Intel PT uses TSC as a timestamp, so add support for using TSC instead
of the monotonic clock. Use of TSC is selected by an environment
variable "JITDUMP_USE_ARCH_TIMESTAMP" and flagged in the jitdump file
with flag JITDUMP_FLAGS_ARCH_TIMESTAMP.

Signed-off-by: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: He Kuang <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Sukadev Bhattiprolu <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
[ Added the fixup from He Kuang to make it build on other arches, ]
[ such as aarch64, to avoid inserting this bisectiong breakage upstream ]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/arch/x86/util/tsc.c | 1 -
tools/perf/arch/x86/util/tsc.h | 17 -----------------
tools/perf/jvmti/jvmti_agent.c | 43 ++++++++++++++++++++++++++++++++++++++++--
tools/perf/util/Build | 3 +--
tools/perf/util/jitdump.c | 37 +++++++++++++++++++++++++++++++-----
tools/perf/util/jitdump.h | 3 +++
tools/perf/util/tsc.h | 11 ++++++++++-
7 files changed, 87 insertions(+), 28 deletions(-)

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 70ff7c1..357f1b1 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -7,7 +7,6 @@
#include <linux/types.h>
#include "../../util/debug.h"
#include "../../util/tsc.h"
-#include "tsc.h"

int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
struct perf_tsc_conversion *tc)
diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
deleted file mode 100644
index 2edc4d3..0000000
--- a/tools/perf/arch/x86/util/tsc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-
-#include <linux/types.h>
-
-struct perf_tsc_conversion {
- u16 time_shift;
- u32 time_mult;
- u64 time_zero;
-};
-
-struct perf_event_mmap_page;
-
-int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
- struct perf_tsc_conversion *tc);
-
-#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 6461e02..3573f31 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -92,6 +92,22 @@ error:
return ret;
}

+static int use_arch_timestamp;
+
+static inline uint64_t
+get_arch_timestamp(void)
+{
+#if defined(__i386__) || defined(__x86_64__)
+ unsigned int low, high;
+
+ asm volatile("rdtsc" : "=a" (low), "=d" (high));
+
+ return low | ((uint64_t)high) << 32;
+#else
+ return 0;
+#endif
+}
+
#define NSEC_PER_SEC 1000000000
static int perf_clk_id = CLOCK_MONOTONIC;

@@ -107,6 +123,9 @@ perf_get_timestamp(void)
struct timespec ts;
int ret;

+ if (use_arch_timestamp)
+ return get_arch_timestamp();
+
ret = clock_gettime(perf_clk_id, &ts);
if (ret)
return 0;
@@ -203,6 +222,17 @@ perf_close_marker_file(void)
munmap(marker_addr, pgsz);
}

+static void
+init_arch_timestamp(void)
+{
+ char *str = getenv("JITDUMP_USE_ARCH_TIMESTAMP");
+
+ if (!str || !*str || !strcmp(str, "0"))
+ return;
+
+ use_arch_timestamp = 1;
+}
+
void *jvmti_open(void)
{
int pad_cnt;
@@ -211,11 +241,17 @@ void *jvmti_open(void)
int fd;
FILE *fp;

+ init_arch_timestamp();
+
/*
* check if clockid is supported
*/
- if (!perf_get_timestamp())
- warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+ if (!perf_get_timestamp()) {
+ if (use_arch_timestamp)
+ warnx("jvmti: arch timestamp not supported");
+ else
+ warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+ }

memset(&header, 0, sizeof(header));

@@ -263,6 +299,9 @@ void *jvmti_open(void)

header.timestamp = perf_get_timestamp();

+ if (use_arch_timestamp)
+ header.flags |= JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
if (!fwrite(&header, sizeof(header), 1, fp)) {
warn("jvmti: cannot write dumpfile header");
goto error;
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index da48fd8..85ceff3 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
libperf-y += record.o
libperf-y += srcline.o
libperf-y += data.o
-libperf-$(CONFIG_X86) += tsc.o
-libperf-$(CONFIG_AUXTRACE) += tsc.o
+libperf-y += tsc.o
libperf-y += cloexec.o
libperf-y += thread-stack.o
libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index ad0c0bb..52fcef3 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -17,6 +17,7 @@
#include "strlist.h"
#include <elf.h>

+#include "tsc.h"
#include "session.h"
#include "jit.h"
#include "jitdump.h"
@@ -33,6 +34,7 @@ struct jit_buf_desc {
size_t bufsize;
FILE *in;
bool needs_bswap; /* handles cross-endianess */
+ bool use_arch_timestamp;
void *debug_data;
size_t nr_debug_entries;
uint32_t code_load_count;
@@ -158,13 +160,16 @@ jit_open(struct jit_buf_desc *jd, const char *name)
header.flags = bswap_64(header.flags);
}

+ jd->use_arch_timestamp = header.flags & JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
if (verbose > 2)
- pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\n",
+ pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\nuse_arch_timestamp=%d\n",
header.version,
header.total_size,
(unsigned long long)header.timestamp,
header.pid,
- header.elf_mach);
+ header.elf_mach,
+ jd->use_arch_timestamp);

if (header.flags & JITDUMP_FLAGS_RESERVED) {
pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
@@ -172,10 +177,15 @@ jit_open(struct jit_buf_desc *jd, const char *name)
goto error;
}

+ if (jd->use_arch_timestamp && !jd->session->time_conv.time_mult) {
+ pr_err("jitdump file uses arch timestamps but there is no timestamp conversion\n");
+ goto error;
+ }
+
/*
* validate event is using the correct clockid
*/
- if (jit_validate_events(jd->session)) {
+ if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) {
pr_err("error, jitted code must be sampled with perf record -k 1\n");
goto error;
}
@@ -329,6 +339,23 @@ jit_inject_event(struct jit_buf_desc *jd, union perf_event *event)
return 0;
}

+static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
+{
+ struct perf_tsc_conversion tc;
+
+ if (!jd->use_arch_timestamp)
+ return timestamp;
+
+ tc.time_shift = jd->session->time_conv.time_shift;
+ tc.time_mult = jd->session->time_conv.time_mult;
+ tc.time_zero = jd->session->time_conv.time_zero;
+
+ if (!tc.time_mult)
+ return 0;
+
+ return tsc_to_perf_time(timestamp, &tc);
+}
+
static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
{
struct perf_sample sample;
@@ -410,7 +437,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
id->tid = tid;
}
if (jd->sample_type & PERF_SAMPLE_TIME)
- id->time = jr->load.p.timestamp;
+ id->time = convert_timestamp(jd, jr->load.p.timestamp);

/*
* create pseudo sample to induce dso hit increment
@@ -499,7 +526,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
id->tid = tid;
}
if (jd->sample_type & PERF_SAMPLE_TIME)
- id->time = jr->load.p.timestamp;
+ id->time = convert_timestamp(jd, jr->load.p.timestamp);

/*
* create pseudo sample to induce dso hit increment
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index b66c1f5..bcacd20 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -23,9 +23,12 @@
#define JITHEADER_VERSION 1

enum jitdump_flags_bits {
+ JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT,
JITDUMP_FLAGS_MAX_BIT,
};

+#define JITDUMP_FLAGS_ARCH_TIMESTAMP (1ULL << JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT)
+
#define JITDUMP_FLAGS_RESERVED (JITDUMP_FLAGS_MAX_BIT < 64 ? \
(~((1ULL << JITDUMP_FLAGS_MAX_BIT) - 1)) : 0)

diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index 280ddc0..d5b11e2 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -4,7 +4,16 @@
#include <linux/types.h>

#include "event.h"
-#include "../arch/x86/util/tsc.h"
+
+struct perf_tsc_conversion {
+ u16 time_shift;
+ u32 time_mult;
+ u64 time_zero;
+};
+struct perf_event_mmap_page;
+
+int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
+ struct perf_tsc_conversion *tc);

u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);