zero PCU area when loading used area.diff -r1.4 -r1.5 src/sys/arch/powerpc/booke/spe.c
(matt)
--- src/sys/arch/powerpc/booke/spe.c 2011/05/02 06:43:16 1.4
+++ src/sys/arch/powerpc/booke/spe.c 2011/06/07 01:01:42 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: spe.c,v 1.4 2011/05/02 06:43:16 matt Exp $ */ | 1 | /* $NetBSD: spe.c,v 1.5 2011/06/07 01:01:42 matt Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Matt Thomas of 3am Software Foundry. | 8 | * by Matt Thomas of 3am Software Foundry. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: spe.c,v 1.4 2011/05/02 06:43:16 matt Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: spe.c,v 1.5 2011/06/07 01:01:42 matt Exp $"); | |
34 | 34 | |||
35 | #include "opt_altivec.h" | 35 | #include "opt_altivec.h" | |
36 | 36 | |||
37 | #ifdef PPC_HAVE_SPE | 37 | #ifdef PPC_HAVE_SPE | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/proc.h> | 40 | #include <sys/proc.h> | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #include <sys/atomic.h> | 42 | #include <sys/atomic.h> | |
43 | #include <sys/siginfo.h> | 43 | #include <sys/siginfo.h> | |
44 | #include <sys/pcu.h> | 44 | #include <sys/pcu.h> | |
45 | 45 | |||
46 | #include <powerpc/altivec.h> | 46 | #include <powerpc/altivec.h> | |
@@ -67,26 +67,31 @@ vec_used_p(lwp_t *l) | @@ -67,26 +67,31 @@ vec_used_p(lwp_t *l) | |||
67 | } | 67 | } | |
68 | 68 | |||
69 | void | 69 | void | |
70 | vec_mark_used(lwp_t *l) | 70 | vec_mark_used(lwp_t *l) | |
71 | { | 71 | { | |
72 | l->l_md.md_flags |= MDLWP_USEDVEC; | 72 | l->l_md.md_flags |= MDLWP_USEDVEC; | |
73 | } | 73 | } | |
74 | 74 | |||
75 | void | 75 | void | |
76 | vec_state_load(lwp_t *l, bool used) | 76 | vec_state_load(lwp_t *l, bool used) | |
77 | { | 77 | { | |
78 | struct pcb * const pcb = lwp_getpcb(l); | 78 | struct pcb * const pcb = lwp_getpcb(l); | |
79 | 79 | |||
80 | if (__predict_false(!vec_used_p(l))) { | |||
81 | memset(&pcb->pcb_vr, 0, sizeof(pcb->pcb_vr)); | |||
82 | vec_mark_used(l); | |||
83 | } | |||
84 | ||||
80 | /* | 85 | /* | |
81 | * Enable SPE temporarily (and disable interrupts). | 86 | * Enable SPE temporarily (and disable interrupts). | |
82 | */ | 87 | */ | |
83 | const register_t msr = mfmsr(); | 88 | const register_t msr = mfmsr(); | |
84 | mtmsr((msr & ~PSL_EE) | PSL_SPV); | 89 | mtmsr((msr & ~PSL_EE) | PSL_SPV); | |
85 | __asm volatile ("isync"); | 90 | __asm volatile ("isync"); | |
86 | 91 | |||
87 | /* | 92 | /* | |
88 | * Call an assembly routine to do load everything. | 93 | * Call an assembly routine to do load everything. | |
89 | */ | 94 | */ | |
90 | vec_load_from_vreg(&pcb->pcb_vr); | 95 | vec_load_from_vreg(&pcb->pcb_vr); | |
91 | __asm volatile ("sync"); | 96 | __asm volatile ("sync"); | |
92 | 97 |
--- src/sys/arch/powerpc/oea/altivec.c 2011/05/25 05:42:37 1.24
+++ src/sys/arch/powerpc/oea/altivec.c 2011/06/07 01:01:43 1.25
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: altivec.c,v 1.24 2011/05/25 05:42:37 matt Exp $ */ | 1 | /* $NetBSD: altivec.c,v 1.25 2011/06/07 01:01:43 matt Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1996 Wolfgang Solfrank. | 4 | * Copyright (C) 1996 Wolfgang Solfrank. | |
5 | * Copyright (C) 1996 TooLs GmbH. | 5 | * Copyright (C) 1996 TooLs GmbH. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -22,27 +22,27 @@ | @@ -22,27 +22,27 @@ | |||
22 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | 22 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | |
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
25 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 25 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <sys/cdefs.h> | 34 | #include <sys/cdefs.h> | |
35 | __KERNEL_RCSID(0, "$NetBSD: altivec.c,v 1.24 2011/05/25 05:42:37 matt Exp $"); | 35 | __KERNEL_RCSID(0, "$NetBSD: altivec.c,v 1.25 2011/06/07 01:01:43 matt Exp $"); | |
36 | 36 | |||
37 | #include "opt_multiprocessor.h" | 37 | #include "opt_multiprocessor.h" | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/proc.h> | 40 | #include <sys/proc.h> | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #include <sys/atomic.h> | 42 | #include <sys/atomic.h> | |
43 | 43 | |||
44 | #include <uvm/uvm_extern.h> /* for vcopypage/vzeropage */ | 44 | #include <uvm/uvm_extern.h> /* for vcopypage/vzeropage */ | |
45 | 45 | |||
46 | #include <powerpc/pcb.h> | 46 | #include <powerpc/pcb.h> | |
47 | #include <powerpc/altivec.h> | 47 | #include <powerpc/altivec.h> | |
48 | #include <powerpc/spr.h> | 48 | #include <powerpc/spr.h> | |
@@ -67,26 +67,31 @@ vec_used_p(lwp_t *l) | @@ -67,26 +67,31 @@ vec_used_p(lwp_t *l) | |||
67 | } | 67 | } | |
68 | 68 | |||
69 | void | 69 | void | |
70 | vec_mark_used(lwp_t *l) | 70 | vec_mark_used(lwp_t *l) | |
71 | { | 71 | { | |
72 | l->l_md.md_flags |= MDLWP_USEDVEC; | 72 | l->l_md.md_flags |= MDLWP_USEDVEC; | |
73 | } | 73 | } | |
74 | 74 | |||
75 | void | 75 | void | |
76 | vec_state_load(lwp_t *l, bool used) | 76 | vec_state_load(lwp_t *l, bool used) | |
77 | { | 77 | { | |
78 | struct pcb * const pcb = lwp_getpcb(l); | 78 | struct pcb * const pcb = lwp_getpcb(l); | |
79 | 79 | |||
80 | if (__predict_false(!vec_used_p(l))) { | |||
81 | memset(&pcb->pcb_vr, 0, sizeof(pcb->pcb_vr)); | |||
82 | vec_mark_used(l); | |||
83 | } | |||
84 | ||||
80 | /* | 85 | /* | |
81 | * Enable AltiVec temporarily (and disable interrupts). | 86 | * Enable AltiVec temporarily (and disable interrupts). | |
82 | */ | 87 | */ | |
83 | const register_t msr = mfmsr(); | 88 | const register_t msr = mfmsr(); | |
84 | mtmsr((msr & ~PSL_EE) | PSL_VEC); | 89 | mtmsr((msr & ~PSL_EE) | PSL_VEC); | |
85 | __asm volatile ("isync"); | 90 | __asm volatile ("isync"); | |
86 | 91 | |||
87 | /* | 92 | /* | |
88 | * Load the vector unit from vreg which is best done in | 93 | * Load the vector unit from vreg which is best done in | |
89 | * assembly. | 94 | * assembly. | |
90 | */ | 95 | */ | |
91 | vec_load_from_vreg(&pcb->pcb_vr); | 96 | vec_load_from_vreg(&pcb->pcb_vr); | |
92 | 97 |
--- src/sys/arch/powerpc/powerpc/fpu.c 2011/06/07 00:48:32 1.30
+++ src/sys/arch/powerpc/powerpc/fpu.c 2011/06/07 01:01:43 1.31
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: fpu.c,v 1.30 2011/06/07 00:48:32 matt Exp $ */ | 1 | /* $NetBSD: fpu.c,v 1.31 2011/06/07 01:01:43 matt Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1996 Wolfgang Solfrank. | 4 | * Copyright (C) 1996 Wolfgang Solfrank. | |
5 | * Copyright (C) 1996 TooLs GmbH. | 5 | * Copyright (C) 1996 TooLs GmbH. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -22,27 +22,27 @@ | @@ -22,27 +22,27 @@ | |||
22 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | 22 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | |
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
25 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 25 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <sys/cdefs.h> | 34 | #include <sys/cdefs.h> | |
35 | __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.30 2011/06/07 00:48:32 matt Exp $"); | 35 | __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.31 2011/06/07 01:01:43 matt Exp $"); | |
36 | 36 | |||
37 | #include "opt_multiprocessor.h" | 37 | #include "opt_multiprocessor.h" | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/proc.h> | 40 | #include <sys/proc.h> | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #include <sys/atomic.h> | 42 | #include <sys/atomic.h> | |
43 | #include <sys/siginfo.h> | 43 | #include <sys/siginfo.h> | |
44 | #include <sys/pcu.h> | 44 | #include <sys/pcu.h> | |
45 | 45 | |||
46 | #include <machine/pcb.h> | 46 | #include <machine/pcb.h> | |
47 | #include <machine/fpu.h> | 47 | #include <machine/fpu.h> | |
48 | #include <machine/psl.h> | 48 | #include <machine/psl.h> | |
@@ -70,28 +70,29 @@ fpu_used_p(lwp_t *l) | @@ -70,28 +70,29 @@ fpu_used_p(lwp_t *l) | |||
70 | 70 | |||
71 | void | 71 | void | |
72 | fpu_mark_used(lwp_t *l) | 72 | fpu_mark_used(lwp_t *l) | |
73 | { | 73 | { | |
74 | l->l_md.md_flags |= MDLWP_USEDFPU; | 74 | l->l_md.md_flags |= MDLWP_USEDFPU; | |
75 | } | 75 | } | |
76 | 76 | |||
77 | #ifdef PPC_HAVE_FPU | 77 | #ifdef PPC_HAVE_FPU | |
78 | void | 78 | void | |
79 | fpu_state_load(lwp_t *l, bool used) | 79 | fpu_state_load(lwp_t *l, bool used) | |
80 | { | 80 | { | |
81 | struct pcb * const pcb = lwp_getpcb(l); | 81 | struct pcb * const pcb = lwp_getpcb(l); | |
82 | 82 | |||
83 | if (__predict_false(!used)) { | 83 | if (__predict_false(!fpu_used_p(l))) { | |
84 | memset(&pcb->pcb_fpu, 0, sizeof(pcb->pcb_fpu)); | 84 | memset(&pcb->pcb_fpu, 0, sizeof(pcb->pcb_fpu)); | |
85 | fpu_mark_used(l); | |||
85 | } | 86 | } | |
86 | 87 | |||
87 | const register_t msr = mfmsr(); | 88 | const register_t msr = mfmsr(); | |
88 | mtmsr((msr & ~PSL_EE) | PSL_FP); | 89 | mtmsr((msr & ~PSL_EE) | PSL_FP); | |
89 | __asm volatile ("isync"); | 90 | __asm volatile ("isync"); | |
90 | 91 | |||
91 | fpu_load_from_fpreg(&pcb->pcb_fpu); | 92 | fpu_load_from_fpreg(&pcb->pcb_fpu); | |
92 | __asm volatile ("sync"); | 93 | __asm volatile ("sync"); | |
93 | 94 | |||
94 | mtmsr(msr); | 95 | mtmsr(msr); | |
95 | __asm volatile ("isync"); | 96 | __asm volatile ("isync"); | |
96 | 97 | |||
97 | curcpu()->ci_ev_fpusw.ev_count++; | 98 | curcpu()->ci_ev_fpusw.ev_count++; |