Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/arch/powerpc Use a constructor to get the cache_info.



details:   https://anonhg.NetBSD.org/src/rev/a60fa4e45c38
branches:  trunk
changeset: 789663:a60fa4e45c38
user:      matt <matt%NetBSD.org@localhost>
date:      Fri Aug 30 21:28:59 2013 +0000

description:
Use a constructor to get the cache_info.
However memset can be called before the constructor is called, just treat
those as simple fills.
Add CACHE_INFO_DCACHE_LINE_SIZE to assym.h and use it

diffstat:

 lib/libc/arch/powerpc/Makefile.inc            |    3 +-
 lib/libc/arch/powerpc/genassym.cf             |    6 +-
 lib/libc/arch/powerpc/misc/powerpc_initfini.c |   64 ++++++++++++
 lib/libc/arch/powerpc/string/bzero.S          |  136 ++-----------------------
 4 files changed, 84 insertions(+), 125 deletions(-)

diffs (279 lines):

diff -r a4d039906bd8 -r a60fa4e45c38 lib/libc/arch/powerpc/Makefile.inc
--- a/lib/libc/arch/powerpc/Makefile.inc        Fri Aug 30 20:57:26 2013 +0000
+++ b/lib/libc/arch/powerpc/Makefile.inc        Fri Aug 30 21:28:59 2013 +0000
@@ -1,6 +1,7 @@
-#      $NetBSD: Makefile.inc,v 1.13 2011/01/17 08:23:53 matt Exp $
+#      $NetBSD: Makefile.inc,v 1.14 2013/08/30 21:28:59 matt Exp $
 
 SRCS+=         __sigaction14_sigtramp.c __sigtramp2.S
+SRCS+=         powerpc_initfini.c
 
 CPPFLAGS+=     -I.
 
diff -r a4d039906bd8 -r a60fa4e45c38 lib/libc/arch/powerpc/genassym.cf
--- a/lib/libc/arch/powerpc/genassym.cf Fri Aug 30 20:57:26 2013 +0000
+++ b/lib/libc/arch/powerpc/genassym.cf Fri Aug 30 21:28:59 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.3 2011/01/18 01:23:24 matt Exp $
+#      $NetBSD: genassym.cf,v 1.4 2013/08/30 21:28:59 matt Exp $
 
 #
 # Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,6 +30,8 @@
 #
 
 include <sys/types.h>
+include <sys/queue.h>
+include <sys/cpu.h>
 include <sys/signal.h>
 include <sys/ucontext.h>
 
@@ -46,3 +48,5 @@
 
 define SIG_BLOCK       SIG_BLOCK
 define SIG_SETMASK     SIG_SETMASK
+
+define CACHE_INFO_DCACHE_LINE_SIZE offsetof(struct cache_info, dcache_line_size)
diff -r a4d039906bd8 -r a60fa4e45c38 lib/libc/arch/powerpc/misc/powerpc_initfini.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/powerpc/misc/powerpc_initfini.c     Fri Aug 30 21:28:59 2013 +0000
@@ -0,0 +1,64 @@
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+__RCSID("$NetBSD: powerpc_initfini.c,v 1.1 2013/08/30 21:28:59 matt Exp $");
+
+#include "namespace.h"
+
+/*
+ * Grab the cache_info at load time.
+ */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/queue.h>
+#include <sys/cpu.h>
+
+#include <stdbool.h>
+#include <stddef.h>
+
+__dso_hidden struct cache_info _libc_powerpc_cache_info;
+
+static void _libc_cache_info_init(void)
+    __attribute__((__constructor__, __used__));
+
+void __section(".text.startup")
+_libc_cache_info_init(void)
+{
+       static bool initialized;
+       if (!initialized) {
+               const int name[2] = { CTL_MACHDEP, CPU_CACHEINFO };
+               size_t len = sizeof(_libc_powerpc_cache_info);
+               (void)sysctl(name, __arraycount(name),
+                   &_libc_powerpc_cache_info, &len, NULL, 0);
+               initialized = 1;
+       }
+}
diff -r a4d039906bd8 -r a60fa4e45c38 lib/libc/arch/powerpc/string/bzero.S
--- a/lib/libc/arch/powerpc/string/bzero.S      Fri Aug 30 20:57:26 2013 +0000
+++ b/lib/libc/arch/powerpc/string/bzero.S      Fri Aug 30 21:28:59 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bzero.S,v 1.12 2013/07/18 12:20:41 matt Exp $ */
+/*     $NetBSD: bzero.S,v 1.13 2013/08/30 21:28:59 matt Exp $ */
 
 /*-
  * Copyright (C) 2001  Martin J. Laubach <mjl%NetBSD.org@localhost>
@@ -32,12 +32,10 @@
 
 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: bzero.S,v 1.12 2013/07/18 12:20:41 matt Exp $")
+__RCSID("$NetBSD: bzero.S,v 1.13 2013/08/30 21:28:59 matt Exp $")
 #endif /* LIBC_SCCS && !lint */
 
