Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode - initialize cpu_info_primary early, befor...



details:   https://anonhg.NetBSD.org/src/rev/0570821a888c
branches:  trunk
changeset: 768255:0570821a888c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Aug 13 10:31:24 2011 +0000

description:
- initialize cpu_info_primary early, before cpu0 attaches
- track idepth in cpu_info struct and use it in cpu_intr_p
- for debug and diagnostic kernels, abort when rebooting
- fill in __cpu_simple_lock_* stubs
- splraise(IPL_HIGH) before calling kernmain
- pmap_extract: only return phys addr if pap is not NULL

diffstat:

 sys/arch/usermode/dev/clock.c        |  12 +++++-------
 sys/arch/usermode/dev/cpu.c          |  30 ++++++++++++++++++++++--------
 sys/arch/usermode/include/cpu.h      |   5 +++--
 sys/arch/usermode/include/lock.h     |  21 ++++++++++++++-------
 sys/arch/usermode/usermode/machdep.c |   6 ++++--
 sys/arch/usermode/usermode/pmap.c    |  13 ++++---------
 6 files changed, 52 insertions(+), 35 deletions(-)

diffs (263 lines):

diff -r 91b0e79c4c38 -r 0570821a888c sys/arch/usermode/dev/clock.c
--- a/sys/arch/usermode/dev/clock.c     Sat Aug 13 02:49:06 2011 +0000
+++ b/sys/arch/usermode/dev/clock.c     Sat Aug 13 10:31:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.6 2011/08/12 00:57:24 jmcneill Exp $ */
+/* $NetBSD: clock.c,v 1.7 2011/08/13 10:31:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.6 2011/08/12 00:57:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.7 2011/08/13 10:31:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -101,13 +101,11 @@
        extern int usermode_x;
        struct clockframe cf;
 
-#if notyet
-       /* XXXJDM */
-       if (usermode_x > IPL_SOFTCLOCK)
-               return;
-#endif
+       curcpu()->ci_idepth++;
 
        hardclock(&cf);
+
+       curcpu()->ci_idepth--;
 }
 
 static u_int
diff -r 91b0e79c4c38 -r 0570821a888c sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c       Sat Aug 13 02:49:06 2011 +0000
+++ b/sys/arch/usermode/dev/cpu.c       Sat Aug 13 10:31:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $ */
+/* $NetBSD: cpu.c,v 1.13 2011/08/13 10:31:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.13 2011/08/13 10:31:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -54,7 +54,13 @@
 static int     cpu_match(device_t, cfdata_t, void *);
 static void    cpu_attach(device_t, device_t, void *);
 
-struct cpu_info cpu_info_primary;
+struct cpu_info cpu_info_primary = {
+       .ci_dev = 0,
+       .ci_self = &cpu_info_primary,
+       .ci_idepth = -1,
+       .ci_curlwp = &lwp0,
+};
+
 char cpu_model[48] = "virtual processor";
 
 typedef struct cpu_softc {
@@ -87,9 +93,6 @@
 
        sc->sc_dev = self;
        sc->sc_ci = &cpu_info_primary;
-       sc->sc_ci->ci_dev = 0;
-       sc->sc_ci->ci_self = &cpu_info_primary;
-       sc->sc_ci->ci_curlwp = &lwp0;
 
        if (thunk_getcontext(&lwp0pcb))
                panic("getcontext failed");
@@ -126,6 +129,10 @@
 
        printf("rebooting...\n");
 
+#if defined(DIAGNOSTIC) || defined(DEBUG)
+       thunk_abort();
+#endif
+
        usermode_reboot();
 
        /* NOTREACHED */
