Skip to contentSkip to conversation

OProfile for Cell: Initial profiling support -- new patch

RFC PATCH In review Maynard Johnson 2 participants 4 messages Nov 15, 2006 – Nov 16, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 OProfile for Cell: Initial profiling support -- new patch

arch/powerpc/configs/cell_defconfig +2 -1
Index: linux-2.6.18/arch/powerpc/configs/cell_defconfig
===================================================================
@@ -1099,7 +1099,8 @@
 #
 # Instrumentation Support
 #
-# CONFIG_PROFILING is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
 # CONFIG_KPROBES is not set
 
 #
arch/powerpc/kernel/cputable.c +3 -0
Index: linux-2.6.18/arch/powerpc/kernel/cputable.c
===================================================================
@@ -304,6 +304,9 @@
 			PPC_FEATURE_SMT,
 		.icache_bsize		= 128,
 		.dcache_bsize		= 128,
+		.num_pmcs		= 4,
+		.oprofile_cpu_type	= "ppc64/cell-be",
+		.oprofile_type		= PPC_OPROFILE_CELL,
 		.platform		= "ppc-cell-be",
 	},
 	{	/* PA Semi PA6T */
arch/powerpc/oprofile/common.c +5 -0
Index: linux-2.6.18/arch/powerpc/oprofile/common.c
===================================================================
@@ -141,6 +141,11 @@
 
 	switch (cur_cpu_spec->oprofile_type) {
 #ifdef CONFIG_PPC64
+#ifdef CONFIG_PPC_CELL
+		case PPC_OPROFILE_CELL:
+			model = &op_model_cell;
+			break;
+#endif
 		case PPC_OPROFILE_RS64:
 			model = &op_model_rs64;
 			break;
arch/powerpc/oprofile/Makefile +1 -0
Index: linux-2.6.18/arch/powerpc/oprofile/Makefile
===================================================================
@@ -11,6 +11,7 @@
 		timer_int.o )
 
 oprofile-y := $(DRIVER_OBJS) common.o backtrace.o
+oprofile-$(CONFIG_PPC_CELL) += op_model_cell.o
 oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o
 oprofile-$(CONFIG_FSL_BOOKE) += op_model_fsl_booke.o
 oprofile-$(CONFIG_6xx) += op_model_7450.o
arch/powerpc/oprofile/op_model_cell.c new file +717 -0

717 lines not on this page · raw message

arch/powerpc/platforms/cell/cbe_regs.c +12 -0
Index: linux-2.6.18/arch/powerpc/platforms/cell/cbe_regs.c
===================================================================
@@ -132,6 +132,18 @@
 }
 EXPORT_SYMBOL_GPL(cbe_get_cpu_mic_tm_regs);
 