-#ifdef _KERNEL
-#include <assym.h>
-#endif
+#include "assym.h"
 
 #define USE_STSWX 0    /* don't. slower than trivial copy loop */
 
@@ -73,128 +71,20 @@
 
 /*----------------------------------------------------------------------*/
 #ifndef _KERNEL
-               /* First find out cache line size */
-               mflr    %r9
 #ifdef PIC
-               bcl     20,31,1f
-1:             mflr    %r5
-               mtlr    %r9
-               addis   %r5,%r5,cache_info+4-1b@ha
-               lwzu    %r9,cache_info+4-1b@l(%r5)
-#else
-               lis     %r5,cache_info+4@ha
-               lwzu    %r9,cache_info+4@l(%r5)
-#endif
-               lwz     %r10,cache_sh-(cache_info+4)(%r5)
-               cmpwi   %r9, -1
-               bne+    cb_cacheline_known
-
-               addi    %r5, %r5, -4    /* point r5 @ beginning of cache_info */
-
-/*----------------------------------------------------------------------*/
-#define CTL_MACHDEP    7
-#define CPU_CACHELINE  1
-#define        CPU_CACHEINFO   5
-
-#define STKFRAME_SZ    64
-#define MIB            8
-#define OLDPLEN                16
-#define R3_SAVE                20
-#define R4_SAVE                24
-#define R0_SAVE                28
-#define R8_SAVE                32
-#define R31_SAVE       36
-#ifdef PIC
-#define R30_SAVE       40
-#endif
-
-               stw     %r9, 4(%r1)
-               stwu    %r1, -STKFRAME_SZ(%r1)
-
-               stw     %r31, R31_SAVE(%r1)
-               mr      %r31, %r5               /* cache info */
-
-#ifdef PIC
-               stw     %r30, R30_SAVE(%r1)
-               PIC_TOCSETUP(cb_memset,%r30)
-#endif
-
-               stw     %r8, R8_SAVE(%r1)
-               stw     %r3, R3_SAVE(%r1)
-               stw     %r4, R4_SAVE(%r1)
-               stw     %r0, R0_SAVE(%r1)
-
-               li      %r0, CTL_MACHDEP                /* Construct MIB */
-               stw     %r0, MIB(%r1)
-               li      %r0, CPU_CACHEINFO
-               stw     %r0, MIB+4(%r1)
-
-               li      %r0, 4*4                        /* Oldlenp := 4*4 */
-               stw     %r0, OLDPLEN(%r1)
-
-               addi    %r3, %r1, MIB
-               li      %r4, 2                  /* namelen */
-               /* %r5 already contains &cache_info */
-               addi    %r6, %r1, OLDPLEN
-               li      %r7, 0
-               li      %r8, 0
-               bl      PIC_PLT(_C_LABEL(sysctl))
-       
-               cmpwi   %r3, 0                  /* Check result */
-               beq     1f
-
-               /* Failure, try older sysctl */
-       
-               li      %r0, CTL_MACHDEP        /* Construct MIB */
-               stw     %r0, MIB(%r1)
-               li      %r0, CPU_CACHELINE
-               stw     %r0, MIB+4(%r1)
-
-               li      %r0, 4                  /* Oldlenp := 4 */
-               stw     %r0, OLDPLEN(%r1)
-
-               addi    %r3, %r1, MIB
-               li      %r4, 2                  /* namelen */
-               addi    %r5, %r31, 4
-               addi    %r6, %r1, OLDPLEN
-               li      %r7, 0
-               li      %r8, 0
-               bl      PIC_PLT(_C_LABEL(sysctl))
-1:
-               lwz     %r3, R3_SAVE(%r1)
-               lwz     %r4, R4_SAVE(%r1)
-               lwz     %r8, R8_SAVE(%r1)
-               lwz     %r0, R0_SAVE(%r1)
-               lwz     %r9, 4(%r31)
-               lwz     %r31, R31_SAVE(%r1)
-#ifdef PIC
-               lwz     %r30, R30_SAVE(%r1)
-#endif
-               addi    %r1, %r1, STKFRAME_SZ
-               lwz     %r7, 4(%r1)
-               mtlr    %r7
-
-               cntlzw  %r6, %r9                        /* compute shift value */
-               li      %r5, 31
-               subf    %r10, %r6, %r5
-
-#ifdef PIC
+               /* First get cache line size */
                mflr    %r9
                bcl     20,31,1f
