diff mbox

[v1] perf: cs-etm: Fix ETMv4 CONFIGR entry in perf.data file

Message ID 1499878883-3066-1-git-send-email-mike.leach@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Mike Leach July 12, 2017, 5:01 p.m. UTC
The value passed into the perf.data file for the CONFIGR register in ETMv4
was incorrectly being set to the command line options/ETMv3 value.

Adds bit definitions and function to remap this value to the correct ETMv4
CONFIGR bit values for all selected options.

Signed-off-by: Mike Leach <mike.leach@linaro.org>
---
Changes for v1:
 - Added more people to the recipient list.

 include/linux/coresight-pmu.h       |  5 +++++
 tools/include/linux/coresight-pmu.h |  5 +++++
 tools/perf/arch/arm/util/cs-etm.c   | 28 +++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)

Comments

Mathieu Poirier July 17, 2017, 3:11 p.m. UTC | #1
On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> The value passed into the perf.data file for the CONFIGR register in ETMv4
> was incorrectly being set to the command line options/ETMv3 value.
>
> Adds bit definitions and function to remap this value to the correct ETMv4
> CONFIGR bit values for all selected options.
>
> Signed-off-by: Mike Leach <mike.leach@linaro.org>
> ---
> Changes for v1:
>  - Added more people to the recipient list.
>
>  include/linux/coresight-pmu.h       |  5 +++++
>  tools/include/linux/coresight-pmu.h |  5 +++++
>  tools/perf/arch/arm/util/cs-etm.c   | 28 +++++++++++++++++++++++++++-
>  3 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h
> index 45852c2..edfeaba 100644
> --- a/include/linux/coresight-pmu.h
> +++ b/include/linux/coresight-pmu.h
> @@ -26,6 +26,11 @@
>  #define ETM_OPT_TS      28
>  #define ETM_OPT_RETSTK 29
>
> +/* ETMv4 CONFIGR programming bits for the ETM OPTs */
> +#define ETM4_CFG_BIT_CYCACC    4
> +#define ETM4_CFG_BIT_TS                11
> +#define ETM4_CFG_BIT_RETSTK    12
> +
>  static inline int coresight_get_trace_id(int cpu)
>  {
>         /*
> diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h
> index 45852c2..edfeaba 100644
> --- a/tools/include/linux/coresight-pmu.h
> +++ b/tools/include/linux/coresight-pmu.h
> @@ -26,6 +26,11 @@
>  #define ETM_OPT_TS      28
>  #define ETM_OPT_RETSTK 29
>
> +/* ETMv4 CONFIGR programming bits for the ETM OPTs */
> +#define ETM4_CFG_BIT_CYCACC    4
> +#define ETM4_CFG_BIT_TS                11
> +#define ETM4_CFG_BIT_RETSTK    12
> +
>  static inline int coresight_get_trace_id(int cpu)
>  {
>         /*
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 29361d9..997734b 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -266,6 +266,32 @@ static u64 cs_etm_get_config(struct auxtrace_record *itr)
>         return config;
>  }
>
> +#ifndef BIT
> +#define BIT(N) (1UL << (N))
> +#endif
> +
> +static u64 cs_etmv4_get_config(struct auxtrace_record *itr)
> +{
> +       u64 config = 0;
> +       u64 config_opts = 0;
> +
> +       /*
> +        * The perf event variable config bits represent both
> +        * the command line options and register programming
> +        * bits in ETMv3/PTM. For ETMv4 we must remap options
> +        * to real bits
> +        */
> +       config_opts = cs_etm_get_config(itr);
> +       if (config_opts & BIT(ETM_OPT_CYCACC))
> +               config |= BIT(ETM4_CFG_BIT_CYCACC);
> +       if (config_opts & BIT(ETM_OPT_TS))
> +               config |= BIT(ETM4_CFG_BIT_TS);
> +       if (config_opts & BIT(ETM_OPT_RETSTK))
> +               config |= BIT(ETM4_CFG_BIT_RETSTK);
> +
> +       return config;
> +}
> +
>  static size_t
>  cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
>                       struct perf_evlist *evlist __maybe_unused)
> @@ -363,7 +389,7 @@ static void cs_etm_get_metadata(int cpu, u32 *offset,
>                 magic = __perf_cs_etmv4_magic;
>                 /* Get trace configuration register */
>                 info->priv[*offset + CS_ETMV4_TRCCONFIGR] =
> -                                               cs_etm_get_config(itr);
> +                                               cs_etmv4_get_config(itr);
>                 /* Get traceID from the framework */
>                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
>                                                 coresight_get_trace_id(cpu);
> --
> 2.7.4
>

Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Mathieu Poirier July 21, 2017, 2:50 p.m. UTC | #2
On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> The value passed into the perf.data file for the CONFIGR register in ETMv4
> was incorrectly being set to the command line options/ETMv3 value.
>
> Adds bit definitions and function to remap this value to the correct ETMv4
> CONFIGR bit values for all selected options.
>
> Signed-off-by: Mike Leach <mike.leach@linaro.org>
> ---
> Changes for v1:
>  - Added more people to the recipient list.
>
>  include/linux/coresight-pmu.h       |  5 +++++
>  tools/include/linux/coresight-pmu.h |  5 +++++
>  tools/perf/arch/arm/util/cs-etm.c   | 28 +++++++++++++++++++++++++++-
>  3 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h
> index 45852c2..edfeaba 100644
> --- a/include/linux/coresight-pmu.h
> +++ b/include/linux/coresight-pmu.h
> @@ -26,6 +26,11 @@
>  #define ETM_OPT_TS      28
>  #define ETM_OPT_RETSTK 29
>
> +/* ETMv4 CONFIGR programming bits for the ETM OPTs */
> +#define ETM4_CFG_BIT_CYCACC    4
> +#define ETM4_CFG_BIT_TS                11
> +#define ETM4_CFG_BIT_RETSTK    12
> +
>  static inline int coresight_get_trace_id(int cpu)
>  {
>         /*
> diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h
> index 45852c2..edfeaba 100644
> --- a/tools/include/linux/coresight-pmu.h
> +++ b/tools/include/linux/coresight-pmu.h
> @@ -26,6 +26,11 @@
>  #define ETM_OPT_TS      28
>  #define ETM_OPT_RETSTK 29
>
> +/* ETMv4 CONFIGR programming bits for the ETM OPTs */
> +#define ETM4_CFG_BIT_CYCACC    4
> +#define ETM4_CFG_BIT_TS                11
> +#define ETM4_CFG_BIT_RETSTK    12
> +
>  static inline int coresight_get_trace_id(int cpu)
>  {
>         /*
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 29361d9..997734b 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -266,6 +266,32 @@ static u64 cs_etm_get_config(struct auxtrace_record *itr)
>         return config;
>  }
>
> +#ifndef BIT
> +#define BIT(N) (1UL << (N))
> +#endif
> +
> +static u64 cs_etmv4_get_config(struct auxtrace_record *itr)
> +{
> +       u64 config = 0;
> +       u64 config_opts = 0;
> +
> +       /*
> +        * The perf event variable config bits represent both
> +        * the command line options and register programming
> +        * bits in ETMv3/PTM. For ETMv4 we must remap options
> +        * to real bits
> +        */
> +       config_opts = cs_etm_get_config(itr);
> +       if (config_opts & BIT(ETM_OPT_CYCACC))
> +               config |= BIT(ETM4_CFG_BIT_CYCACC);
> +       if (config_opts & BIT(ETM_OPT_TS))
> +               config |= BIT(ETM4_CFG_BIT_TS);
> +       if (config_opts & BIT(ETM_OPT_RETSTK))
> +               config |= BIT(ETM4_CFG_BIT_RETSTK);
> +
> +       return config;
> +}
> +
>  static size_t
>  cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
>                       struct perf_evlist *evlist __maybe_unused)
> @@ -363,7 +389,7 @@ static void cs_etm_get_metadata(int cpu, u32 *offset,
>                 magic = __perf_cs_etmv4_magic;
>                 /* Get trace configuration register */
>                 info->priv[*offset + CS_ETMV4_TRCCONFIGR] =
> -                                               cs_etm_get_config(itr);
> +                                               cs_etmv4_get_config(itr);
>                 /* Get traceID from the framework */
>                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
>                                                 coresight_get_trace_id(cpu);

I have tested this patch on my side and things work as advertised now.

Arnaldo, if you want to pick this up through your tree then:

Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Otherwise I'll get this, whatever you prefer.

Thanks,
Mathieu.

> --
> 2.7.4
>
Arnaldo Carvalho de Melo July 21, 2017, 4:19 p.m. UTC | #3
Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
> On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> > The value passed into the perf.data file for the CONFIGR register in ETMv4
> > was incorrectly being set to the command line options/ETMv3 value.
> >
> >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
> >                                                 coresight_get_trace_id(cpu);
> 
> I have tested this patch on my side and things work as advertised now.
> 
> Arnaldo, if you want to pick this up through your tree then:
> 
> Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> Otherwise I'll get this, whatever you prefer.

I'll get it, thanks for the ping,

- Arnaldo
Arnaldo Carvalho de Melo July 21, 2017, 6:35 p.m. UTC | #4
Em Fri, Jul 21, 2017 at 01:19:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
> > On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> > > The value passed into the perf.data file for the CONFIGR register in ETMv4
> > > was incorrectly being set to the command line options/ETMv3 value.
> > >
> > >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
> > >                                                 coresight_get_trace_id(cpu);
> > 
> > I have tested this patch on my side and things work as advertised now.
> > 
> > Arnaldo, if you want to pick this up through your tree then:
> > 
> > Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> > 
> > Otherwise I'll get this, whatever you prefer.
> 
> I'll get it, thanks for the ping,

It is breaking the build in one of my containers, one with fedora 24 and
a android toolchain from http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip

arch/arm/util/cs-etm.c: In function 'cs_etmv4_get_config':^M
arch/arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)^M
  if (config_opts & BIT(ETM_OPT_RETSTK))

It builds as

NDK=/opt/android-ndk-r12b/
NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
make -C /git/linux/tools/perf O=/tmp/build/perf WERROR=0 CFLAGS=${CFLAGS} ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" 
Ideas?

- Arnaldo
Arnaldo Carvalho de Melo July 21, 2017, 6:37 p.m. UTC | #5
Em Fri, Jul 21, 2017 at 03:35:33PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jul 21, 2017 at 01:19:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
> > > On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> > > > The value passed into the perf.data file for the CONFIGR register in ETMv4
> > > > was incorrectly being set to the command line options/ETMv3 value.
> > > >
> > > >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
> > > >                                                 coresight_get_trace_id(cpu);
> > > 
> > > I have tested this patch on my side and things work as advertised now.
> > > 
> > > Arnaldo, if you want to pick this up through your tree then:
> > > 
> > > Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> > > 
> > > Otherwise I'll get this, whatever you prefer.
> > 
> > I'll get it, thanks for the ping,
> 
> It is breaking the build in one of my containers, one with fedora 24 and
> a android toolchain from http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
> 
> arch/arm/util/cs-etm.c: In function 'cs_etmv4_get_config':^M
> arch/arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)^M
>   if (config_opts & BIT(ETM_OPT_RETSTK))
> 
> It builds as
> 
> NDK=/opt/android-ndk-r12b/
> NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
> NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
> make -C /git/linux/tools/perf O=/tmp/build/perf WERROR=0 CFLAGS=${CFLAGS} ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" 
> Ideas?

