Patchwork [1/2] powerpc: G4 oprofile: variable number of counters

login
register
mail settings
Submitter Octavian Purdila
Date Jan. 6, 2009, 12:55 p.m.
Message ID <1231246535-13151-2-git-send-email-opurdila@ixiacom.com>
Download mbox | patch
Permalink /patch/16801/
State Changes Requested
Delegated to: Benjamin Herrenschmidt
Headers show

Comments

Octavian Purdila - Jan. 6, 2009, 12:55 p.m.
For ppc750 processors which use 4 performance counters instead of the
6 G4 uses but otherwise is compatible with G4.

Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
---
 arch/powerpc/oprofile/op_model_7450.c |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)
Benjamin Herrenschmidt - Feb. 4, 2009, 5:22 a.m.
On Tue, 2009-01-06 at 14:55 +0200, Octavian Purdila wrote:
> For ppc750 processors which use 4 performance counters instead of the
> 6 G4 uses but otherwise is compatible with G4.
> 
> Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
> ---
>  arch/powerpc/oprofile/op_model_7450.c |   21 +++++++++++----------
>  1 files changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/powerpc/oprofile/op_model_7450.c b/arch/powerpc/oprofile/op_model_7450.c
> index cc599eb..97348f5 100644
> --- a/arch/powerpc/oprofile/op_model_7450.c
> +++ b/arch/powerpc/oprofile/op_model_7450.c
> @@ -29,7 +29,7 @@
>  static unsigned long reset_value[OP_MAX_COUNTER];
>  
>  static int oprofile_running;
> -static u32 mmcr0_val, mmcr1_val, mmcr2_val;
> +static u32 mmcr0_val, mmcr1_val, mmcr2_val, ctrs;

This may be static but it's still a global scope as far as kernel
symbols are concerned. Care to give it a slightly better name ? num_pmcs
would probably be already more telling.

Cheers,
Ben.
Octavian Purdila - Feb. 24, 2009, 12:09 p.m.
>>  static int oprofile_running;
>> -static u32 mmcr0_val, mmcr1_val, mmcr2_val;
>> +static u32 mmcr0_val, mmcr1_val, mmcr2_val, ctrs;
>
>This may be static but it's still a global scope as far as kernel
>symbols are concerned. Care to give it a slightly better name ? num_pmcs
>would probably be already more telling.

Sure. v2 will follow, with s/ctrs/num_pmcs/.

Thanks,
tavi

Patch

diff --git a/arch/powerpc/oprofile/op_model_7450.c b/arch/powerpc/oprofile/op_model_7450.c
index cc599eb..97348f5 100644
--- a/arch/powerpc/oprofile/op_model_7450.c
+++ b/arch/powerpc/oprofile/op_model_7450.c
@@ -29,7 +29,7 @@ 
 static unsigned long reset_value[OP_MAX_COUNTER];
 
 static int oprofile_running;
-static u32 mmcr0_val, mmcr1_val, mmcr2_val;
+static u32 mmcr0_val, mmcr1_val, mmcr2_val, ctrs;
 
 #define MMCR0_PMC1_SHIFT	6
 #define MMCR0_PMC2_SHIFT	0
@@ -88,13 +88,12 @@  static int fsl7450_cpu_setup(struct op_counter_config *ctr)
 
 	mtspr(SPRN_MMCR0, mmcr0_val);
 	mtspr(SPRN_MMCR1, mmcr1_val);
-	mtspr(SPRN_MMCR2, mmcr2_val);
+	if (ctrs > 4)
+		mtspr(SPRN_MMCR2, mmcr2_val);
 
 	return 0;
 }
 
-#define NUM_CTRS 6
-
 /* Configures the global settings for the countes on all CPUs. */
 static int fsl7450_reg_setup(struct op_counter_config *ctr,
 			     struct op_system_config *sys,
@@ -102,12 +101,13 @@  static int fsl7450_reg_setup(struct op_counter_config *ctr,
 {
 	int i;
 
+	ctrs = num_ctrs;
 	/* Our counters count up, and "count" refers to
 	 * how much before the next interrupt, and we interrupt
 	 * on overflow.  So we calculate the starting value
 	 * which will give us "count" until overflow.
 	 * Then we set the events on the enabled counters */
-	for (i = 0; i < NUM_CTRS; ++i)
+	for (i = 0; i < num_ctrs; ++i)
 		reset_value[i] = 0x80000000UL - ctr[i].count;
 
 	/* Set events for Counters 1 & 2 */
@@ -123,9 +123,10 @@  static int fsl7450_reg_setup(struct op_counter_config *ctr,
 
 	/* Set events for Counters 3-6 */
 	mmcr1_val = mmcr1_event3(ctr[2].event)
-		| mmcr1_event4(ctr[3].event)
-		| mmcr1_event5(ctr[4].event)
-		| mmcr1_event6(ctr[5].event);
+		| mmcr1_event4(ctr[3].event);
+	if (num_ctrs > 4)
+		mmcr1_val |= mmcr1_event5(ctr[4].event)
+			| mmcr1_event6(ctr[5].event);
 
 	mmcr2_val = 0;
 
@@ -139,7 +140,7 @@  static int fsl7450_start(struct op_counter_config *ctr)
 
 	mtmsr(mfmsr() | MSR_PMM);
 
-	for (i = 0; i < NUM_CTRS; ++i) {
+	for (i = 0; i < ctrs; ++i) {
 		if (ctr[i].enabled)
 			classic_ctr_write(i, reset_value[i]);
 		else
@@ -184,7 +185,7 @@  static void fsl7450_handle_interrupt(struct pt_regs *regs,
 	pc = mfspr(SPRN_SIAR);
 	is_kernel = is_kernel_addr(pc);
 
-	for (i = 0; i < NUM_CTRS; ++i) {
+	for (i = 0; i < ctrs; ++i) {
 		val = classic_ctr_read(i);
 		if (val < 0) {
 			if (oprofile_running && ctr[i].enabled) {