Source-Changes-HG archive

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

[src/trunk]: src/sys/arch the i386 and amd64 boot time msgbuf init code is ne...



details:   https://anonhg.NetBSD.org/src/rev/aa51c4bfd90e
branches:  trunk
changeset: 820003:aa51c4bfd90e
user:      cherry <cherry%NetBSD.org@localhost>
date:      Mon Dec 26 17:54:06 2016 +0000

description:
the i386 and amd64 boot time msgbuf init code is nearly identical.

Unify them into x86/x86_machdep.c:init_x86_msgbuf()

Boot tested on GENERIC (i386, amd64), XEN3_DOM0 (amd64)

diffstat:

 sys/arch/amd64/amd64/machdep.c |  60 ++--------------------------------------
 sys/arch/i386/i386/machdep.c   |  58 ++-------------------------------------
 sys/arch/x86/include/machdep.h |  13 ++++++++-
 sys/arch/x86/x86/x86_machdep.c |  62 +++++++++++++++++++++++++++++++++++++++--
 4 files changed, 76 insertions(+), 117 deletions(-)

diffs (truncated from 324 to 300 lines):

diff -r 636b70248b12 -r aa51c4bfd90e sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Mon Dec 26 16:20:17 2016 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Mon Dec 26 17:54:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.245 2016/12/26 13:55:13 cherry Exp $     */
+/*     $NetBSD: machdep.c,v 1.246 2016/12/26 17:54:06 cherry Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.245 2016/12/26 13:55:13 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.246 2016/12/26 17:54:06 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -254,14 +254,6 @@
 size_t dump_header_size;
 size_t dump_totalbytesleft;
 
-vaddr_t msgbuf_vaddr;
-
-struct {
-       paddr_t paddr;
-       psize_t sz;
-} msgbuf_p_seg[VM_PHYSSEG_MAX];
-unsigned int msgbuf_p_cnt = 0;
-
 vaddr_t idt_vaddr;
 paddr_t idt_paddr;
 vaddr_t gdt_vaddr;
@@ -1466,52 +1458,6 @@
 extern vector *IDTVEC(exceptions)[];
 
 static void
-init_x86_64_msgbuf(void)
-{
-       /* Message buffer is located at end of core. */
-       psize_t sz = round_page(MSGBUFSIZE);
-       psize_t reqsz = sz;
-       uvm_physseg_t x;
-               
- search_again:
-        for (x = uvm_physseg_get_first();
-            uvm_physseg_valid_p(x);
-            x = uvm_physseg_get_next(x)) {
-
-               if (ctob(uvm_physseg_get_avail_end(x)) == avail_end)
-                       break;
-       }
-
-       if (uvm_physseg_valid_p(x) == false)
-               panic("init_x86_64: can't find end of memory");
-
-       /* Shrink so it'll fit in the last segment. */
-       if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
-               sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
-
-       uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
-       msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
-        msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
-
-       /* Now find where the new avail_end is. */
-       avail_end = ctob(uvm_physseg_get_avail_end(x));
-
-       if (sz == reqsz)
-               return;
-
-       reqsz -= sz;
-       if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
-               /* No more segments available, bail out. */
-               printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
-                   (size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
-               return;
-       }
-
-       sz = reqsz;
-       goto search_again;
-}
-
-static void
 init_x86_64_ksyms(void)
 {
 #if NKSYMS || defined(DDB) || defined(MODULAR)
@@ -1640,7 +1586,7 @@
            atop(avail_start), atop(avail_end), VM_FREELIST_DEFAULT);
 #endif
 
-       init_x86_64_msgbuf();
+       init_x86_msgbuf();
 
        pmap_growkernel(VM_MIN_KERNEL_ADDRESS + 32 * 1024 * 1024);
 
diff -r 636b70248b12 -r aa51c4bfd90e sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Mon Dec 26 16:20:17 2016 +0000
+++ b/sys/arch/i386/i386/machdep.c      Mon Dec 26 17:54:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $     */
+/*     $NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -236,13 +236,6 @@
 int i386_has_sse;
 int i386_has_sse2;
 
-vaddr_t msgbuf_vaddr;
-struct {
-       paddr_t paddr;
-       psize_t sz;
-} msgbuf_p_seg[VM_PHYSSEG_MAX];
-unsigned int msgbuf_p_cnt = 0;
-
 vaddr_t idt_vaddr;
 paddr_t idt_paddr;
 vaddr_t gdt_vaddr;
@@ -1034,51 +1027,6 @@
 #endif /* !XEN */
 }
 