Ok, it also fails on:

  14 debian:experimental-x-arm64: FAIL


Same problem:

  CC       /tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o
  CC       /tmp/build/perf/util/config.o
arch/arm64/util/../../arm/util/cs-etm.c: In function 'cs_etmv4_get_config':
arch/arm64/util/../../arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)
  if (config_opts & BIT(ETM_OPT_RETSTK))
                        ^
arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
 #define BIT(N) (1UL << (N))
                         ^
arch/arm64/util/../../arm/util/cs-etm.c:289:24: note: each undeclared identifier is reported only once for each function it appears in
  if (config_opts & BIT(ETM_OPT_RETSTK))
                        ^
arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
 #define BIT(N) (1UL << (N))
                         ^
mv: cannot stat '/tmp/build/perf/arch/arm64/util/../../arm/util/.cs-etm.o.tmp': No such file or directory
/git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o' failed
make[6]: *** [/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o] Error 1
/git/linux/tools/build/Makefile.build:144: recipe for target 'util' failed
make[5]: *** [util] Error 2
/git/linux/tools/build/Makefile.build:144: recipe for target 'arm64' failed
make[4]: *** [arm64] Error 2
/git/linux/tools/build/Makefile.build:144: recipe for target 'arch' failed
make[3]: *** [arch] Error 2
make[3]: *** Waiting for unfinished jobs....
  CC       /tmp/build/perf/util/ctype.o

