[meta-fsl-arm-extra] linux-wandboard: Configure the ARM core to use hardware performance counters.

Submitted by Gonzalez, Alex on Dec. 21, 2014, 4:06 p.m. | Patch ID: 85345

Details

Message ID 1419178019-27037-2-git-send-email-alex.gonzalez@digi.com
State Deferred, archived
Delegated to: Otavio Salvador
Headers show

Commit Message

Gonzalez, Alex Dec. 21, 2014, 4:06 p.m.
Without this patch the performance counters in the Cortex A9 core always
return zero.

Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
---
 ...6q-Set-non-invasive-debug-configuration-p.patch | 42 ++++++++++++++++++++++
 recipes-kernel/linux/linux-wandboard_3.10.17.bb    |  2 ++
 2 files changed, 44 insertions(+)
 create mode 100644 recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch

Patch hide | download patch | download mbox

diff --git a/recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch b/recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch
new file mode 100644
index 000000000000..69826afe25e2
--- /dev/null
+++ b/recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch
@@ -0,0 +1,42 @@ 
+From: Alex Gonzalez <alex.gonzalez@digi.com>
+Date: Sun, 21 Dec 2014 16:04:56 +0100
+Subject: [PATCH] ARM: imx: imx6q: Set non invasive debug configuration
+ permission bits.
+
+This is needed in order to use the hardware performance events counters.
+
+http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16431.html
+
+Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
+---
+ arch/arm/mach-imx/mach-imx6q.c | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+diff --git a/arch/arm/mach-imx/mach-imx6q.c b/arch/arm/mach-imx/mach-imx6q.c
+index 5fb11af5643d..e54906a8d442 100644
+--- a/arch/arm/mach-imx/mach-imx6q.c
++++ b/arch/arm/mach-imx/mach-imx6q.c
+@@ -304,6 +304,15 @@ static const struct of_dev_auxdata imx6q_auxdata_lookup[] __initconst = {
+ 	{ /* sentinel */ }
+ };
+ 
++static void imx6q_armpmu_init(void)
++{
++	/* Configure the non invasive debug configuration registers */
++	if (IS_ENABLED(CONFIG_HW_PERF_EVENTS)) {
++		u32 val = 0b11;
++		asm volatile("mcr p15, 0, %0, c1, c1, 1" : : "r" (val));
++	}
++}
++
+ static void __init imx6q_init_machine(void)
+ {
+ 	struct device *parent;
+@@ -320,6 +329,7 @@ static void __init imx6q_init_machine(void)
+ 	imx_anatop_init();
+ 	imx6_pm_init();
+ 	imx6q_csi_mux_init();
++	imx6q_armpmu_init();
+ }
+ 
+ #define OCOTP_CFG3			0x440
diff --git a/recipes-kernel/linux/linux-wandboard_3.10.17.bb b/recipes-kernel/linux/linux-wandboard_3.10.17.bb
index 30483f18d6b9..347bad8dfee7 100644
--- a/recipes-kernel/linux/linux-wandboard_3.10.17.bb
+++ b/recipes-kernel/linux/linux-wandboard_3.10.17.bb
@@ -6,6 +6,8 @@  require recipes-kernel/linux/linux-dtb.inc
 
 DEPENDS += "lzop-native bc-native"
 
+SRC_URI += "file://0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch"
+
 # Wandboard branch - based on 3.10.17_1.0.1_ga from Freescale git
 SRCBRANCH = "wandboard_imx_3.10.17_1.0.1_ga"
 SRCREV = "a6e7fc58e6912986d003598ed79bb6a391a2113c"

Comments

Fabio Estevam Dec. 29, 2014, 2:13 p.m.
On Sun, Dec 21, 2014 at 2:06 PM, Alex Gonzalez <alex.gonzalez@digi.com> wrote:
> Without this patch the performance counters in the Cortex A9 core always
> return zero.

I suppose you have a JTAG cable connected to the board as per
"ERR006259 ARM: Debug/trace functions (PMU, PTM and ETB) are disabled
with absence of JTAG_TCK clock after POR" , right?


> Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
> ---
>  ...6q-Set-non-invasive-debug-configuration-p.patch | 42 ++++++++++++++++++++++
>  recipes-kernel/linux/linux-wandboard_3.10.17.bb    |  2 ++
>  2 files changed, 44 insertions(+)
>  create mode 100644 recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch
>
> diff --git a/recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch b/recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch
> new file mode 100644
> index 000000000000..69826afe25e2
> --- /dev/null
> +++ b/recipes-kernel/linux/linux-wandboard-3.10.17/0001-ARM-imx-imx6q-Set-non-invasive-debug-configuration-p.patch
> @@ -0,0 +1,42 @@
> +From: Alex Gonzalez <alex.gonzalez@digi.com>
> +Date: Sun, 21 Dec 2014 16:04:56 +0100
> +Subject: [PATCH] ARM: imx: imx6q: Set non invasive debug configuration
> + permission bits.
> +
> +This is needed in order to use the hardware performance events counters.
> +
> +http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16431.html
> +
> +Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
> +---
> + arch/arm/mach-imx/mach-imx6q.c | 10 ++++++++++
> + 1 file changed, 10 insertions(+)
> +
> +diff --git a/arch/arm/mach-imx/mach-imx6q.c b/arch/arm/mach-imx/mach-imx6q.c
> +index 5fb11af5643d..e54906a8d442 100644
> +--- a/arch/arm/mach-imx/mach-imx6q.c
> ++++ b/arch/arm/mach-imx/mach-imx6q.c
> +@@ -304,6 +304,15 @@ static const struct of_dev_auxdata imx6q_auxdata_lookup[] __initconst = {
> +       { /* sentinel */ }
> + };
> +
> ++static void imx6q_armpmu_init(void)
> ++{
> ++      /* Configure the non invasive debug configuration registers */
> ++      if (IS_ENABLED(CONFIG_HW_PERF_EVENTS)) {
> ++              u32 val = 0b11;
> ++              asm volatile("mcr p15, 0, %0, c1, c1, 1" : : "r" (val));

Wouldn't this be required for all CortexA9 instead of mx6 only?

It would be nice if you could send this to the linux-arm-kernel for
review and proper discussion.

Thanks
Gonzalez, Alex Jan. 5, 2015, 11:26 a.m.
Thanks Fabio,

> I suppose you have a JTAG cable connected to the board as per
> "ERR006259 ARM: Debug/trace functions (PMU, PTM and ETB) are disabled
> with absence of JTAG_TCK clock after POR" , right?

I'll have to revisit this after reading the errata. I was able to read perf counters after the patch without the JTAG clock, so I need to understand what's going on.

Once I understand I will send the patch to linux-arm-kernel for review.

Alex
Gonzalez, Alex Jan. 12, 2015, 7:48 p.m.
Hi,

An update on this patch.

I can confirm that I can successfully read PMU events counters if I supply a JTAG clock.

However, as I said, I could also read them with this patch. I took the approach of comparing the cpu cycles event with the corresponding PMU event counter. The value obtained with the JTAG clock is more exact than the one with this patch.

Current code, no JTAG clock:

perf stat -e r11 sleep 1
 Performance counter stats for 'sleep 1':
                 0 r11                                                         
       1.005361000 seconds time elapsed

perf stat -e cycles sleep 1
 Performance counter stats for 'sleep 1':
           1594953 cycles                    #    0.000 GHz                    
       1.005478333 seconds time elapsed

JTAG clock:

 perf stat -e r11 sleep 1

 Performance counter stats for 'sleep 1':
           1535519 r11                                                         
       1.005299334 seconds time elapsed

Applying the enclosed user mode access patch:

 Performance counter stats for 'sleep 1':
            409200 r11                                                         
       1.005370667 seconds time elapsed

This makes sense in that the Linux kernel running in privileged mode does not need to configure the non-invasive debug bits for user mode access.

However, I am still puzzled as to why configuring those bits I am able to read data from the PMU at all.

Bottom line, please ignore the patch.

Alex