Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/i386/stand Pre-allocate memory for the kernel space...



details:   https://anonhg.NetBSD.org/src/rev/7043c6a0bbeb
branches:  trunk
changeset: 462178:7043c6a0bbeb
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Fri Jul 26 12:09:48 2019 +0000

description:
Pre-allocate memory for the kernel space at startup.

diffstat:

 sys/arch/i386/stand/efiboot/boot.c      |  28 +--------------
 sys/arch/i386/stand/efiboot/efimemory.c |  16 +++++++-
 sys/arch/i386/stand/lib/exec.c          |  60 +--------------------------------
 sys/arch/i386/stand/lib/libi386.h       |   3 +-
 4 files changed, 18 insertions(+), 89 deletions(-)

diffs (185 lines):

diff -r dfc73944197d -r 7043c6a0bbeb sys/arch/i386/stand/efiboot/boot.c
--- a/sys/arch/i386/stand/efiboot/boot.c        Fri Jul 26 11:38:21 2019 +0000
+++ b/sys/arch/i386/stand/efiboot/boot.c        Fri Jul 26 12:09:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.11 2019/06/20 17:33:31 maxv Exp $   */
+/*     $NetBSD: boot.c,v 1.12 2019/07/26 12:09:48 nonaka Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -226,40 +226,16 @@
 static void
 bootit(const char *filename, int howto)
 {
-       EFI_STATUS status;
-       EFI_PHYSICAL_ADDRESS bouncebuf;
-       UINTN npages;
-       u_long allocsz;
 
        if (howto & AB_VERBOSE)
                printf("booting %s (howto 0x%x)\n", sprint_bootsel(filename),
                    howto);
 
-       if (count_netbsd(filename, &allocsz) < 0) {
-               printf("boot: %s: %s\n", sprint_bootsel(filename),
-                      strerror(errno));
-               return;
-       }
-
-       bouncebuf = EFI_ALLOCATE_MAX_ADDRESS;
-       npages = EFI_SIZE_TO_PAGES(allocsz);
-       status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress,
-           EfiLoaderData, npages, &bouncebuf);
-       if (EFI_ERROR(status)) {
-               printf("boot: %s: %s\n", sprint_bootsel(filename),
-                      strerror(ENOMEM));
-               return;
-       }
-
-       efi_loadaddr = bouncebuf;
-       if (exec_netbsd(filename, bouncebuf, howto, 0, efi_cleanup) < 0)
+       if (exec_netbsd(filename, efi_loadaddr, howto, 0, efi_cleanup) < 0)
                printf("boot: %s: %s\n", sprint_bootsel(filename),
                       strerror(errno));
        else
                printf("boot returned\n");
-
-       (void) uefi_call_wrapper(BS->FreePages, 2, bouncebuf, npages);
-       efi_loadaddr = 0;
 }
 
 void
diff -r dfc73944197d -r 7043c6a0bbeb sys/arch/i386/stand/efiboot/efimemory.c
--- a/sys/arch/i386/stand/efiboot/efimemory.c   Fri Jul 26 11:38:21 2019 +0000
+++ b/sys/arch/i386/stand/efiboot/efimemory.c   Fri Jul 26 12:09:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efimemory.c,v 1.5 2018/03/27 14:15:05 nonaka Exp $     */
+/*     $NetBSD: efimemory.c,v 1.6 2019/07/26 12:09:48 nonaka Exp $     */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -64,6 +64,10 @@
        "PersistentMemory",
 };
 
+#ifndef KERN_LOADSPACE_SIZE
+#define KERN_LOADSPACE_SIZE    (128 * 1024 * 1024)     /* 128MiB */
+#endif
+
 static int
 getmemtype(EFI_MEMORY_DESCRIPTOR *md)
 {
@@ -231,13 +235,21 @@
 efi_memory_probe(void)
 {
        EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next;
+       EFI_STATUS status;
+       EFI_PHYSICAL_ADDRESS bouncebuf;
        UINTN i, n, NoEntries, MapKey, DescriptorSize, MappingSize;
        UINT32 DescriptorVersion;
        int memtype;
 
+       bouncebuf = EFI_ALLOCATE_MAX_ADDRESS;
+       status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress,
+           EfiLoaderData, EFI_SIZE_TO_PAGES(KERN_LOADSPACE_SIZE), &bouncebuf);
+       if (EFI_ERROR(status))
+               panic("couldn't allocate kernel space.");
+       efi_loadaddr = bouncebuf;
+
        mdtop = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize,
            &DescriptorVersion, false);