-1:             mflr    %r5
+1:             mflr    %r10
                mtlr    %r9
-
-               addis   %r5, %r5, cache_info+4-1b@ha
-               lwzu    %r9, cache_info+4-1b@l(%r5)
+               addis   %r10,%r10,_libc_powerpc_cache_info+CACHE_INFO_DCACHE_LINE_SIZE-1b@ha
+               lwz     %r9,_libc_powerpc_cache_info+CACHE_INFO_DCACHE_LINE_SIZE-1b@l(%r10)
 #else
-               lis     %r5, cache_info+4@ha
-               lwzu    %r9, cache_info+4@l(%r5)
+               lis     %r10,_libc_powerpc_cache_info+CACHE_INFO_DCACHE_LINE_SIZE@ha
+               lwz     %r9,_libc_powerpc_cache_info+CACHE_INFO_DCACHE_LINE_SIZE@l(%r10)
 #endif
-               stw     %r10, cache_sh-(cache_info+4)(%r5)
-
-/*----------------------------------------------------------------------*/
-/* Okay, we know the cache line size (%r9) and shift value (%r10) */
-cb_cacheline_known:
+               cmplwi  %cr1, %r9, 0            /* Unknown? */
+               beq-    simple_fill             /* a trivial fill routine */
 #else /* _KERNEL */
 #ifdef MULTIPROCESSOR
                mfsprg  %r10, 0                 /* Get cpu_info pointer */
@@ -202,11 +92,11 @@
                lis     %r10, cpu_info_store@ha
                addi    %r10, %r10, cpu_info_store@l
 #endif
-               lwz     %r9, CPU_CI+4(%r10)     /* Load D$ line size */
+               lwz     %r9, CPU_CI+CACHE_INFO_DCACHE_LINE_SIZE(%r10)   /* Load D$ line size */
+#endif /* _KERNEL */
                cntlzw  %r10, %r9                       /* Calculate shift.. */
                li      %r6, 31
                subf    %r10, %r10, %r6
-#endif /* _KERNEL */
                /* Back in memory filling business */
                
                cmplwi  %cr1, r_len, 0          /* Nothing to do? */



Home | Main Index | Thread Index | Old Index