Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64/sparc64 Reuse results of "bootpath" and "bo...



details:   https://anonhg.NetBSD.org/src/rev/3d9f11bec0fb
branches:  trunk
changeset: 336736:3d9f11bec0fb
user:      nakayama <nakayama%NetBSD.org@localhost>
date:      Sun Mar 15 10:38:58 2015 +0000

description:
Reuse results of "bootpath" and "bootargs" from openfirmware
instead of calling openfirmware in each sysctl CPU_BOOT*.

This change reduces openfirmware calls from userland since sysctl
CPU_BOOTED_KERNEL is used in system commands such as pstat and
netstat.

diffstat:

 sys/arch/sparc64/sparc64/autoconf.c |  14 ++++-
 sys/arch/sparc64/sparc64/machdep.c  |  86 ++++++------------------------------
 2 files changed, 25 insertions(+), 75 deletions(-)

diffs (174 lines):

diff -r d46188f67c7d -r 3d9f11bec0fb sys/arch/sparc64/sparc64/autoconf.c
--- a/sys/arch/sparc64/sparc64/autoconf.c       Sun Mar 15 09:21:01 2015 +0000
+++ b/sys/arch/sparc64/sparc64/autoconf.c       Sun Mar 15 10:38:58 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.201 2015/01/10 22:19:26 palle Exp $ */
+/*     $NetBSD: autoconf.c,v 1.202 2015/03/15 10:38:58 nakayama Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.201 2015/01/10 22:19:26 palle Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.202 2015/03/15 10:38:58 nakayama Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -146,6 +146,7 @@
 char   machine_banner[100];
 char   machine_model[100];
 char   ofbootpath[OFPATHLEN], *ofboottarget, *ofbootpartition;
+char   ofbootargs[OFPATHLEN], *ofbootfile, *ofbootflags;
 int    ofbootpackage;
 
 static int mbprint(void *, const char *);
@@ -418,8 +419,9 @@
        /* Setup pointer to boot flags */
        if (OF_getprop(chosen, "bootargs", sbuf, sizeof(sbuf)) == -1)
                return;
+       strcpy(ofbootargs, sbuf);
 
-       cp = sbuf;
+       cp = ofbootargs;
 
        /* Find start of boot flags */
        while (*cp) {
@@ -427,8 +429,12 @@
                if (*cp == '-' || *cp == '\0')
                        break;
                while(*cp != ' ' && *cp != '\t' && *cp != '\0') cp++;
-               
+               if (*cp != '\0')
+                       *cp++ = '\0';
        }
+       if (cp != ofbootargs)
+               ofbootfile = ofbootargs;
+       ofbootflags = cp;
        if (*cp != '-')
                return;
 
diff -r d46188f67c7d -r 3d9f11bec0fb sys/arch/sparc64/sparc64/machdep.c
--- a/sys/arch/sparc64/sparc64/machdep.c        Sun Mar 15 09:21:01 2015 +0000
+++ b/sys/arch/sparc64/sparc64/machdep.c        Sun Mar 15 10:38:58 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.280 2014/10/28 13:04:51 nakayama Exp $ */
+/*     $NetBSD: machdep.c,v 1.281 2015/03/15 10:38:58 nakayama Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.280 2014/10/28 13:04:51 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.281 2015/03/15 10:38:58 nakayama Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -295,59 +295,6 @@
 #endif
 }
 
-static char *parse_bootfile(char *);
-static char *parse_bootargs(char *);
-
-static char *
-parse_bootfile(char *args)
-{
-       char *cp;
-
-       /*
-        * bootargs is of the form: [kernelname] [args...]
-        * It can be the empty string if we booted from the default
-        * kernel name.
-        */
-       cp = args;
-       for (cp = args; *cp != 0 && *cp != ' ' && *cp != '\t'; cp++) {
-               if (*cp == '-') {
-                       int c;
-                       /*
-                        * If this `-' is most likely the start of boot
-                        * options, we're done.
-                        */
-                       if (cp == args)
-                               break;
-                       if ((c = *(cp-1)) == ' ' || c == '\t')
-                               break;
-               }
-       }
-       /* Now we've separated out the kernel name from the args */
-       *cp = '\0';
-       return (args);
-}
-
-static char *
-parse_bootargs(char *args)
-{
-       char *cp;
-
-       for (cp = args; *cp != '\0'; cp++) {
-               if (*cp == '-') {
-                       int c;
-                       /*
-                        * Looks like options start here, but check this
-                        * `-' is not part of the kernel name.
-                        */
-                       if (cp == args)
-                               break;
-                       if ((c = *(cp-1)) == ' ' || c == '\t')
-                               break;
-               }
-       }
-       return (cp);
-}
-
 /*
  * machine dependent system variables.
  */
@@ -355,31 +302,28 @@
 sysctl_machdep_boot(SYSCTLFN_ARGS)
 {
        struct sysctlnode node = *rnode;
-       u_int chosen;
-       char bootargs[256];
-       const char *cp;
-
-       if ((chosen = OF_finddevice("/chosen")) == -1)
-               return (ENOENT);
-       if (node.sysctl_num == CPU_BOOTED_DEVICE)
-               cp = "bootpath";
-       else
-               cp = "bootargs";
-       if (OF_getprop(chosen, cp, bootargs, sizeof bootargs) < 0)
-               return (ENOENT);
+       char bootpath[256];
+       const char *cp = NULL;
+       extern char ofbootpath[], *ofbootpartition, *ofbootfile, *ofbootflags;
 
        switch (node.sysctl_num) {
        case CPU_BOOTED_KERNEL:
-               cp = parse_bootfile(bootargs);
-                if (cp != NULL && cp[0] == '\0')
+               cp = ofbootfile;
+                if (cp == NULL || cp[0] == '\0')
                         /* Unknown to firmware, return default name */
                         cp = "netbsd";
                break;
        case CPU_BOOT_ARGS:
-               cp = parse_bootargs(bootargs);
+               cp = ofbootflags;
                break;
        case CPU_BOOTED_DEVICE:
-               cp = bootargs;
+               if (ofbootpartition) {
+                       snprintf(bootpath, sizeof(bootpath), "%s:%s",
+                           ofbootpath, ofbootpartition);
+                       cp = bootpath;
+               } else {
+                       cp = ofbootpath;
+               }
                break;
        }
 



Home | Main Index | Thread Index | Old Index