Builds with:

ARCH=arm64
TARGET=aarch64-linux-gnu
make ARCH=${ARCH} CROSS_COMPILE=${TARGET}- -C /git/linux/tools/perf O=/tmp/build/perf

- Arnaldo
Arnaldo Carvalho de Melo July 21, 2017, 7:11 p.m. UTC | #6
Em Fri, Jul 21, 2017 at 03:37:40PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jul 21, 2017 at 03:35:33PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Jul 21, 2017 at 01:19:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
> > > > On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> > > > > The value passed into the perf.data file for the CONFIGR register in ETMv4
> > > > > was incorrectly being set to the command line options/ETMv3 value.
> > > > >
> > > > >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
> > > > >                                                 coresight_get_trace_id(cpu);
> > > > 
> > > > I have tested this patch on my side and things work as advertised now.
> > > > 
> > > > Arnaldo, if you want to pick this up through your tree then:
> > > > 
> > > > Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> > > > 
> > > > Otherwise I'll get this, whatever you prefer.
> > > 
> > > I'll get it, thanks for the ping,
> > 
> > It is breaking the build in one of my containers, one with fedora 24 and
> > a android toolchain from http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
> > 
> > arch/arm/util/cs-etm.c: In function 'cs_etmv4_get_config':^M
> > arch/arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)^M
> >   if (config_opts & BIT(ETM_OPT_RETSTK))
> > 
> > It builds as
> > 
> > NDK=/opt/android-ndk-r12b/
> > NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
> > NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
> > make -C /git/linux/tools/perf O=/tmp/build/perf WERROR=0 CFLAGS=${CFLAGS} ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" 
> > Ideas?
> 
> Ok, it also fails on:
> 
>   14 debian:experimental-x-arm64: FAIL

