From: Will Deacon <hidden> Date: 2011-03-16 15:38:17
ARMv7 dictates that the interrupt-enable and count-enable registers for
each PMU counter are UNKNOWN following core reset.
This patch adds an arch_initcall to the ARMv7 perf events backend which
disables the counters on each CPU prior to setting the Enable bit in the
PMCR.
Cc: Jean Pihet <redacted>
Signed-off-by: Will Deacon <redacted>
---
arch/arm/kernel/perf_event_v7.c | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
@@ -860,12 +860,31 @@ static struct arm_pmu armv7pmu = {.max_period=(1LLU<<32)-1,};-staticu32__initarmv7_reset_read_pmnc(void)+staticvoidarmv7_reset_pmnc(void*info){-u32nb_cnt;+u32idx,nb_cnt=armv7pmu.num_events;++/* The counter and interrupt enable registers are unknown@reset. */+for(idx=1;idx<nb_cnt;++idx)+armv7pmu_disable_event(NULL,idx);/* Initialize & Reset PMNC: C and P bits */armv7_pmnc_write(ARMV7_PMNC_P|ARMV7_PMNC_C);+}++staticint__initarmv7_pmnc_init(void)+{+/*+*ResetthecounterstatusoneachCPUsothatwedon'treceive+*spuriousinterruptswhenwesettheEbit.+*/+returnon_each_cpu(armv7_reset_pmnc,NULL,1);+}+arch_initcall(armv7_pmnc_init);++staticu32__initarmv7_read_num_pmnc_events(void)+{+u32nb_cnt;/* Read the nb of CNTx counters supported from PMNC */nb_cnt=(armv7_pmnc_read()>>ARMV7_PMNC_N_SHIFT)&ARMV7_PMNC_N_MASK;
From: Will Deacon <hidden> Date: 2011-03-16 15:38:18
The ARMv7 architecture does not guarantee that effects from co-processor
writes are immediately visible to following instructions.
This patch adds two isbs to the ARMv7 perf code:
(1) Immediately after selecting an event register, so that the PMU state
following this instruction is consistent with the new event.
(2) Immediately before writing to the PMCR, so that any previous writes
to the PMU have taken effect before (typically) enabling the
counters.
Cc: Jean Pihet <redacted>
Signed-off-by: Will Deacon <redacted>
---
arch/arm/kernel/perf_event_v7.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
From: Jean Pihet <hidden> Date: 2011-03-16 16:00:14
On Wed, Mar 16, 2011 at 4:38 PM, Will Deacon [off-list ref] wrote:
The ARMv7 architecture does not guarantee that effects from co-processor
writes are immediately visible to following instructions.
This patch adds two isbs to the ARMv7 perf code:
(1) Immediately after selecting an event register, so that the PMU state
? ?following this instruction is consistent with the new event.
Ok
(2) Immediately before writing to the PMCR, so that any previous writes
? ?to the PMU have taken effect before (typically) enabling the
? ?counters.
Should the isb come _after_ the cp15 instruction so that the current
access is actually performed?
Thanks,
Jean
From: Will Deacon <hidden> Date: 2011-03-16 16:21:09
Hi Jean,
On Wed, Mar 16, 2011 at 4:38 PM, Will Deacon [off-list ref] wrote:
quoted
ARMv7 dictates that the interrupt-enable and count-enable registers for
each PMU counter are UNKNOWN following core reset.
Great! Is this development driven by actual issues or by precaution?
Just precautionary, but it's also a precursor to some power management
work in ARM which might leave the registers in a funny state when they
come out of a low-power state. This code at least gives them an entry
hook for dealing with that.
quoted
This patch adds an arch_initcall to the ARMv7 perf events backend which
disables the counters on each CPU prior to setting the Enable bit in the
PMCR.
Also the function rename is a good thing.
Yup.
quoted
Cc: Jean Pihet <redacted>
Signed-off-by: Will Deacon <redacted>
From: Will Deacon <hidden> Date: 2011-03-16 16:34:15
Hello,
On Wed, Mar 16, 2011 at 4:38 PM, Will Deacon [off-list ref] wrote:
quoted
The ARMv7 architecture does not guarantee that effects from co-processor
writes are immediately visible to following instructions.
This patch adds two isbs to the ARMv7 perf code:
(1) Immediately after selecting an event register, so that the PMU state
? ?following this instruction is consistent with the new event.
Ok
quoted
(2) Immediately before writing to the PMCR, so that any previous writes
? ?to the PMU have taken effect before (typically) enabling the
? ?counters.
Should the isb come _after_ the cp15 instruction so that the current
access is actually performed?
No. We want to ensure that the _other_ PMU registers are up-to-date before
playing with the control register, otherwise we could end up in a horrible
situation where we enable all the counters, but the writes to the counters
themselves haven't yet made it.
The write to the control register will take effect before the next
exception return, which is fine for what we want.
Will
From: Will Deacon <hidden> Date: 2011-03-21 18:22:04
Hi Jean,
quoted
On Wed, Mar 16, 2011 at 4:38 PM, Will Deacon [off-list ref] wrote:
quoted
The ARMv7 architecture does not guarantee that effects from co-processor
writes are immediately visible to following instructions.
This patch adds two isbs to the ARMv7 perf code:
(1) Immediately after selecting an event register, so that the PMU state
? ?following this instruction is consistent with the new event.
Ok
quoted
(2) Immediately before writing to the PMCR, so that any previous writes
? ?to the PMU have taken effect before (typically) enabling the
? ?counters.
Should the isb come _after_ the cp15 instruction so that the current
access is actually performed?
No. We want to ensure that the _other_ PMU registers are up-to-date before
playing with the control register, otherwise we could end up in a horrible
situation where we enable all the counters, but the writes to the counters
themselves haven't yet made it.
The write to the control register will take effect before the next
exception return, which is fine for what we want.
I'd like to submit this to the patch system if you're happy with it.
Are you OK with the barrier coming before the write to the PMCR?
Cheers,
Will
From: Will Deacon <hidden> Date: 2011-03-23 13:39:22
Hi Jean,
On Wed, Mar 16, 2011 at 4:38 PM, Will Deacon [off-list ref] wrote:
quoted
ARMv7 dictates that the interrupt-enable and count-enable registers for
each PMU counter are UNKNOWN following core reset.
Great! Is this development driven by actual issues or by precaution?
quoted
This patch adds an arch_initcall to the ARMv7 perf events backend which
disables the counters on each CPU prior to setting the Enable bit in the
PMCR.
Also the function rename is a good thing.
quoted
Cc: Jean Pihet <redacted>
Signed-off-by: Will Deacon <redacted>
Acked-by: Jean Pihet <redacted>
I don't think this patch is safe for combined v6/v7 kernels because the
arch_initcall will try to poke the v7 PMU regardless of whether or not
it exists. I'll try and rework something and send another version to the
list.
I've removed it from the patch system but left the isb patch there
because that is fine as it is.
Stay tuned...
Will