-
        printf(" mem[");
        for (i = 0, n = 0, md = mdtop; i < NoEntries; i++, md = next) {
                next = NextMemoryDescriptor(md, DescriptorSize);
diff -r dfc73944197d -r 7043c6a0bbeb sys/arch/i386/stand/lib/exec.c
--- a/sys/arch/i386/stand/lib/exec.c    Fri Jul 26 11:38:21 2019 +0000
+++ b/sys/arch/i386/stand/lib/exec.c    Fri Jul 26 12:09:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec.c,v 1.72 2019/06/24 13:58:24 pgoyette Exp $        */
+/*     $NetBSD: exec.c,v 1.73 2019/07/26 12:09:48 nonaka Exp $  */
 
 /*
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -573,64 +573,6 @@
        return -1;
 }
 
-int
-count_netbsd(const char *file, u_long *rsz)
-{
-       u_long marks[MARK_MAX];
-       char kdev[64];
-       char base_path[64] = "/";
-       struct stat st;
-       boot_module_t *bm;
-       u_long sz;
-       int err, fd;
-
-       if (has_prekern) {
-               /*
-                * Hardcoded for now. Need to count both the prekern and the
-                * kernel. 128MB is enough in all cases, so use that.
-                */
-               *rsz = (128UL << 20);
-               return 0;
-       }
-
-       howto = AB_SILENT;
-
-       memset(marks, 0, sizeof(marks));
-       if ((fd = loadfile(file, marks, COUNT_KERNEL | LOAD_NOTE)) == -1)
-               return -1;
-       close(fd);
-       marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
-           (-sizeof(int));
-       sz = marks[MARK_END];
-
-       /* The modules must be allocated after the kernel */
-       if (boot_modules_enabled) {
-               extract_device(file, kdev, sizeof(kdev));
-               module_base_path(base_path, sizeof(base_path));
-
-               /* If the root fs type is unusual, load its module. */
-               if (fsmod != NULL)
-                       module_add_split(fsmod, BM_TYPE_KMOD);
-
-               for (bm = boot_modules; bm; bm = bm->bm_next) {
-                       fd = module_open(bm, 0, kdev, base_path, false);
-                       if (fd == -1)
-                               continue;
-                       sz = (sz + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
-                       err = fstat(fd, &st);
-                       if (err == -1 || st.st_size == -1) {
-                               close(fd);
-                               continue;
-                       }
-                       sz += st.st_size;
-                       close(fd);
-               }
-       }
-
-       *rsz = sz;
-       return 0;
-}
-
 static void
 extract_device(const char *path, char *buf, size_t buflen)
 {
diff -r dfc73944197d -r 7043c6a0bbeb sys/arch/i386/stand/lib/libi386.h
--- a/sys/arch/i386/stand/lib/libi386.h Fri Jul 26 11:38:21 2019 +0000
+++ b/sys/arch/i386/stand/lib/libi386.h Fri Jul 26 12:09:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libi386.h,v 1.43 2019/06/24 13:58:24 pgoyette Exp $    */
+/*     $NetBSD: libi386.h,v 1.44 2019/07/26 12:09:48 nonaka Exp $      */
 
 /*
  * Copyright (c) 1996
@@ -43,7 +43,6 @@
 
 int exec_netbsd(const char *, physaddr_t, int, int, void (*)(void));
 int exec_multiboot(const char *, char *);
-int count_netbsd(const char *, u_long *);
 
 void delay(int);
 int getbasemem(void);



Home | Main Index | Thread Index | Old Index