Ok, we need a definition for ETM_OPT_RETSTK, just like we have for the
other two...

Nuked it from my perf/core branch, please resubmit.

- Arnaldo
 
> 
> Same problem:
> 
>   CC       /tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o
>   CC       /tmp/build/perf/util/config.o
> arch/arm64/util/../../arm/util/cs-etm.c: In function 'cs_etmv4_get_config':
> arch/arm64/util/../../arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)
>   if (config_opts & BIT(ETM_OPT_RETSTK))
>                         ^
> arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
>  #define BIT(N) (1UL << (N))
>                          ^
> arch/arm64/util/../../arm/util/cs-etm.c:289:24: note: each undeclared identifier is reported only once for each function it appears in
>   if (config_opts & BIT(ETM_OPT_RETSTK))
>                         ^
> arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
>  #define BIT(N) (1UL << (N))
>                          ^
> mv: cannot stat '/tmp/build/perf/arch/arm64/util/../../arm/util/.cs-etm.o.tmp': No such file or directory
> /git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o' failed
> make[6]: *** [/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o] Error 1
> /git/linux/tools/build/Makefile.build:144: recipe for target 'util' failed
> make[5]: *** [util] Error 2
> /git/linux/tools/build/Makefile.build:144: recipe for target 'arm64' failed
> make[4]: *** [arm64] Error 2
> /git/linux/tools/build/Makefile.build:144: recipe for target 'arch' failed
> make[3]: *** [arch] Error 2
> make[3]: *** Waiting for unfinished jobs....
>   CC       /tmp/build/perf/util/ctype.o
> 
> Builds with:
> 
> ARCH=arm64
> TARGET=aarch64-linux-gnu
> make ARCH=${ARCH} CROSS_COMPILE=${TARGET}- -C /git/linux/tools/perf O=/tmp/build/perf
> 
> - Arnaldo
Mathieu Poirier July 24, 2017, 7:37 p.m. UTC | #7
On 21 July 2017 at 13:11, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> Em Fri, Jul 21, 2017 at 03:37:40PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Jul 21, 2017 at 03:35:33PM -0300, Arnaldo Carvalho de Melo escreveu:
>> > Em Fri, Jul 21, 2017 at 01:19:16PM -0300, Arnaldo Carvalho de Melo escreveu:
>> > > Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
>> > > > On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
>> > > > > The value passed into the perf.data file for the CONFIGR register in ETMv4
>> > > > > was incorrectly being set to the command line options/ETMv3 value.
>> > > > >
>> > > > >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
>> > > > >                                                 coresight_get_trace_id(cpu);
>> > > >
>> > > > I have tested this patch on my side and things work as advertised now.
>> > > >
>> > > > Arnaldo, if you want to pick this up through your tree then:
>> > > >
>> > > > Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
>> > > >
>> > > > Otherwise I'll get this, whatever you prefer.
>> > >
>> > > I'll get it, thanks for the ping,
>> >
>> > It is breaking the build in one of my containers, one with fedora 24 and
>> > a android toolchain from http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
>> >
>> > arch/arm/util/cs-etm.c: In function 'cs_etmv4_get_config':^M
>> > arch/arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)^M
>> >   if (config_opts & BIT(ETM_OPT_RETSTK))
>> >
>> > It builds as
>> >
>> > NDK=/opt/android-ndk-r12b/
>> > NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
>> > NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
>> > make -C /git/linux/tools/perf O=/tmp/build/perf WERROR=0 CFLAGS=${CFLAGS} ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
>> > Ideas?
>>
>> Ok, it also fails on:
>>
>>   14 debian:experimental-x-arm64: FAIL
>
> Ok, we need a definition for ETM_OPT_RETSTK, just like we have for the
> other two...
>
> Nuked it from my perf/core branch, please resubmit.