-static void
-init386_msgbuf(void)
-{
-       /* Message buffer is located at end of core. */
-       psize_t sz = round_page(MSGBUFSIZE);
-       psize_t reqsz = sz;
-       uvm_physseg_t x;
-               
-search_again:
-        for (x = uvm_physseg_get_first();
-            uvm_physseg_valid_p(x);
-            x = uvm_physseg_get_next(x)) {
-               if (ctob(uvm_physseg_get_avail_end(x)) == avail_end) {
-                       break;
-               }
-       }
-       if (uvm_physseg_valid_p(x) == false)
-               panic("init386: can't find end of memory");
-
-       /* Shrink so it'll fit in the last segment. */
-       if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
-               sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
-
-       uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
-       msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
-        msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
-
-       /* Now find where the new avail_end is. */
-       avail_end = ctob(uvm_physseg_get_avail_end(x));
-
-       if (sz == reqsz)
-               return;
-
-       reqsz -= sz;
-       if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
-               /* No more segments available, bail out. */
-               printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
-                   (size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
-               return;
-       }
-
-       sz = reqsz;
-       goto search_again;
-}
-
 #ifndef XEN
 static void
 init386_pte0(void)
@@ -1273,7 +1221,7 @@
 
 #endif /* !XEN */
 
-       init386_msgbuf();
+       init_x86_msgbuf();
 
 #if !defined(XEN) && NBIOSCALL > 0
        /*
diff -r 636b70248b12 -r aa51c4bfd90e sys/arch/x86/include/machdep.h
--- a/sys/arch/x86/include/machdep.h    Mon Dec 26 16:20:17 2016 +0000
+++ b/sys/arch/x86/include/machdep.h    Mon Dec 26 17:54:06 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.8 2016/07/16 17:02:34 maxv Exp $ */
+/* $NetBSD: machdep.h,v 1.9 2016/12/26 17:54:07 cherry Exp $ */
 /*
  * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,11 +32,21 @@
 
 extern phys_ram_seg_t mem_clusters[];
 extern int mem_cluster_cnt;
+extern vaddr_t msgbuf_vaddr;
+extern unsigned int msgbuf_p_cnt;
+
 
 struct btinfo_memmap;
 struct extent;
 struct sysctllog;
 
+struct msgbuf_p_seg {
+       paddr_t paddr;
+       psize_t sz;
+};
+
+extern struct msgbuf_p_seg msgbuf_p_seg[];
+
 void   x86_cpu_idle_init(void);
 void   x86_cpu_idle_get(void (**)(void), char *, size_t);
 void   x86_cpu_idle_set(void (*)(void), const char *, bool);
@@ -45,6 +55,7 @@
 
 void   init_x86_clusters(void);
 int    init_x86_vm(paddr_t);
+void   init_x86_msgbuf(void);
 
 void   x86_startup(void);
 void   x86_sysctl_machdep_setup(struct sysctllog **);
diff -r 636b70248b12 -r aa51c4bfd90e sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Mon Dec 26 16:20:17 2016 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Mon Dec 26 17:54:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_machdep.c,v 1.79 2016/12/20 14:03:15 maxv Exp $    */
+/*     $NetBSD: x86_machdep.c,v 1.80 2016/12/26 17:54:07 cherry Exp $  */
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.79 2016/12/20 14:03:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.80 2016/12/26 17:54:07 cherry Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -101,6 +101,16 @@
 
 static kauth_listener_t x86_listener;
 
+extern paddr_t lowmem_rsvd, avail_start, avail_end;
+
+vaddr_t msgbuf_vaddr;
+
+struct msgbuf_p_seg msgbuf_p_seg[VM_PHYSSEG_MAX];
+
+unsigned int msgbuf_p_cnt = 0;
+
+void init_x86_msgbuf(void);
+
 /*
  * Given the type of a bootinfo entry, looks for a matching item inside
  * the bootinfo structure.  If found, returns a pointer to it (which must
@@ -482,8 +492,6 @@
        { VM_FREELIST_FIRST16,  16 * 1024 * 1024 },
 };
 
-extern paddr_t lowmem_rsvd, avail_end;
-
 int
 x86_select_freelist(uint64_t maxaddr)
 {
@@ -902,6 +910,52 @@
 #endif /* !XEN */
 
 void
+init_x86_msgbuf(void)
+{
+       /* Message buffer is located at end of core. */
+       psize_t sz = round_page(MSGBUFSIZE);
+       psize_t reqsz = sz;
+       uvm_physseg_t x;
+               
+ search_again:
+        for (x = uvm_physseg_get_first();
+            uvm_physseg_valid_p(x);
+            x = uvm_physseg_get_next(x)) {
+
+               if (ctob(uvm_physseg_get_avail_end(x)) == avail_end)
+                       break;
+       }
+
+       if (uvm_physseg_valid_p(x) == false)
+               panic("init_x86_msgbuf: can't find end of memory");
+
+       /* Shrink so it'll fit in the last segment. */
+       if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
+               sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
+
+       uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
+       msgbuf_p_seg[msgbuf_p_cnt].sz = sz;



Home | Main Index | Thread Index | Old Index