]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/linuxu: Avoid re-initialization of the `heap` and `initrd`
authorDiego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
Wed, 10 May 2023 11:12:39 +0000 (14:12 +0300)
committerUnikraft <monkey@unikraft.io>
Wed, 10 May 2023 11:23:43 +0000 (11:23 +0000)
Keep a locally declared static variable `init` to cache the
current amount of memory region descriptors. This way, whenever
`ukplat_memregion_count` is called, `__linuxu_plat_heap_init` and
`__linuxu_plat_initrd_init` do not have to be executed more than
once.

Co-authored-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Diego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #878

plat/linuxu/memory.c

index 42426044807657e05b905e8d0bd5d346671e99f6..2410de291eaacf70924f868b36e940e2e4b5cad1 100644 (file)
@@ -127,27 +127,19 @@ static int __linuxu_plat_initrd_init(void)
 
 int ukplat_memregion_count(void)
 {
-       static int have_heap = 0;
-       static int have_initrd = 0;
-       int rc = 0;
+       static int init;
+       int rc;
 
-       /*
-        * NOTE: The heap size and initrd file can be changed by a
-        * library parameter. We assume that those ones are processed
-        * by the boot library shortly before memory regions are
-        * scanned. This is why we initialize the heap here.
-        */
-       if (!have_heap) {
-               rc = __linuxu_plat_heap_init();
-               have_heap = (rc == 0) ? 1 : 0;
-       }
+       if (init)
+               return init;
 
-       if (!have_initrd) {
-               rc = __linuxu_plat_initrd_init();
-               have_initrd = (rc == 0) ? 1 : 0;
-       }
+       rc = __linuxu_plat_heap_init();
+       init += (rc == 0) ? 1 : 0;
+
+       rc = __linuxu_plat_initrd_init();
+       init += (rc == 0) ? 1 : 0;
 
-       return have_heap + have_initrd;
+       return init;
 }
 
 int ukplat_memregion_get(int i, struct ukplat_memregion_desc **m)