Symbol ETM_OPT_RETSTK was added as part of another patch [1] that is
already in my CoreSight tree.  Do you mind if we make this one go
through my tree then?

Thanks,
Mathieu

[1]. https://www.spinics.net/lists/arm-kernel/msg593008.html

> - Arnaldo
>
>>
>> Same problem:
>>
>>   CC       /tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o
>>   CC       /tmp/build/perf/util/config.o
>> arch/arm64/util/../../arm/util/cs-etm.c: In function 'cs_etmv4_get_config':
>> arch/arm64/util/../../arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)
>>   if (config_opts & BIT(ETM_OPT_RETSTK))
>>                         ^
>> arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
>>  #define BIT(N) (1UL << (N))
>>                          ^
>> arch/arm64/util/../../arm/util/cs-etm.c:289:24: note: each undeclared identifier is reported only once for each function it appears in
>>   if (config_opts & BIT(ETM_OPT_RETSTK))
>>                         ^
>> arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
>>  #define BIT(N) (1UL << (N))
>>                          ^
>> mv: cannot stat '/tmp/build/perf/arch/arm64/util/../../arm/util/.cs-etm.o.tmp': No such file or directory
>> /git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o' failed
>> make[6]: *** [/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o] Error 1
>> /git/linux/tools/build/Makefile.build:144: recipe for target 'util' failed
>> make[5]: *** [util] Error 2
>> /git/linux/tools/build/Makefile.build:144: recipe for target 'arm64' failed
>> make[4]: *** [arm64] Error 2
>> /git/linux/tools/build/Makefile.build:144: recipe for target 'arch' failed
>> make[3]: *** [arch] Error 2
>> make[3]: *** Waiting for unfinished jobs....
>>   CC       /tmp/build/perf/util/ctype.o
>>
>> Builds with:
>>
>> ARCH=arm64
>> TARGET=aarch64-linux-gnu
>> make ARCH=${ARCH} CROSS_COMPILE=${TARGET}- -C /git/linux/tools/perf O=/tmp/build/perf
>>
>> - Arnaldo
Mathieu Poirier Aug. 1, 2017, 4:17 p.m. UTC | #8
On 24 July 2017 at 13:37, Mathieu Poirier <mathieu.poirier@linaro.org> wrote:
> On 21 July 2017 at 13:11, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>> Em Fri, Jul 21, 2017 at 03:37:40PM -0300, Arnaldo Carvalho de Melo escreveu:
>>> Em Fri, Jul 21, 2017 at 03:35:33PM -0300, Arnaldo Carvalho de Melo escreveu:
>>> > Em Fri, Jul 21, 2017 at 01:19:16PM -0300, Arnaldo Carvalho de Melo escreveu:
>>> > > Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
>>> > > > On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
>>> > > > > The value passed into the perf.data file for the CONFIGR register in ETMv4
>>> > > > > was incorrectly being set to the command line options/ETMv3 value.
>>> > > > >
>>> > > > >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
>>> > > > >                                                 coresight_get_trace_id(cpu);
>>> > > >
>>> > > > I have tested this patch on my side and things work as advertised now.
>>> > > >
>>> > > > Arnaldo, if you want to pick this up through your tree then:
>>> > > >
>>> > > > Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
>>> > > >
>>> > > > Otherwise I'll get this, whatever you prefer.
>>> > >
>>> > > I'll get it, thanks for the ping,
>>> >
>>> > It is breaking the build in one of my containers, one with fedora 24 and
>>> > a android toolchain from http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
>>> >
>>> > arch/arm/util/cs-etm.c: In function 'cs_etmv4_get_config':^M
>>> > arch/arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)^M
>>> >   if (config_opts & BIT(ETM_OPT_RETSTK))
>>> >
>>> > It builds as
>>> >
>>> > NDK=/opt/android-ndk-r12b/
>>> > NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
>>> > NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
>>> > make -C /git/linux/tools/perf O=/tmp/build/perf WERROR=0 CFLAGS=${CFLAGS} ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
>>> > Ideas?
>>>
>>> Ok, it also fails on:
>>>
>>>   14 debian:experimental-x-arm64: FAIL
>>
>> Ok, we need a definition for ETM_OPT_RETSTK, just like we have for the
>> other two...
>>
>> Nuked it from my perf/core branch, please resubmit.
>
> Symbol ETM_OPT_RETSTK was added as part of another patch [1] that is
> already in my CoreSight tree.  Do you mind if we make this one go
> through my tree then?

