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

[Minios-devel] [UNIKRAFT PATCH v2 6/7] lib/ukboot: Replace the parser with the uklibparam



We replace the existing parser in linuxu platform with uklibparam.
The library parsing is performed during the boot after constructor
initialization.

Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 lib/ukboot/boot.c    |  20 +++++--
 plat/linuxu/memory.c |  29 +++++++++-
 plat/linuxu/setup.c  | 125 -------------------------------------------
 3 files changed, 45 insertions(+), 129 deletions(-)

diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
index 97c7d18b..9738a912 100644
--- a/lib/ukboot/boot.c
+++ b/lib/ukboot/boot.c
@@ -61,6 +61,9 @@
 #if CONFIG_LIBUKBUS
 #include <uk/bus.h>
 #endif /* CONFIG_LIBUKBUS */
+#ifdef CONFIG_LIBUKLIBPARAM
+#include <uk/libparam.h>
+#endif /* CONFIG_LIBUKLIBPARAM */
 
 int main(int argc, char *argv[]) __weak;
 #ifdef CONFIG_LIBLWIP
@@ -165,9 +168,10 @@ void ukplat_entry(int argc, char *argv[])
 {
        const uk_ctor_func_t *cfn;
        struct thread_main_arg tma;
+       int kern_args = 0;
+       int rc __maybe_unused = 0;
 #if CONFIG_LIBUKALLOC
        struct uk_alloc *a = NULL;
-       int rc;
 #endif
 #if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
        struct ukplat_memregion_desc md;
@@ -183,6 +187,16 @@ void ukplat_entry(int argc, char *argv[])
                (*cfn)();
        }
 
+#ifdef CONFIG_LIBUKLIBPARAM
+       rc = (argc > 1) ? uk_libparam_parse(argv[0], argc - 1, &argv[1]) : 0;
+       if (unlikely(rc < 0))
+               uk_pr_crit("Failed to parse the kernel argument\n");
+       else {
+               kern_args = rc;
+               uk_pr_info("Found %d library args\n", kern_args);
+       }
+#endif /* CONFIG_LIBUKLIBPARAM */
+
 #if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
        /* initialize memory allocator
         * FIXME: ukallocbbuddy is hard-coded for now
@@ -236,8 +250,8 @@ void ukplat_entry(int argc, char *argv[])
                UK_CRASH("Could not initialize the scheduler\n");
 #endif
 
-       tma.argc = argc;
-       tma.argv = argv;
+       tma.argc = argc - kern_args;
+       tma.argv = &argv[kern_args];
 
 #if CONFIG_LIBUKSCHED
        main_thread = uk_thread_create("main", main_thread_func, &tma);
diff --git a/plat/linuxu/memory.c b/plat/linuxu/memory.c
index c5b32201..bdea2aae 100644
--- a/plat/linuxu/memory.c
+++ b/plat/linuxu/memory.c
@@ -47,10 +47,37 @@
 static __u32 heap_size = CONFIG_LINUXU_DEFAULT_HEAPMB;
 UK_LIB_PARAM(heap_size, __u32);
 
+static int __linuxu_plat_heap_init(void)
+{
+       void *pret;
+       int rc = 0;
+
+       _liblinuxuplat_opts.heap.len = heap_size * MB2B;
+       uk_pr_info("Heap size %u\n", heap_size);
+
+       /**
+        * Allocate heap memory
+        */
+       if (_liblinuxuplat_opts.heap.len > 0) {
+               pret = sys_mapmem(NULL, _liblinuxuplat_opts.heap.len);
+               if (PTRISERR(pret)) {
+                       rc = PTR2ERR(pret);
+                       uk_pr_err("Failed to allocate memory for heap: %d\n",
+                                  rc);
+               } else
+                       _liblinuxuplat_opts.heap.base = pret;
+       }
+
+       return rc;
+
+}
 
 int ukplat_memregion_count(void)
 {
-       return _liblinuxuplat_opts.heap.base ? 1 : 0;
+       int rc = 0;
+
+       rc = __linuxu_plat_heap_init();
+       return (rc == 0) ? 1 : 0;
 }
 
 int ukplat_memregion_get(int i, struct ukplat_memregion_desc *m)
diff --git a/plat/linuxu/setup.c b/plat/linuxu/setup.c
index 50454437..863d30ff 100644
--- a/plat/linuxu/setup.c
+++ b/plat/linuxu/setup.c
@@ -35,12 +35,10 @@
 
 #include <uk/config.h>
 #include <string.h>
-#include <errno.h>
 #include <getopt.h>
 #include <stdlib.h>
 #include <linuxu/setup.h>
 #include <linuxu/console.h>