@@ -310,6 +317,8 @@
 {
        char pbuf[9];
 
+       banner();
+
        printf("%s%s", copyright, version);
        format_bytes(pbuf, sizeof(pbuf), ptoa(physmem));
        printf("total memory = %s\n", pbuf);
@@ -335,6 +344,11 @@
 bool
 cpu_intr_p(void)
 {
-       printf("cpu_intr_p\n");
-       return false;
+       int idepth;
+
+       kpreempt_disable();
+       idepth = curcpu()->ci_idepth;
+       kpreempt_enable();
+
+       return (idepth >= 0);
 }
diff -r 91b0e79c4c38 -r 0570821a888c sys/arch/usermode/include/cpu.h
--- a/sys/arch/usermode/include/cpu.h   Sat Aug 13 02:49:06 2011 +0000
+++ b/sys/arch/usermode/include/cpu.h   Sat Aug 13 10:31:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.5 2011/08/12 00:57:24 jmcneill Exp $ */
+/* $NetBSD: cpu.h,v 1.6 2011/08/13 10:31:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -33,7 +33,6 @@
 #include <sys/cpu_data.h>
 
 #include <machine/intrdefs.h>
-#include <machine/thunk.h>
 
 extern void    cpu_signotify(struct lwp *);
 extern void    cpu_need_proftick(struct lwp *);
@@ -45,6 +44,7 @@
        struct cpu_data ci_data;
        u_int           ci_cpuid;
        int             ci_want_resched;
+       int             ci_idepth;
        volatile int    ci_mtx_count;
        volatile int    ci_mtx_oldspl;
        lwp_t           *ci_curlwp;
@@ -62,6 +62,7 @@
 __inline static void
 usermode_delay(unsigned int ms)
 {
+       extern int thunk_usleep(unsigned int);
        thunk_usleep(ms);
 }
 
diff -r 91b0e79c4c38 -r 0570821a888c sys/arch/usermode/include/lock.h
--- a/sys/arch/usermode/include/lock.h  Sat Aug 13 02:49:06 2011 +0000
+++ b/sys/arch/usermode/include/lock.h  Sat Aug 13 10:31:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lock.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
+/* $NetBSD: lock.h,v 1.3 2011/08/13 10:31:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -32,16 +32,29 @@
 __inline static void
 __cpu_simple_lock_init(__cpu_simple_lock_t *lockp)
 {
+       *lockp = __SIMPLELOCK_UNLOCKED;
+}
+
+__inline static int
+__cpu_simple_lock_try(__cpu_simple_lock_t *lockp)
+{
+       if (*lockp == __SIMPLELOCK_LOCKED)
+               return 0;
+       *lockp = __SIMPLELOCK_LOCKED;
+       return 1;
 }
 
 __inline static void
 __cpu_simple_lock(__cpu_simple_lock_t *lockp)
 {
+       while (!__cpu_simple_lock_try(lockp))
+               ;
 }
 
 __inline static void
 __cpu_simple_unlock(__cpu_simple_lock_t *lockp)
 {
+       *lockp = __SIMPLELOCK_UNLOCKED;
 }
 
 __inline static int
@@ -56,10 +69,4 @@
        return *lockp == __SIMPLELOCK_UNLOCKED;
 }
 
-__inline static int
-__cpu_simple_lock_try(__cpu_simple_lock_t *lockp)
-{
-       return __SIMPLELOCK_UNLOCKED;
-}
-
 #endif /* !_ARCH_USERMODE_INCLUDE_LOCK_H */
diff -r 91b0e79c4c38 -r 0570821a888c sys/arch/usermode/usermode/machdep.c
--- a/sys/arch/usermode/usermode/machdep.c      Sat Aug 13 02:49:06 2011 +0000
+++ b/sys/arch/usermode/usermode/machdep.c      Sat Aug 13 10:31:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $ */
+/* $NetBSD: machdep.c,v 1.13 2011/08/13 10:31:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.13 2011/08/13 10:31:24 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -94,6 +94,8 @@
 
        pmap_bootstrap();
 
+       splraise(IPL_HIGH);
+
        kernmain();
 }
 
diff -r 91b0e79c4c38 -r 0570821a888c sys/arch/usermode/usermode/pmap.c
--- a/sys/arch/usermode/usermode/pmap.c Sat Aug 13 02:49:06 2011 +0000
+++ b/sys/arch/usermode/usermode/pmap.c Sat Aug 13 10:31:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.7 2011/08/11 22:26:18 jmcneill Exp $ */
+/* $NetBSD: pmap.c,v 1.8 2011/08/13 10:31:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.7 2011/08/11 22:26:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.8 2011/08/13 10:31:24 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -70,12 +70,6 @@
        virtual_avail += PAGE_SIZE;
 
        pmap_maxkvaddr = VM_MIN_KERNEL_ADDRESS;
-#if 0
-       kmeminit_nkmempages();
-       bufsz = buf_memcalc();
-       if (buf_setvalimit(bufsz))
-               panic("pmap_bootstrap: buf_setvalimit failed\n");
-#endif
 }
 
 void
@@ -172,7 +166,8 @@
 pmap_extract(pmap_t pmap, vaddr_t va, paddr_t *pap)
 {
        /* XXXJDM */
-       *pap = va;
+       if (pap)
+               *pap = va;
        return true;
 }
 



Home | Main Index | Thread Index | Old Index