I haven't heard back from this so I'll assume you want me to take the patch.

>
> Thanks,
> Mathieu
>
> [1]. https://www.spinics.net/lists/arm-kernel/msg593008.html
>
>> - Arnaldo
>>
>>>
>>> Same problem:
>>>
>>>   CC       /tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o
>>>   CC       /tmp/build/perf/util/config.o
>>> arch/arm64/util/../../arm/util/cs-etm.c: In function 'cs_etmv4_get_config':
>>> arch/arm64/util/../../arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)
>>>   if (config_opts & BIT(ETM_OPT_RETSTK))
>>>                         ^
>>> arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
>>>  #define BIT(N) (1UL << (N))
>>>                          ^
>>> arch/arm64/util/../../arm/util/cs-etm.c:289:24: note: each undeclared identifier is reported only once for each function it appears in
>>>   if (config_opts & BIT(ETM_OPT_RETSTK))
>>>                         ^
>>> arch/arm64/util/../../arm/util/cs-etm.c:270:25: note: in definition of macro 'BIT'
>>>  #define BIT(N) (1UL << (N))
>>>                          ^
>>> mv: cannot stat '/tmp/build/perf/arch/arm64/util/../../arm/util/.cs-etm.o.tmp': No such file or directory
>>> /git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o' failed
>>> make[6]: *** [/tmp/build/perf/arch/arm64/util/../../arm/util/cs-etm.o] Error 1
>>> /git/linux/tools/build/Makefile.build:144: recipe for target 'util' failed
>>> make[5]: *** [util] Error 2
>>> /git/linux/tools/build/Makefile.build:144: recipe for target 'arm64' failed
>>> make[4]: *** [arm64] Error 2
>>> /git/linux/tools/build/Makefile.build:144: recipe for target 'arch' failed
>>> make[3]: *** [arch] Error 2
>>> make[3]: *** Waiting for unfinished jobs....
>>>   CC       /tmp/build/perf/util/ctype.o
>>>
>>> Builds with:
>>>
>>> ARCH=arm64
>>> TARGET=aarch64-linux-gnu
>>> make ARCH=${ARCH} CROSS_COMPILE=${TARGET}- -C /git/linux/tools/perf O=/tmp/build/perf
>>>
>>> - Arnaldo
Arnaldo Carvalho de Melo Aug. 1, 2017, 4:44 p.m. UTC | #9
Em Tue, Aug 01, 2017 at 10:17:56AM -0600, Mathieu Poirier escreveu:
> On 24 July 2017 at 13:37, Mathieu Poirier <mathieu.poirier@linaro.org> wrote:
> > On 21 July 2017 at 13:11, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >> Em Fri, Jul 21, 2017 at 03:37:40PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>> Em Fri, Jul 21, 2017 at 03:35:33PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>> > Em Fri, Jul 21, 2017 at 01:19:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>> > > Em Fri, Jul 21, 2017 at 08:50:09AM -0600, Mathieu Poirier escreveu:
> >>> > > > On 12 July 2017 at 11:01, Mike Leach <mike.leach@linaro.org> wrote:
> >>> > > > > The value passed into the perf.data file for the CONFIGR register in ETMv4
> >>> > > > > was incorrectly being set to the command line options/ETMv3 value.
> >>> > > > >
> >>> > > > >                 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
> >>> > > > >                                                 coresight_get_trace_id(cpu);
> >>> > > >
> >>> > > > I have tested this patch on my side and things work as advertised now.
> >>> > > >
> >>> > > > Arnaldo, if you want to pick this up through your tree then:
> >>> > > >
> >>> > > > Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> >>> > > >
> >>> > > > Otherwise I'll get this, whatever you prefer.
> >>> > >
> >>> > > I'll get it, thanks for the ping,
> >>> >
> >>> > It is breaking the build in one of my containers, one with fedora 24 and
> >>> > a android toolchain from http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
> >>> >
> >>> > arch/arm/util/cs-etm.c: In function 'cs_etmv4_get_config':^M
> >>> > arch/arm/util/cs-etm.c:289:24: error: 'ETM_OPT_RETSTK' undeclared (first use in this function)^M
> >>> >   if (config_opts & BIT(ETM_OPT_RETSTK))
> >>> >
> >>> > It builds as
> >>> >
> >>> > NDK=/opt/android-ndk-r12b/
> >>> > NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
> >>> > NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
> >>> > make -C /git/linux/tools/perf O=/tmp/build/perf WERROR=0 CFLAGS=${CFLAGS} ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
> >>> > Ideas?
> >>>
> >>> Ok, it also fails on:
> >>>
> >>>   14 debian:experimental-x-arm64: FAIL
> >>
> >> Ok, we need a definition for ETM_OPT_RETSTK, just like we have for the
> >> other two...
> >>
> >> Nuked it from my perf/core branch, please resubmit.
> >
> > Symbol ETM_OPT_RETSTK was added as part of another patch [1] that is
> > already in my CoreSight tree.  Do you mind if we make this one go
> > through my tree then?
> 
> I haven't heard back from this so I'll assume you want me to take the patch.

