Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64 Cache info is now printed during bootstrap ...



details:   https://anonhg.NetBSD.org/src/rev/0816b0716bdb
branches:  trunk
changeset: 335814:0816b0716bdb
user:      palle <palle%NetBSD.org@localhost>
date:      Sat Jan 24 20:17:22 2015 +0000

description:
Cache info is now printed during bootstrap on the sun4v platform. Make the sun4u centric cache info code in cpu_attach() a bit more general

diffstat:

 sys/arch/sparc64/doc/TODO      |    3 +-
 sys/arch/sparc64/sparc64/cpu.c |  171 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 150 insertions(+), 24 deletions(-)

diffs (266 lines):

diff -r cf79d4982338 -r 0816b0716bdb sys/arch/sparc64/doc/TODO
--- a/sys/arch/sparc64/doc/TODO Sat Jan 24 19:24:08 2015 +0000
+++ b/sys/arch/sparc64/doc/TODO Sat Jan 24 20:17:22 2015 +0000
@@ -1,4 +1,4 @@
- /* $NetBSD: TODO,v 1.8 2015/01/05 11:42:19 palle Exp $ */
+ /* $NetBSD: TODO,v 1.9 2015/01/24 20:17:22 palle Exp $ */
 
 Things to be done:
 
@@ -16,7 +16,6 @@
 - ofwboot: tlb_init_sun4v() hardcodes number of slots to 64
 - locore.s: sun4v_datatrap missing implementation for trap levels 0 and 1
 - pmap.c: pmap_calculate_colors() should known about sun4v
-- cpu.c: cpu_attach() does not emit cache info on sun4v
 - check build without SUN4V defined
 - replace relevant references til %ver with GET_MAXCWP
 - pmap_mp_init(): sun4v missing handling
diff -r cf79d4982338 -r 0816b0716bdb sys/arch/sparc64/sparc64/cpu.c
--- a/sys/arch/sparc64/sparc64/cpu.c    Sat Jan 24 19:24:08 2015 +0000
+++ b/sys/arch/sparc64/sparc64/cpu.c    Sat Jan 24 20:17:22 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.121 2014/12/05 11:34:00 nakayama Exp $ */
+/*     $NetBSD: cpu.c,v 1.122 2015/01/24 20:17:22 palle Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.121 2014/12/05 11:34:00 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.122 2015/01/24 20:17:22 palle Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -75,6 +75,7 @@
 
 #include <sparc64/sparc64/cache.h>
 #include <sparc64/hypervisor.h>
+#include <sparc64/mdesc.h>
 
 #define SUN4V_MONDO_QUEUE_SIZE 32
 #define SUN4V_QUEUE_ENTRY_SIZE 64
@@ -153,6 +154,140 @@
        return id;
 }
 
+static int
+cpu_cache_info_sun4v(const char *type, int level, const char *prop)
+{
+       int idx = 0;
+       uint64_t val = 0;;
+       idx = mdesc_find_node_by_idx(idx, "cache");
+       while (idx != -1 && val == 0) {
+               const char *p;
+               size_t len = 0;
+               p = mdesc_get_prop_data(idx, "type", &len);
+               if (p == NULL)
+                       panic("No type found\n");
+               if (len == 0)
+                       panic("Len is zero");
+               if (type == NULL || strcmp(p, type) == 0) {
+                       uint64_t l;
+                       l = mdesc_get_prop_val(idx, "level");
+                       if (l == level)
+                               val = mdesc_get_prop_val(idx, prop);
+               }
+               if (val == 0)
+                       idx = mdesc_next_node(idx);
+       }
+       return val;
+}
+
+static int
+cpu_icache_size(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v("instn", 1, "size");
+       else 
+               return prom_getpropint(node, "icache-size", 0);
+}
+
+static int
+cpu_icache_line_size(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v("instn", 1, "line-size");
+       else
+               return prom_getpropint(node, "icache-line-size", 0);
+}
+
+static int
+cpu_icache_nlines(int node)
+{
+       if (CPU_ISSUN4V)
+               return 0;
+       else
+               return prom_getpropint(node, "icache-nlines", 64);
+}
+
+static int
+cpu_icache_associativity(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v("instn", 1, "associativity");
+       else
+               return prom_getpropint(node, "icache-associativity", 1);
+}
+
+static int
+cpu_dcache_size(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v("data", 1, "size");
+       else
+               return prom_getpropint(node, "dcache-size", 0);
+}
+
+static int
+cpu_dcache_line_size(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v("data", 1, "line-size");
+       else
+               return prom_getpropint(node, "dcache-line-size", 0);
+}
+
+static int
+cpu_dcache_nlines(int node)
+{
+       if (CPU_ISSUN4V)
+               return 0;
+       else
+               return prom_getpropint(node, "dcache-nlines", 128);
+}
+
+static int
+cpu_dcache_associativity(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v("data", 1, "associativity");
+       else 
+               return prom_getpropint(node, "dcache-associativity", 1);
+}
+
+static int
+cpu_ecache_size(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v(NULL, 2, "size");
+       else
+               return prom_getpropint(node, "ecache-size", 0);
+}
+
+static int
+cpu_ecache_line_size(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v(NULL, 2, "line-size");
+       else
+               return prom_getpropint(node, "ecache-line-size", 0);
+}
+
+static int
+cpu_ecache_nlines(int node)
+{
+       if (CPU_ISSUN4V)
+               return 0;
+       else
+               return prom_getpropint(node, "ecache-nlines", 32768);
+}
+
+static int
+cpu_ecache_associativity(int node)
+{
+       if (CPU_ISSUN4V)
+               return cpu_cache_info_sun4v(NULL, 2, "associativity");
+       else
+               return prom_getpropint(node, "ecache-associativity", 1);
+}
+
 struct cpu_info *
 alloc_cpuinfo(u_int cpu_node)
 {
@@ -352,13 +487,12 @@
        }
        aprint_normal_dev(dev, "");
 
-       /* XXX sun4v mising cache info printout */
        bigcache = 0;
 
