Module Name:    src
Committed By:   skrll
Date:           Sun Jun  6 12:13:36 UTC 2010

Modified Files:
        src/sys/arch/hp700/dev: cpu.c
        src/sys/arch/hp700/hp700: locore.S machdep.c
        src/sys/arch/hp700/include: cpu.h
        src/sys/arch/hppa/hppa: copy.S trap.S
        src/sys/arch/hppa/include: reg.h

Log Message:
MULTIPROCESSOR fixes

- provide curcpu in a control register instead of curlwp
- define {GET,SET}_CURLWP and GET_CURCPU and use whereever possible.
- define a cpu count and use it in CPU_INFO_FOREACH

XXX hppa_ncpus isn't valid yet.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/hp700/dev/cpu.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/hp700/hp700/locore.S
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/hp700/hp700/machdep.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/hp700/include/cpu.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/hppa/hppa/copy.S
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/hppa/hppa/trap.S
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/hppa/include/reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/hp700/dev/cpu.c
diff -u src/sys/arch/hp700/dev/cpu.c:1.14 src/sys/arch/hp700/dev/cpu.c:1.15
--- src/sys/arch/hp700/dev/cpu.c:1.14	Tue Mar 30 07:58:02 2010
+++ src/sys/arch/hp700/dev/cpu.c	Sun Jun  6 12:13:35 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.14 2010/03/30 07:58:02 skrll Exp $	*/
+/*	$NetBSD: cpu.c,v 1.15 2010/06/06 12:13:35 skrll Exp $	*/
 
 /*	$OpenBSD: cpu.c,v 1.28 2004/12/28 05:18:25 mickey Exp $	*/
 
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.14 2010/03/30 07:58:02 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.15 2010/06/06 12:13:35 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,6 +51,10 @@
 	void *sc_ih;
 };
 
+#ifdef MULTIPROCESSOR
+int hppa_ncpus;
+#endif
+
 int	cpumatch(device_t, cfdata_t, void *);
 void	cpuattach(device_t, device_t, void *);
 

Index: src/sys/arch/hp700/hp700/locore.S
diff -u src/sys/arch/hp700/hp700/locore.S:1.46 src/sys/arch/hp700/hp700/locore.S:1.47
--- src/sys/arch/hp700/hp700/locore.S:1.46	Mon Apr  5 12:56:51 2010
+++ src/sys/arch/hp700/hp700/locore.S	Sun Jun  6 12:13:35 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.46 2010/04/05 12:56:51 skrll Exp $	*/
+/*	$NetBSD: locore.S,v 1.47 2010/06/06 12:13:35 skrll Exp $	*/
 /*	$OpenBSD: locore.S,v 1.158 2008/07/28 19:08:46 miod Exp $	*/
 
 /*
@@ -142,6 +142,16 @@
 #define	MTCPU_U(x,r)	.word	0x14001840 | ((r) << 21) | ((x) << 16)
 #endif
 
+#ifdef MULTIPROCESSOR
+#define	GET_CURCPU(r)	mfctl	CR_CURCPU, r
+#define	GET_CURLWP(r)	mfctl	CR_CURCPU, r ! ldw	CI_CURLWP(r), r
+#define	SET_CURLWP(r,s)	mfctl	CR_CURCPU, s ! stw	r, CI_CURLWP(s)
+#else
+#define	GET_CURCPU(r)	mfctl	CR_CURLWP, r ! ldw	L_CPU(r), r
+#define	GET_CURLWP(r)	mfctl	CR_CURLWP, r
+#define	SET_CURLWP(r,s)	mtctl	r, CR_CURLWP
+#endif
+
 	.import	$global$, data
 	.import pdc, data
 	.import	boothowto, data
@@ -537,8 +547,7 @@
  * int splraise(int ncpl);
  */
 LEAF_ENTRY(splraise)
-	mfctl	CR_CURLWP, %t1
-	ldw	L_CPU(%t1),%t1
+	GET_CURCPU(%t1)
 	ldw	CI_CPL(%t1), %ret0
 	or	%ret0, %arg0, %arg0
 	bv	%r0(%rp)
@@ -549,8 +558,7 @@
  * int spllower(int ncpl);
  */
 ENTRY(spllower,HPPA_FRAME_SIZE)