-#include <linuxu/syscall.h>
 #include <uk/plat/console.h>
 #include <uk/plat/bootstrap.h>
 #include <uk/assert.h>
@@ -49,108 +47,10 @@
 
 struct liblinuxuplat_opts _liblinuxuplat_opts = { 0 };
 
-#define _coutk_chr(c)                          \
-       ukplat_coutk((char *) &(c), 1)
-#define _coutk_str(str)                                \
-       ukplat_coutk((str), strlen(str))
-
-static const char *sopts = "h?Vm:";
-static struct option lopts[] = {
-       {"help",        no_argument,            NULL,   'h'},
-       {"version",     no_argument,            NULL,   'V'},
-       {"heapmem",     required_argument,      NULL,   'm'},
-       {NULL, 0, NULL, 0}
-};
-
-static void version(void)
-{
-       _coutk_str("Unikraft "
-                  STRINGIFY(UK_CODENAME) " "
-                  STRINGIFY(UK_FULLVERSION) "\n");
-}
-
-static void usage(const char *progname)
-{
-       _coutk_str("Usage: ");
-       _coutk_str(progname);
-       _coutk_str(" [[LINUXU PLATFORM ARGUMENT]].. -- [[ARGUMENT]]..\n\n");
-       _coutk_str("Unikraft LinuxU platform arguments:\n");
-       _coutk_str("Mandatory arguments to long options are mandatory for short 
options too.\n");
-       _coutk_str("  -h, --help                 display this help and exit\n");
-       _coutk_str("  -V, --version              display Unikraft version and 
exit\n");
-       _coutk_str("  -m, --heapmem [MBYTES]     allocate MBYTES as heap 
memory\n");
-}
-
-static int parseopts(int argc, char *argv[], struct liblinuxuplat_opts *opts)
-{
-       const char *progname = argv[0];
-       char *old_optarg;
-       int old_optind;
-       int old_optopt;
-       char **argvopt;
-       int opt, optidx;
-       int ret;
-
-       /*
-        * Clear & set default options
-        */
-       memset(opts, 0, sizeof(*opts));
-       _liblinuxuplat_opts.heap.len = (size_t)(CONFIG_LINUXU_DEFAULT_HEAPMB)
-                                       * 1024 * 1024;
-
-       /*
-        * Parse arguments
-        */
-       old_optind = optind;
-       old_optopt = optopt;
-       old_optarg = optarg;
-       argvopt = argv;
-       optind = 1;
-       while ((opt = getopt_long(argc, argvopt, sopts, lopts, &optidx)) >= 0) {
-               switch (opt) {
-               case 'h':
-               case '?': /* usage */
-                       usage(progname);
-                       ukplat_halt();
-               case 'V': /* version */
-                       version();
-                       ukplat_halt();
-               case 'm':
-                       _liblinuxuplat_opts.heap.len = (((size_t)
-                                                        strtoul(optarg,
-                                                                NULL, 10))
-                                                       * 1024 * 1024);
-                       break;
-               default:
-                       _coutk_str(progname);
-                       _coutk_str(": invalid option: -");
-                       _coutk_chr(opt);
-                       _coutk_str("\n");
-                       usage(progname);
-                       ret = -EINVAL;
-                       goto out;
-               }
-       }
-       ret = optind;
-
-out:
-       /*
-        * Restore getopt state for later calls
-        */
-       optind = old_optind;
-       optopt = old_optopt;
-       optarg = old_optarg;
-       return ret;
-}
-
 void _liblinuxuplat_entry(int argc, char *argv[]) __noreturn;
 
 void _liblinuxuplat_entry(int argc, char *argv[])
 {
-       char *progname = argv[0];
-       int ret;
-       void *pret;
-
        _init_cpufeatures();
 
        /*
@@ -158,31 +58,6 @@ void _liblinuxuplat_entry(int argc, char *argv[])
         */
        _liblinuxuplat_init_console();
 
-       /*
-        * Parse LinuxU platform arguments
-        */
-       if ((ret = parseopts(argc, argv, &_liblinuxuplat_opts)) < 0)
-               ukplat_crash();
-
-       /*
-        * Remove arguments related to LinuxU platform
-        * and set progname again as argument 0
-        */
-       argc -= (ret - 1);
-       argv += (ret - 1);
-       argv[0] = progname;
-
-       /*
-        * Allocate heap memory
-        */
-       if (_liblinuxuplat_opts.heap.len > 0) {
-               pret = sys_mapmem(NULL, _liblinuxuplat_opts.heap.len);
-               if (PTRISERR(pret))
-                       uk_pr_err("Failed to allocate memory for heap: %d\n", 
PTR2ERR(pret));
-               else
-                       _liblinuxuplat_opts.heap.base = pret;
-       }
-
        /*
         * Enter Unikraft
         */
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.