Merge pmc.[ch]

David Gibson david at gibson.dropbear.id.au
Wed Oct 19 14:53:32 EST 2005


Merge ppc64 pmc.[ch] with ppc32 perfmon.[ch]

This patches the ppc32 and ppc64 versions of the headers and .c files
with helper functions for manipulating the performance counting
hardware.  As a side effect, it removes use of the term "perfmon" from
ppc32, thus avoiding confusion with the unrelated performance counter
interface from HP Labs also called "perfmon".

Built, but not booted, for g5, pSeries, iSeries, and 32-bit Powermac
with both ARCH=powerpc and ARCH=ppc{,64} as appropriate.

Signed-off-by: David Gibson <dwg at au1.ibm.com>

Index: working-2.6/include/asm-powerpc/pmc.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ working-2.6/include/asm-powerpc/pmc.h	2005-10-19 14:25:42.000000000 +1000
@@ -0,0 +1,46 @@
+/*
+ * pmc.h
+ * Copyright (C) 2004  David Gibson, IBM Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+#ifndef _POWERPC_PMC_H
+#define _POWERPC_PMC_H
+
+#include <asm/ptrace.h>
+
+typedef void (*perf_irq_t)(struct pt_regs *);
+
+int reserve_pmc_hardware(perf_irq_t new_perf_irq);
+void release_pmc_hardware(void);
+
+#ifdef CONFIG_PPC64
+void power4_enable_pmcs(void);
+#endif
+
+#ifdef CONFIG_FSL_BOOKE
+void init_pmc_stop(int ctr);
+void set_pmc_event(int ctr, int event);
+void set_pmc_user_kernel(int ctr, int user, int kernel);
+void set_pmc_marked(int ctr, int mark0, int mark1);
+void pmc_start_ctr(int ctr, int enable);
+void pmc_start_ctrs(int enable);
+void pmc_stop_ctrs(void);
+void dump_pmcs(void);
+
+extern struct op_powerpc_model op_model_fsl_booke;
+#endif
+
+#endif /* _POWERPC_PMC_H */
Index: working-2.6/include/asm-ppc64/pmc.h
===================================================================
--- working-2.6.orig/include/asm-ppc64/pmc.h	2005-09-07 15:13:26.000000000 +1000
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,31 +0,0 @@
-/*
- * pmc.h
- * Copyright (C) 2004  David Gibson, IBM Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-#ifndef _PPC64_PMC_H
-#define _PPC64_PMC_H
-
-#include <asm/ptrace.h>
-
-typedef void (*perf_irq_t)(struct pt_regs *);
-
-int reserve_pmc_hardware(perf_irq_t new_perf_irq);
-void release_pmc_hardware(void);
-
-void power4_enable_pmcs(void);
-
-#endif /* _PPC64_PMC_H */
Index: working-2.6/arch/powerpc/kernel/pmc.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ working-2.6/arch/powerpc/kernel/pmc.c	2005-10-19 14:25:42.000000000 +1000
@@ -0,0 +1,112 @@
+/*
+ *  arch/powerpc/kernel/pmc.c
+ *
+ *  Copyright (C) 2004 David Gibson, IBM Corporation.
+ *  Includes code formerly from arch/ppc/kernel/perfmon.c:
+ *    Author: Andy Fleming
+ *    Copyright (c) 2004 Freescale Semiconductor, Inc
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version
+ *  2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/config.h>
+#include <linux/errno.h>
+#include <linux/spinlock.h>
+#include <linux/module.h>
+
+#include <asm/processor.h>
+#include <asm/pmc.h>
+
+#if defined(CONFIG_FSL_BOOKE) && !defined(CONFIG_E200)
+static void dummy_perf(struct pt_regs *regs)
+{
+	unsigned int pmgc0 = mfpmr(PMRN_PMGC0);
+
+	pmgc0 &= ~PMGC0_PMIE;
+	mtpmr(PMRN_PMGC0, pmgc0);
+}
+#elif defined(CONFIG_PPC64) || defined(CONFIG_6xx)
+
+#ifndef MMCR0_PMAO
+#define MMCR0_PMAO	0
+#endif
+
+/* Ensure exceptions are disabled */
+static void dummy_perf(struct pt_regs *regs)
+{
+	unsigned int mmcr0 = mfspr(SPRN_MMCR0);
+
+	mmcr0 &= ~(MMCR0_PMXE|MMCR0_PMAO);
+	mtspr(SPRN_MMCR0, mmcr0);
+}
+#else
+static void dummy_perf(struct pt_regs *regs)
+{
+}
+#endif
+
+static DEFINE_SPINLOCK(pmc_owner_lock);
+static void *pmc_owner_caller; /* mostly for debugging */
+perf_irq_t perf_irq = dummy_perf;
+
+int reserve_pmc_hardware(perf_irq_t new_perf_irq)
+{
+	int err = 0;
+
+	spin_lock(&pmc_owner_lock);
+
+	if (pmc_owner_caller) {
+		printk(KERN_WARNING "reserve_pmc_hardware: "
+		       "PMC hardware busy (reserved by caller %p)\n",
+		       pmc_owner_caller);
+		err = -EBUSY;
+		goto out;
+	}
+
+	pmc_owner_caller = __builtin_return_address(0);
+	perf_irq = new_perf_irq ? : dummy_perf;
+
+ out:
+	spin_unlock(&pmc_owner_lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(reserve_pmc_hardware);
+
+void release_pmc_hardware(void)
+{
+	spin_lock(&pmc_owner_lock);
+
+	WARN_ON(! pmc_owner_caller);
+
+	pmc_owner_caller = NULL;
+	perf_irq = dummy_perf;
+
+	spin_unlock(&pmc_owner_lock);
+}
+EXPORT_SYMBOL_GPL(release_pmc_hardware);
+
+#ifdef CONFIG_PPC64
+void power4_enable_pmcs(void)
+{
+	unsigned long hid0;
+
+	hid0 = mfspr(SPRN_HID0);
+	hid0 |= 1UL << (63 - 20);
+
+	/* POWER4 requires the following sequence */
+	asm volatile(
+		"sync\n"
+		"mtspr     %1, %0\n"
+		"mfspr     %0, %1\n"
+		"mfspr     %0, %1\n"
+		"mfspr     %0, %1\n"
+		"mfspr     %0, %1\n"
+		"mfspr     %0, %1\n"
+		"mfspr     %0, %1\n"
+		"isync" : "=&r" (hid0) : "i" (SPRN_HID0), "0" (hid0):
+		"memory");
+}
+#endif /* CONFIG_PPC64 */
Index: working-2.6/arch/ppc/kernel/perfmon.c
===================================================================
--- working-2.6.orig/arch/ppc/kernel/perfmon.c	2005-10-19 14:16:40.000000000 +1000
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,96 +0,0 @@
-/* kernel/perfmon.c
- * PPC 32 Performance Monitor Infrastructure
- *
- * Author: Andy Fleming
- * Copyright (c) 2004 Freescale Semiconductor, Inc
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; either version
- *  2 of the License, or (at your option) any later version.
- */
-
-#include <linux/errno.h>
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/stddef.h>
-#include <linux/unistd.h>
-#include <linux/ptrace.h>
-#include <linux/slab.h>
-#include <linux/user.h>
-#include <linux/a.out.h>
-#include <linux/interrupt.h>
-#include <linux/config.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/prctl.h>
-
-#include <asm/pgtable.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <asm/io.h>
-#include <asm/reg.h>
-#include <asm/xmon.h>
-
-/* A lock to regulate grabbing the interrupt */
-DEFINE_SPINLOCK(perfmon_lock);
-
-#if defined (CONFIG_FSL_BOOKE) && !defined (CONFIG_E200)
-static void dummy_perf(struct pt_regs *regs)
-{
-	unsigned int pmgc0 = mfpmr(PMRN_PMGC0);
-
-	pmgc0 &= ~PMGC0_PMIE;
-	mtpmr(PMRN_PMGC0, pmgc0);
-}
-
-#elif defined(CONFIG_6xx)
-/* Ensure exceptions are disabled */
-static void dummy_perf(struct pt_regs *regs)
-{
-	unsigned int mmcr0 = mfspr(SPRN_MMCR0);
-
-	mmcr0 &= ~MMCR0_PMXE;
-	mtspr(SPRN_MMCR0, mmcr0);
-}
-#else
-static void dummy_perf(struct pt_regs *regs)
-{
-}
-#endif
-
-void (*perf_irq)(struct pt_regs *) = dummy_perf;
-
-/* Grab the interrupt, if it's free.
- * Returns 0 on success, -1 if the interrupt is taken already */
-int reserve_pmc_hardware(void (*handler)(struct pt_regs *))
-{
-	int err = 0;
-
-	spin_lock(&perfmon_lock);
-
-	if (perf_irq == dummy_perf)
-		perf_irq = handler;
-	else {
-		pr_info("perfmon irq already handled by %p\n", perf_irq);
-		err = -EBUSY;
-	}
-
-	spin_unlock(&perfmon_lock);
-
-	return err;
-}
-
-void release_pmc_hardware(void)
-{
-	spin_lock(&perfmon_lock);
-
-	perf_irq = dummy_perf;
-
-	spin_unlock(&perfmon_lock);
-}
-
-EXPORT_SYMBOL(perf_irq);
-EXPORT_SYMBOL(reserve_pmc_hardware);
-EXPORT_SYMBOL(release_pmc_hardware);
Index: working-2.6/arch/ppc64/kernel/pmc.c
===================================================================
--- working-2.6.orig/arch/ppc64/kernel/pmc.c	2005-10-19 14:16:41.000000000 +1000
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,88 +0,0 @@
-/*
- *  linux/arch/ppc64/kernel/pmc.c
- *
- *  Copyright (C) 2004 David Gibson, IBM Corporation.
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; either version
- *  2 of the License, or (at your option) any later version.
- */
-
-#include <linux/config.h>
-#include <linux/errno.h>
-#include <linux/spinlock.h>
-#include <linux/module.h>
-
-#include <asm/processor.h>
-#include <asm/pmc.h>
-
-/* Ensure exceptions are disabled */
-static void dummy_perf(struct pt_regs *regs)
-{
-	unsigned int mmcr0 = mfspr(SPRN_MMCR0);
-
-	mmcr0 &= ~(MMCR0_PMXE|MMCR0_PMAO);
-	mtspr(SPRN_MMCR0, mmcr0);
-}
-
-static DEFINE_SPINLOCK(pmc_owner_lock);
-static void *pmc_owner_caller; /* mostly for debugging */
-perf_irq_t perf_irq = dummy_perf;
-
-int reserve_pmc_hardware(perf_irq_t new_perf_irq)
-{
-	int err = 0;
-
-	spin_lock(&pmc_owner_lock);
-
-	if (pmc_owner_caller) {
-		printk(KERN_WARNING "reserve_pmc_hardware: "
-		       "PMC hardware busy (reserved by caller %p)\n",
-		       pmc_owner_caller);
-		err = -EBUSY;
-		goto out;
-	}
-
-	pmc_owner_caller = __builtin_return_address(0);
-	perf_irq = new_perf_irq ? : dummy_perf;
-
- out:
-	spin_unlock(&pmc_owner_lock);
-	return err;
-}
-EXPORT_SYMBOL_GPL(reserve_pmc_hardware);
-
-void release_pmc_hardware(void)
-{
-	spin_lock(&pmc_owner_lock);
-
-	WARN_ON(! pmc_owner_caller);
-
-	pmc_owner_caller = NULL;
-	perf_irq = dummy_perf;
-
-	spin_unlock(&pmc_owner_lock);
-}
-EXPORT_SYMBOL_GPL(release_pmc_hardware);
-
-void power4_enable_pmcs(void)
-{
-	unsigned long hid0;
-
-	hid0 = mfspr(SPRN_HID0);
-	hid0 |= 1UL << (63 - 20);
-
-	/* POWER4 requires the following sequence */
-	asm volatile(
-		"sync\n"
-		"mtspr     %1, %0\n"
-		"mfspr     %0, %1\n"
-		"mfspr     %0, %1\n"
-		"mfspr     %0, %1\n"
-		"mfspr     %0, %1\n"
-		"mfspr     %0, %1\n"
-		"mfspr     %0, %1\n"
-		"isync" : "=&r" (hid0) : "i" (SPRN_HID0), "0" (hid0):
-		"memory");
-}
Index: working-2.6/include/asm-ppc/perfmon.h
===================================================================
--- working-2.6.orig/include/asm-ppc/perfmon.h	2005-10-19 14:16:42.000000000 +1000
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,22 +0,0 @@
-#ifndef __PERFMON_H
-#define __PERFMON_H
-
-extern void (*perf_irq)(struct pt_regs *);
-
-int reserve_pmc_hardware(void (*handler)(struct pt_regs *));
-void release_pmc_hardware(void);
-
-#ifdef CONFIG_FSL_BOOKE
-void init_pmc_stop(int ctr);
-void set_pmc_event(int ctr, int event);
-void set_pmc_user_kernel(int ctr, int user, int kernel);
-void set_pmc_marked(int ctr, int mark0, int mark1);
-void pmc_start_ctr(int ctr, int enable);
-void pmc_start_ctrs(int enable);
-void pmc_stop_ctrs(void);
-void dump_pmcs(void);
-
-extern struct op_powerpc_model op_model_fsl_booke;
-#endif
-
-#endif /* __PERFMON_H */
Index: working-2.6/arch/powerpc/kernel/Makefile
===================================================================
--- working-2.6.orig/arch/powerpc/kernel/Makefile	2005-10-19 14:16:38.000000000 +1000
+++ working-2.6/arch/powerpc/kernel/Makefile	2005-10-19 14:25:42.000000000 +1000
@@ -11,7 +11,7 @@
 endif
 
 obj-y				:= semaphore.o cputable.o ptrace.o syscalls.o \
-				   signal_32.o
+				   signal_32.o pmc.o
 obj-$(CONFIG_PPC64)		+= binfmt_elf32.o sys_ppc32.o
 obj-$(CONFIG_ALTIVEC)		+= vecemu.o vector.o
 obj-$(CONFIG_POWER4)		+= idle_power4.o
Index: working-2.6/arch/ppc/kernel/Makefile
===================================================================
--- working-2.6.orig/arch/ppc/kernel/Makefile	2005-10-19 14:16:39.000000000 +1000
+++ working-2.6/arch/ppc/kernel/Makefile	2005-10-19 14:25:42.000000000 +1000
@@ -15,7 +15,7 @@
 obj-y				:= entry.o traps.o irq.o idle.o time.o misc.o \
 					process.o align.o \
 					setup.o \
-					ppc_htab.o perfmon.o
+					ppc_htab.o
 obj-$(CONFIG_6xx)		+= l2cr.o cpu_setup_6xx.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= swsusp.o
 obj-$(CONFIG_POWER4)		+= cpu_setup_power4.o
@@ -38,7 +38,7 @@
 
 else
 obj-y				:= irq.o idle.o time.o \
-					align.o perfmon.o
+					align.o
 obj-$(CONFIG_6xx)		+= l2cr.o cpu_setup_6xx.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= swsusp.o
 obj-$(CONFIG_MODULES)		+= module.o
Index: working-2.6/arch/ppc64/kernel/Makefile
===================================================================
--- working-2.6.orig/arch/ppc64/kernel/Makefile	2005-10-19 14:16:40.000000000 +1000
+++ working-2.6/arch/ppc64/kernel/Makefile	2005-10-19 14:25:42.000000000 +1000
@@ -17,7 +17,7 @@
 			udbg.o ioctl32.o \
 			ptrace32.o rtc.o \
 			cpu_setup_power4.o \
-			iommu.o sysfs.o vdso.o pmc.o firmware.o
+			iommu.o sysfs.o vdso.o firmware.o
 obj-y += vdso32/ vdso64/
 
 pci-obj-$(CONFIG_PPC_MULTIPLATFORM)	+= pci_dn.o pci_direct_iommu.o
Index: working-2.6/arch/powerpc/kernel/traps.c
===================================================================
--- working-2.6.orig/arch/powerpc/kernel/traps.c	2005-10-19 14:16:39.000000000 +1000
+++ working-2.6/arch/powerpc/kernel/traps.c	2005-10-19 14:25:42.000000000 +1000
@@ -40,9 +40,9 @@
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/xmon.h>
+#include <asm/pmc.h>
 #ifdef CONFIG_PPC32
 #include <asm/reg.h>
-#include <asm/perfmon.h>
 #endif
 #ifdef CONFIG_PMAC_BACKLIGHT
 #include <asm/backlight.h>
@@ -51,7 +51,6 @@
 #include <asm/firmware.h>
 #include <asm/processor.h>
 #include <asm/systemcfg.h>
-#include <asm/pmc.h>
 #endif
 
 #ifdef CONFIG_PPC64	/* XXX */
Index: working-2.6/arch/powerpc/oprofile/common.c
===================================================================
--- working-2.6.orig/arch/powerpc/oprofile/common.c	2005-10-19 14:16:39.000000000 +1000
+++ working-2.6/arch/powerpc/oprofile/common.c	2005-10-19 14:25:42.000000000 +1000
@@ -22,11 +22,7 @@
 #include <linux/errno.h>
 #include <asm/ptrace.h>
 #include <asm/system.h>
-#ifdef __powerpc64__
 #include <asm/pmc.h>
-#else /* __powerpc64__ */
-#include <asm/perfmon.h>
-#endif /* __powerpc64__ */
 #include <asm/cputable.h>
 #include <asm/oprofile_impl.h>
 
Index: working-2.6/arch/powerpc/oprofile/op_model_fsl_booke.c
===================================================================
--- working-2.6.orig/arch/powerpc/oprofile/op_model_fsl_booke.c	2005-10-19 14:16:39.000000000 +1000
+++ working-2.6/arch/powerpc/oprofile/op_model_fsl_booke.c	2005-10-19 14:25:42.000000000 +1000
@@ -24,7 +24,7 @@
 #include <asm/cputable.h>
 #include <asm/reg_booke.h>
 #include <asm/page.h>
-#include <asm/perfmon.h>
+#include <asm/pmc.h>
 #include <asm/oprofile_impl.h>
 
 static unsigned long reset_value[OP_MAX_COUNTER];
Index: working-2.6/arch/ppc/kernel/perfmon_fsl_booke.c
===================================================================
--- working-2.6.orig/arch/ppc/kernel/perfmon_fsl_booke.c	2005-05-24 14:12:22.000000000 +1000
+++ working-2.6/arch/ppc/kernel/perfmon_fsl_booke.c	2005-10-19 14:25:42.000000000 +1000
@@ -32,7 +32,7 @@
 #include <asm/io.h>
 #include <asm/reg.h>
 #include <asm/xmon.h>
-#include <asm/perfmon.h>
+#include <asm/pmc.h>
 
 static inline u32 get_pmlca(int ctr);
 static inline void set_pmlca(int ctr, u32 pmlca);
Index: working-2.6/arch/ppc/kernel/traps.c
===================================================================
--- working-2.6.orig/arch/ppc/kernel/traps.c	2005-10-19 14:16:40.000000000 +1000
+++ working-2.6/arch/ppc/kernel/traps.c	2005-10-19 14:25:42.000000000 +1000
@@ -41,7 +41,7 @@
 #ifdef CONFIG_PMAC_BACKLIGHT
 #include <asm/backlight.h>
 #endif
-#include <asm/perfmon.h>
+#include <asm/pmc.h>
 
 #ifdef CONFIG_XMON
 extern int xmon_bpt(struct pt_regs *regs);


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/people/dgibson



More information about the Linuxppc64-dev mailing list