-	mfctl	CR_CURLWP, %t1
-	ldw	L_CPU(%t1),%t1
+	GET_CURCPU(%t1)
 
 	ldw	CI_IPENDING(%t1), %r1	; load ipending
 	andcm,<> %r1, %arg0, %r1	; and with complement of new cpl
@@ -615,8 +623,7 @@
  * void hp700_intr_schedule(int mask);
  */
 ENTRY(hp700_intr_schedule,0)
-	mfctl	CR_CURLWP, %t1
-	ldw	L_CPU(%t1),%t2
+	GET_CURCPU(%t2)
 	mfctl	%eiem, %arg1
 	mtctl	%r0, %eiem			; disable interrupts
 	ldw	CI_IPENDING(%t2), %r1		; load ipending
@@ -870,12 +877,7 @@
 	ldw	TF_CR30(%t1), %t2		/* pmap_activate? */
 	mtctl	%t2, CR_FPPADDR			/* pmap_activate? */
 
-	mtctl	%arg1, CR_CURLWP
-
-#ifdef MULTIPROCESSOR
-	ldw	L_CPU(%arg1),%t2		; %t2 = curcpu()
-	stw	%arg1, CI_CURLWP(%t2)
-#endif
+	SET_CURLWP(%arg1, %t2)
 
 	ldo	-(HPPA_FRAME_SIZE+16*4)(%sp), %r3
 
@@ -991,7 +993,7 @@
 	 * this LWP was created by the fork()
 	 * syscall, which we now return from.
 	 */
-	mfctl	CR_CURLWP, %t2
+	GET_CURLWP(%t2)
 	.call
 	b	syscall_return
 	ldw	L_MD(%t2), %t3

Index: src/sys/arch/hp700/hp700/machdep.c
diff -u src/sys/arch/hp700/hp700/machdep.c:1.87 src/sys/arch/hp700/hp700/machdep.c:1.88
--- src/sys/arch/hp700/hp700/machdep.c:1.87	Sun Jun  6 10:15:51 2010
+++ src/sys/arch/hp700/hp700/machdep.c	Sun Jun  6 12:13:35 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.87 2010/06/06 10:15:51 skrll Exp $	*/
+/*	$NetBSD: machdep.c,v 1.88 2010/06/06 12:13:35 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.87 2010/06/06 10:15:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.88 2010/06/06 12:13:35 skrll Exp $");
 
 #include "opt_cputype.h"
 #include "opt_ddb.h"
@@ -256,10 +256,13 @@
 /* Virtual page frame for /dev/mem (see mem.c) */
 vaddr_t vmmap;
 
+/* Our exported CPU info */
 struct cpu_info cpus[HPPA_MAXCPUS] = {
+	{
 #ifdef MULTIPROCESSOR
-	.ci_curlwp = &lwp0
+		.ci_curlwp = &lwp0,
 #endif
+	},
 };
 
 struct vm_map *phys_map = NULL;
@@ -426,8 +429,12 @@
 #ifdef KGDB
 	boothowto |= RB_KDB;	/* go to kgdb early if compiled in. */
 #endif
-	/* Setup curlwp early for LOCKDEBUG */
+	/* Setup curlwp/curcpu early for LOCKDEBUG */
+#ifdef MULTIPROCESSOR
+	mtctl(&cpus[0], CR_CURCPU);
+#else
 	mtctl(&lwp0, CR_CURLWP);
+#endif
 
 	/* Copy bootinfo */
 	if (bi != NULL)

Index: src/sys/arch/hp700/include/cpu.h
diff -u src/sys/arch/hp700/include/cpu.h:1.51 src/sys/arch/hp700/include/cpu.h:1.52
--- src/sys/arch/hp700/include/cpu.h:1.51	Sun Jun  6 10:22:43 2010
+++ src/sys/arch/hp700/include/cpu.h	Sun Jun  6 12:13:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.51 2010/06/06 10:22:43 skrll Exp $	*/
+/*	$NetBSD: cpu.h,v 1.52 2010/06/06 12:13:36 skrll Exp $	*/
 
 /*	$OpenBSD: cpu.h,v 1.55 2008/07/23 17:39:35 kettenis Exp $	*/
 
@@ -231,7 +231,9 @@
 
 	struct cpu_data ci_data;	/* MI per-cpu data */
 
