From: Diego Alejandro Parra Guzman Date: Wed, 10 May 2023 11:12:39 +0000 (+0300) Subject: plat/linuxu: Avoid re-initialization of the `heap` and `initrd` X-Git-Tag: RELEASE-0.13.0~29 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d57a4c7cd10ab8d781a089629cb310b8e8de3c91;p=unikraft%2Funikraft.git plat/linuxu: Avoid re-initialization of the `heap` and `initrd` 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 Signed-off-by: Sergiu Moga Signed-off-by: Diego Alejandro Parra Guzman Reviewed-by: Razvan Deaconescu Approved-by: Razvan Deaconescu Tested-by: Unikraft CI GitHub-Closes: #878 --- diff --git a/plat/linuxu/memory.c b/plat/linuxu/memory.c index 424260448..2410de291 100644 --- a/plat/linuxu/memory.c +++ b/plat/linuxu/memory.c @@ -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)