+/* FIXME
+ * This is little more than a stub at the moment.  It should be
+ * fleshed out so that it works for both SMT and non-SMT, no
+ * matter if the passed cpu is odd or even. 
+ * For SMT enabled, returns 0 for even-numbered cpu; otherwise 1.
+ * For SMT disabled, returns 0 for all cpus.
+ */
+u32 cbe_get_hw_thread_id(int cpu)
+{
+	return (cpu & 1);
+}
+EXPORT_SYMBOL_GPL(cbe_get_hw_thread_id);
 
 void __init cbe_regs_init(void)
 {
include/asm-powerpc/cell-pmu.h +17 -0
Index: linux-2.6.18/include/asm-powerpc/cell-pmu.h
===================================================================
@@ -92,4 +92,21 @@
 extern u32  cbe_query_pm_interrupts(u32 cpu);
 extern u32  cbe_clear_pm_interrupts(u32 cpu);
 
+/* Utility functions, macros */
+extern u32 cbe_get_hw_thread_id(int cpu);
+
+#define cbe_cpu_to_node(cpu) ((cpu) >> 1)
+
+#define CBE_COUNT_SUPERVISOR_MODE       0
+#define CBE_COUNT_HYPERVISOR_MODE       1
+#define CBE_COUNT_PROBLEM_MODE          2
+#define CBE_COUNT_ALL_MODES             3
+
+/* Macros for the pm07_control registers. */
+#define PM07_CTR_INPUT_MUX(x)                    ((((x) & 1) << 26) & 0x3f)
+#define PM07_CTR_INPUT_CONTROL(x)                (((x) & 1) << 25)
+#define PM07_CTR_POLARITY(x)                     (((x) & 1) << 24)
+#define PM07_CTR_COUNT_CYCLES(x)                 (((x) & 1) << 23)
+#define PM07_CTR_ENABLE(x)                       (((x) & 1) << 22)
+
 #endif /* __ASM_CELL_PMU_H__ */
include/asm-powerpc/cputable.h +1 -0
Index: linux-2.6.18/include/asm-powerpc/cputable.h
===================================================================
@@ -45,6 +45,7 @@
 	PPC_OPROFILE_POWER4 = 2,
 	PPC_OPROFILE_G4 = 3,
 	PPC_OPROFILE_BOOKE = 4,
+	PPC_OPROFILE_CELL = 5,
 };
 
 struct cpu_spec {
include/asm-powerpc/oprofile_impl.h +1 -0
Index: linux-2.6.18/include/asm-powerpc/oprofile_impl.h
===================================================================
@@ -54,6 +54,7 @@
 extern struct op_powerpc_model op_model_rs64;
 extern struct op_powerpc_model op_model_power4;
 extern struct op_powerpc_model op_model_7450;
+extern struct op_powerpc_model op_model_cell;
 
 #ifndef CONFIG_FSL_BOOKE
 
#1 lore raw

Sorry for the spam, but I forgot to add the header into the patch, which includes the description of the patch, along with signed-off lines. I'll repost.

[snip]

Maynard Johnson
IBM LTC Power Linux Toolchain

#2 lore raw

RFC PATCH 1/1 OProfile for Cell: Initial profiling support -- corrected patch with header

In reply to Maynard Johnson

Add PPU event-based and cycle-based profiling support to Oprofile for Cell.

Oprofile is expected to collect data on all CPUs simultaneously. However, there is one set of performance counters per node. There are two hardware threads or virtual CPUs on each node. Hence, OProfile must multiplex in time the performance counter collection on the two virtual CPUs.

The multiplexing of the performance counters is done by a virtual counter routine. Initially, the counters are configured to collect data on the even CPUs in the system, one CPU per node. In order to capture the PC for the virtual CPU when the performance counter interrupt occurs (the specified number of events between samples has occurred), the even processors are configured to handle the performance counter interrupts for their node. The virtual counter routine is called via a kernel timer after the virtual sample time. The routine stops the counters, saves the current counts, loads the last counts for the other virtual CPU on the node, sets interrupts to be handled by the other virtual CPU and restarts the counters, the virtual timer routine is scheduled to run again. The virtual sample time is kept relatively small to make sure sampling occurs on both CPUs on the node with a relatively small granularity. Whenever the counters overflow, the performance counter interrupt is called to collect the PC for the CPU where data is being collected.

The oprofile driver relies on a firmware RTAS call to setup the debug bus to route the desired signals to the performance counter hardware to be counted. The RTAS call must set the routing registers appropriately in each of the islands to pass the signals down the debug bus as well as routing the signals from a particular island onto the bus. There is a second firmware RTAS call to reset the debug bus to the non pass thru state when the counters are not in use.

arch/powerpc/configs/cell_defconfig +2 -1
Index: linux-2.6.18/arch/powerpc/configs/cell_defconfig
===================================================================
@@ -1099,7 +1099,8 @@
 #
 # Instrumentation Support
 #
-# CONFIG_PROFILING is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
 # CONFIG_KPROBES is not set
 
 #
arch/powerpc/kernel/cputable.c +3 -0
Index: linux-2.6.18/arch/powerpc/kernel/cputable.c
===================================================================
@@ -304,6 +304,9 @@
 			PPC_FEATURE_SMT,
 		.icache_bsize		= 128,
 		.dcache_bsize		= 128,
+		.num_pmcs		= 4,
+		.oprofile_cpu_type	= "ppc64/cell-be",
+		.oprofile_type		= PPC_OPROFILE_CELL,
 		.platform		= "ppc-cell-be",
 	},
 	{	/* PA Semi PA6T */
arch/powerpc/oprofile/common.c +5 -0
Index: linux-2.6.18/arch/powerpc/oprofile/common.c
===================================================================
@@ -141,6 +141,11 @@
 
 	switch (cur_cpu_spec->oprofile_type) {
 #ifdef CONFIG_PPC64
+#ifdef CONFIG_PPC_CELL
+		case PPC_OPROFILE_CELL:
+			model = &op_model_cell;
+			break;
+#endif
 		case PPC_OPROFILE_RS64:
 			model = &op_model_rs64;
 			break;
arch/powerpc/oprofile/Makefile +1 -0
Index: linux-2.6.18/arch/powerpc/oprofile/Makefile
===================================================================
@@ -11,6 +11,7 @@
 		timer_int.o )
 
 oprofile-y := $(DRIVER_OBJS) common.o backtrace.o
+oprofile-$(CONFIG_PPC_CELL) += op_model_cell.o
 oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o
 oprofile-$(CONFIG_FSL_BOOKE) += op_model_fsl_booke.o
 oprofile-$(CONFIG_6xx) += op_model_7450.o
arch/powerpc/oprofile/op_model_cell.c new file +717 -0

717 lines not on this page · raw message

arch/powerpc/platforms/cell/cbe_regs.c +12 -0
Index: linux-2.6.18/arch/powerpc/platforms/cell/cbe_regs.c
===================================================================
@@ -132,6 +132,18 @@
 }
 EXPORT_SYMBOL_GPL(cbe_get_cpu_mic_tm_regs);
 