+#ifdef MULTIPROCESSOR
 	struct	lwp	*ci_curlwp;	/* CPU owner */
+#endif
 	int		ci_cpuid;	/* CPU index (see cpus[] array) */
 	int		ci_mtx_count;
 	int		ci_mtx_oldspl;
@@ -252,15 +254,31 @@
 
 #ifdef MULTIPROCESSOR
 
+/* Number of CPUs in the system */
+extern int hppa_ncpus;
+
 #define	HPPA_MAXCPUS	4
 #define	cpu_number()			(curcpu()->ci_cpuid)
 
 #define	CPU_IS_PRIMARY(ci)		((ci)->ci_cpuid == 0)
 #define	CPU_INFO_ITERATOR		int
-#define	CPU_INFO_FOREACH(cii, ci)	cii = 0; ci =  &cpus[0], cii < ncpus; cii++, ci++
+#define	CPU_INFO_FOREACH(cii, ci)	cii = 0; ci =  &cpus[0], cii < hppa_ncpus; cii++, ci++
 
 void	cpu_boot_secondary_processors(void);
-#else /* MULTIPROCESSOR */
+
+static __inline struct cpu_info *
+hppa_curcpu(void)
+{
+	struct cpu_info *ci;
+
+	__asm volatile("mfctl %1, %0" : "=r" (ci): "i" (CR_CURCPU));
+
+	return ci;
+}
+
+#define	curcpu()			hppa_curcpu()
+
+#else /*  MULTIPROCESSOR */
 
 #define	HPPA_MAXCPUS	1
 #define	curcpu()			(&cpus[0])

Index: src/sys/arch/hppa/hppa/copy.S
diff -u src/sys/arch/hppa/hppa/copy.S:1.16 src/sys/arch/hppa/hppa/copy.S:1.17
--- src/sys/arch/hppa/hppa/copy.S:1.16	Sat Mar 20 23:31:27 2010
+++ src/sys/arch/hppa/hppa/copy.S	Sun Jun  6 12:13:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.16 2010/03/20 23:31:27 chs Exp $	*/
+/*	$NetBSD: copy.S,v 1.17 2010/06/06 12:13:36 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@
 LEAF_ENTRY_NOPROFILE(name)			! \
 	ldil	L%VM_MAXUSER_ADDRESS, %t1	! \
 	comb,>>= %arg0, %t1, fusubadaddr	! \
-	mfctl	CR_CURLWP, %t1			! \
+	GET_CURLWP(%t1)				! \
 	ldw	L_PCB(%t1), %t1			! \
 	ldil	L%fusufault, %t2		! \
 	ldo	R%fusufault(%t2), %t2		! \
@@ -149,7 +149,7 @@
  */
 LEAF_ENTRY(spstrcpy)
 	/* setup fault handler */
-	mfctl	CR_CURLWP, %r31
+	GET_CURLWP(%r31)
 	ldw	L_PCB(%r31), %r31
 	ldil	L%L$spstrcpy_fault, %t2
 	ldo	R%L$spstrcpy_fault(%t2), %t2
@@ -222,7 +222,7 @@
 
 /* This loads curlwp's space into the given register. */
 #define SPACE_CURLWP(reg)			  \
-	mfctl	CR_CURLWP, reg			! \
+	GET_CURLWP(reg)				! \
 	ldw	L_PCB(reg), reg			! \
 	ldw	PCB_SPACE(reg), reg
 
@@ -352,7 +352,7 @@
 	comb,>>= %arg0, %t1, 1f
 
 	/* setup fault handler */
-	mfctl	CR_CURLWP, %r31
+	GET_CURLWP(%r31)
 	ldw	L_PCB(%r31), %r31
 	ldil	L%L$ucas_32_fault, %t2
 	ldo	R%L$ucas_32_fault(%t2), %t2

Index: src/sys/arch/hppa/hppa/trap.S
diff -u src/sys/arch/hppa/hppa/trap.S:1.49 src/sys/arch/hppa/hppa/trap.S:1.50
--- src/sys/arch/hppa/hppa/trap.S:1.49	Mon Apr 26 12:10:51 2010
+++ src/sys/arch/hppa/hppa/trap.S	Sun Jun  6 12:13:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.S,v 1.49 2010/04/26 12:10:51 skrll Exp $	*/
+/*	$NetBSD: trap.S,v 1.50 2010/06/06 12:13:36 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -203,7 +203,7 @@
 	 */
 
 	/* t2 = curlwp PCB */