-       icachesize = prom_getpropint(node, "icache-size", 0);
+       icachesize = cpu_icache_size(node);
        if (icachesize > icache_size)
                icache_size = icachesize;
-       linesize = l = prom_getpropint(node, "icache-line-size", 0);
+       linesize = l = cpu_icache_line_size(node);
        if (linesize > icache_line_size)
                icache_line_size = linesize;
 
@@ -369,11 +503,9 @@
        totalsize = icachesize;
        if (totalsize == 0)
                totalsize = l *
-                       prom_getpropint(node, "icache-nlines", 64) *
-                       prom_getpropint(node, "icache-associativity", 1);
+                   cpu_icache_nlines(node) * cpu_icache_associativity(node);
 
-       cachesize = totalsize /
-           prom_getpropint(node, "icache-associativity", 1);
+       cachesize = totalsize / cpu_icache_associativity(node);
        bigcache = cachesize;
 
        sep = "";
@@ -384,10 +516,10 @@
                sep = ", ";
        }
 
-       dcachesize = prom_getpropint(node, "dcache-size", 0);
+       dcachesize = cpu_dcache_size(node);
        if (dcachesize > dcache_size)
                dcache_size = dcachesize;
-       linesize = l = prom_getpropint(node, "dcache-line-size", 0);
+       linesize = l = cpu_dcache_line_size(node);
        if (linesize > dcache_line_size)
                dcache_line_size = linesize;
 
@@ -398,11 +530,9 @@
        totalsize = dcachesize;
        if (totalsize == 0)
                totalsize = l *
-                       prom_getpropint(node, "dcache-nlines", 128) *
-                       prom_getpropint(node, "dcache-associativity", 1);
+                   cpu_dcache_nlines(node) * cpu_dcache_associativity(node);
 
-       cachesize = totalsize /
-           prom_getpropint(node, "dcache-associativity", 1);
+       cachesize = totalsize / cpu_dcache_associativity(node);
        if (cachesize > bigcache)
                bigcache = cachesize;
 
@@ -413,20 +543,17 @@
                sep = ", ";
        }
 
-       linesize = l =
-               prom_getpropint(node, "ecache-line-size", 0);
+       linesize = l = cpu_ecache_line_size(node);
        for (i = 0; (1 << i) < l && l; i++)
                /* void */;
        if ((1 << i) != l && l)
                panic("bad ecache line size %d", l);
-       totalsize = prom_getpropint(node, "ecache-size", 0);
+       totalsize = cpu_ecache_size(node);
        if (totalsize == 0)
                totalsize = l *
-                       prom_getpropint(node, "ecache-nlines", 32768) *
-                       prom_getpropint(node, "ecache-associativity", 1);
+                   cpu_ecache_nlines(node) * cpu_ecache_associativity(node);
 
-       cachesize = totalsize /
-            prom_getpropint(node, "ecache-associativity", 1);
+       cachesize = totalsize / cpu_ecache_associativity(node);
        if (cachesize > bigcache)
                bigcache = cachesize;
 



Home | Main Index | Thread Index | Old Index