+/* FIXME
+ * This is little more than a stub at the moment.  It should be
+ * fleshed out so that it works for both SMT and non-SMT, no
+ * matter if the passed cpu is odd or even. 
+ * For SMT enabled, returns 0 for even-numbered cpu; otherwise 1.
+ * For SMT disabled, returns 0 for all cpus.
+ */
+u32 cbe_get_hw_thread_id(int cpu)
+{
+	return (cpu & 1);
+}
+EXPORT_SYMBOL_GPL(cbe_get_hw_thread_id);
 
 void __init cbe_regs_init(void)
 {
include/asm-powerpc/cell-pmu.h +17 -0
Index: linux-2.6.18/include/asm-powerpc/cell-pmu.h
===================================================================
@@ -92,4 +92,21 @@
 extern u32  cbe_query_pm_interrupts(u32 cpu);
 extern u32  cbe_clear_pm_interrupts(u32 cpu);
 
+/* Utility functions, macros */
+extern u32 cbe_get_hw_thread_id(int cpu);
+
+#define cbe_cpu_to_node(cpu) ((cpu) >> 1)
+
+#define CBE_COUNT_SUPERVISOR_MODE       0
+#define CBE_COUNT_HYPERVISOR_MODE       1
+#define CBE_COUNT_PROBLEM_MODE          2
+#define CBE_COUNT_ALL_MODES             3
+
+/* Macros for the pm07_control registers. */
+#define PM07_CTR_INPUT_MUX(x)                    ((((x) & 1) << 26) & 0x3f)
+#define PM07_CTR_INPUT_CONTROL(x)                (((x) & 1) << 25)
+#define PM07_CTR_POLARITY(x)                     (((x) & 1) << 24)
+#define PM07_CTR_COUNT_CYCLES(x)                 (((x) & 1) << 23)
+#define PM07_CTR_ENABLE(x)                       (((x) & 1) << 22)
+
 #endif /* __ASM_CELL_PMU_H__ */
include/asm-powerpc/cputable.h +1 -0
Index: linux-2.6.18/include/asm-powerpc/cputable.h
===================================================================
@@ -45,6 +45,7 @@
 	PPC_OPROFILE_POWER4 = 2,
 	PPC_OPROFILE_G4 = 3,
 	PPC_OPROFILE_BOOKE = 4,
+	PPC_OPROFILE_CELL = 5,
 };
 
 struct cpu_spec {
include/asm-powerpc/oprofile_impl.h +1 -0
Index: linux-2.6.18/include/asm-powerpc/oprofile_impl.h
===================================================================
@@ -54,6 +54,7 @@
 extern struct op_powerpc_model op_model_rs64;
 extern struct op_powerpc_model op_model_power4;
 extern struct op_powerpc_model op_model_7450;
+extern struct op_powerpc_model op_model_cell;
 
 #ifndef CONFIG_FSL_BOOKE
 
#3 lore raw
In reply to Maynard Johnson
Quoted 7 lines · Maynard Johnson
arch/powerpc/oprofile/op_model_cell.c new file +6 -0
+/* This function is called once for all cpus combined */
+static void
+cell_reg_setup(struct op_counter_config *ctr,
+	       struct op_system_config *sys, int num_ctrs)
+{
[SNIP]
+	for (i = 0; i < num_ctrs; ++i) {

arch/powerpc/oprofile/op_model_cell.c line 499

Quoted 10 lines
arch/powerpc/oprofile/op_model_cell.c new file +10 -0
+
+		if ((ctr[i].event >= 2100) && (ctr[i].event <= 2111))
+			pmc_cntrl[1][i].evnts = ctr[i].event + 19;
+		else if (ctr[i].event == 2203)
+			pmc_cntrl[1][i].evnts = ctr[i].event;
+		else if ((ctr[i].event >= 2200) && (ctr[i].event <= 2215))
+			pmc_cntrl[1][i].evnts = ctr[i].event + 16;
+		else
+			pmc_cntrl[1][i].evnts = ctr[i].event;
+

I think the previous code would be more readable with a switch() statement.

	switch (ctr[i].event) {
	case 2100 ... 2111:
		pmc_cntrl[1][i] = ctr[i].event + 19;
		break;
	case 2200 ... 2202:
	case 2204 ... 2215:
		pmc_cntrl[1][i] = ctr[i].event + 16;
		break;
	default:
		pmc_cntrl[1][i] = ctr[i].event;
	}

- Heikki