-	mfctl	CR_CURLWP, %t3 
+	GET_CURLWP(%t3)
 	ldw	L_PCB(%sr1, %t3), %t2			/* XXX can use ,sl */
 
 	/*
@@ -399,7 +399,7 @@
 	CALL(syscall, %r1)
 
 	/* load curlwp's trapframe pointer */
-	mfctl	CR_CURLWP, %r1
+	GET_CURLWP(%r1)
 	ldw	L_MD(%r1), %t3
 
 	.exit
@@ -421,8 +421,7 @@
 	 * a note for trapall).  Hopefully no page fault would happen on or after
 	 * the copy, and interrupts are disabled.
 	 */
-	mfctl	CR_CURLWP, %t2
-	ldw	L_CPU(%t2), %t2
+	GET_CURCPU(%t2)
 	ldo	CI_TRAPSAVE(%t2), %t2
 
 	ldw  0(%t3), %r1 ! ldw  4(%t3), %t1 ! stw %r1,  0(%t2) ! stw %t1,  4(%t2)
@@ -508,8 +507,13 @@
 	ldw	TF_CR30(%sr3, %t3), %t1
 	mtctl	%t1, CR_FPPADDR
 
+#ifdef MULTIPROCESSOR
+	mfctl	CR_CURCPU, %t3
+#else
 	mfctl	CR_CURLWP, %t3
 	ldw	L_CPU(%sr3, %t3), %t3
+#endif
+
 	/*
 	 * Clear the system mask, this puts us back into physical mode.  Reload
 	 * the trapframe pointer with the correspondent PA value.  %sp will be
@@ -1910,8 +1914,7 @@
 	/* do not overwrite %tr4(%cr28) it contains the contents of r24 */
 	mtctl	%t3, %tr2
 
-	mfctl	CR_CURLWP, %t3
-	ldw	L_CPU(%t3), %t3
+	GET_CURCPU(%t3)
 
 	stw	%t1, CI_TRAPSAVE + TF_R22(%t3)	/* use ,bc */
 	stw	%t2, CI_TRAPSAVE + TF_R21(%t3)
@@ -2119,8 +2122,7 @@
 	/*
 	 * Copy partially saved state from the store into the frame
 	 */
-	mfctl	CR_CURLWP, %t2
-	ldw	L_CPU(%t2), %t2
+	GET_CURCPU(%t2)
 	ldo	CI_TRAPSAVE(%t2), %t2
 
 	/* use ,bc each line */
@@ -2222,7 +2224,7 @@
 	bb,>=,n	%arg0, TFF_LAST_POS, L$trap_return
 	nop
 
-	mfctl	CR_CURLWP, %t2
+	GET_CURLWP(%t2)
 	ldw	L_MD(%t2), %t3
 
 L$trap_return:

Index: src/sys/arch/hppa/include/reg.h
diff -u src/sys/arch/hppa/include/reg.h:1.11 src/sys/arch/hppa/include/reg.h:1.12
--- src/sys/arch/hppa/include/reg.h:1.11	Tue Mar 16 16:20:19 2010
+++ src/sys/arch/hppa/include/reg.h	Sun Jun  6 12:13:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: reg.h,v 1.11 2010/03/16 16:20:19 skrll Exp $	*/
+/*	$NetBSD: reg.h,v 1.12 2010/06/06 12:13:36 skrll Exp $	*/
 
 /*	$OpenBSD: reg.h,v 1.7 2000/06/15 17:00:37 mickey Exp $	*/
 
@@ -82,7 +82,11 @@
 #define	CR_EIRR		23
 
 /* Temporary control registers */
+#ifdef MULTIPROCESSOR
+#define	CR_CURCPU	24	/* tr0: curcpu				*/
+#else
 #define	CR_CURLWP	24	/* tr0: curlwp				*/
+#endif
 #define	CR_VTOP		25	/* tr1: virt to phys table address	*/
 #define	CR_TR2		26	/* tr2: temporary			*/
 #define	CR_TLS		27	/* tr3: thread local storage pointer	*/

Reply via email to