Yeah, I should've replied to you, but since this depends on stuff only
in your tree, going thru that is sensible :-)

Ack.

- Arnaldo
diff mbox

Patch

diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h
index 45852c2..edfeaba 100644
--- a/include/linux/coresight-pmu.h
+++ b/include/linux/coresight-pmu.h
@@ -26,6 +26,11 @@ 
 #define ETM_OPT_TS      28
 #define ETM_OPT_RETSTK	29
 
+/* ETMv4 CONFIGR programming bits for the ETM OPTs */
+#define ETM4_CFG_BIT_CYCACC	4
+#define ETM4_CFG_BIT_TS		11
+#define ETM4_CFG_BIT_RETSTK	12
+
 static inline int coresight_get_trace_id(int cpu)
 {
 	/*
diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h
index 45852c2..edfeaba 100644
--- a/tools/include/linux/coresight-pmu.h
+++ b/tools/include/linux/coresight-pmu.h
@@ -26,6 +26,11 @@ 
 #define ETM_OPT_TS      28
 #define ETM_OPT_RETSTK	29
 
+/* ETMv4 CONFIGR programming bits for the ETM OPTs */
+#define ETM4_CFG_BIT_CYCACC	4
+#define ETM4_CFG_BIT_TS		11
+#define ETM4_CFG_BIT_RETSTK	12
+
 static inline int coresight_get_trace_id(int cpu)
 {
 	/*
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 29361d9..997734b 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -266,6 +266,32 @@  static u64 cs_etm_get_config(struct auxtrace_record *itr)
 	return config;
 }
 
+#ifndef BIT
+#define BIT(N) (1UL << (N))
+#endif
+
+static u64 cs_etmv4_get_config(struct auxtrace_record *itr)
+{
+	u64 config = 0;
+	u64 config_opts = 0;
+
+	/*
+	 * The perf event variable config bits represent both
+	 * the command line options and register programming
+	 * bits in ETMv3/PTM. For ETMv4 we must remap options
+	 * to real bits
+	 */
+	config_opts = cs_etm_get_config(itr);
+	if (config_opts & BIT(ETM_OPT_CYCACC))
+		config |= BIT(ETM4_CFG_BIT_CYCACC);
+	if (config_opts & BIT(ETM_OPT_TS))
+		config |= BIT(ETM4_CFG_BIT_TS);
+	if (config_opts & BIT(ETM_OPT_RETSTK))
+		config |= BIT(ETM4_CFG_BIT_RETSTK);
+
+	return config;
+}
+
 static size_t
 cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
 		      struct perf_evlist *evlist __maybe_unused)
@@ -363,7 +389,7 @@  static void cs_etm_get_metadata(int cpu, u32 *offset,
 		magic = __perf_cs_etmv4_magic;
 		/* Get trace configuration register */
 		info->priv[*offset + CS_ETMV4_TRCCONFIGR] =
-						cs_etm_get_config(itr);
+						cs_etmv4_get_config(itr);
 		/* Get traceID from the framework */
 		info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
 						coresight_get_trace_id(cpu);