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

Re: [Minios-devel] [UNIKRAFT PATCH v2 2/9] include: Clean-ups to <uk/ctors.h>


  • To: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>, "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Fri, 31 Jan 2020 13:07:30 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D8Z4uIRiw+sXcui8KY5uCrxq+BVbXb4BfGQb1tqGW0A=; b=iPyy3WTjDhkMiuz1PETZqKd1sYmZnQMToT3IEHx3DlRswyLSXSEZOLOyxc+iW37PImoZJq8Ssdg0OgDPFZP3hM13VzILNEVGx7CvYygCdDRZ0sgTJcnA4Q2R/SkZbwcql7c4sBbB0u7lRPGs1dlqEzPVThxISl7qf18l2lftE0yP0PBHLrxEEwHiQwAVKJdjTOfU+TgD0KR7oiSct7mZbrly38zse5VU0eOTWd52anRSPKrbd/SbHlXqbPjgVWXJjLIZe0t9dazCGUH7rpZVo7MifN3TLGUkkXTWOsoAACaazVnv/amCNP12RLdQh4E67gtIeqN7AoqZrThAkRVsWQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ixTtvOwQb5kFuVZ3AQuxV1ZG7EOewsLD2XRwin5hXK7VdKghP124+n563Umnc8BxtuaMPDgAtxneLxO8G6RrQNY6PztxyPaPVkA4VoqYklnhr3HIyMCCGeCBKIv7cj4G3An7sK7erdMIWDhXfAaL38VZGGZwHaluHfo/WBt2kmrHJWMztCdqfyrxb6HTEDyVi8EEDUDLXLCvj66tCfLvgovogEPlEkQfZ5PpEElxKmOX5xjg+oxSIy2ODlFIXYBbcJUpLvQxy3OGbYxRtBQBP7ruLHK7Kf4PcCTrC9d0PKhWBaNf0UAHV4vNTjtq33mWwiUoVwvzILt4KzC7x0tbvQ==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Delivery-date: Fri, 31 Jan 2020 13:07:35 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHV18N0VaZOzrlICUqkgiJfG6HqUKgEvz8A
  • Thread-topic: [UNIKRAFT PATCH v2 2/9] include: Clean-ups to <uk/ctors.h>

Thanks!

Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

On 31.01.2020 01:17, Simon Kuenzer wrote:
> This commit brings the Unikraft constructor definitions closer to the
> one of the Unikraft Init table.
>
> UK_CTOR_FUNC() is basically replaced by UK_CTOR_PRIO(). Naming and
> argument order is derived from Init table definition <uk/init.h>.
>
> The table iterator is now similar as the one found in the Init
> table. Instead of providing an integer as index, the foreach-macro is
> directly iterating with a function pointer.
>
> Because of compatibility reasons, the previous macro UK_CTOR_FUNC() is
> still provided. The idea is that it gets removed as soon all depending
> code was updated (internal and external).
>
> Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
> ---
>   include/uk/ctors.h                            | 60 ++++++++++++-------
>   lib/ukboot/boot.c                             | 44 +++++++-------
>   lib/uklibparam/include/uk/libparam.h          |  2 +-
>   .../include/uk/plat/common/common.lds.h       |  2 +-
>   4 files changed, 62 insertions(+), 46 deletions(-)
>
> diff --git a/include/uk/ctors.h b/include/uk/ctors.h
> index e7d0dece..35e4cf49 100644
> --- a/include/uk/ctors.h
> +++ b/include/uk/ctors.h
> @@ -53,41 +53,55 @@ extern const uk_ctor_func_t __preinit_array_start[];
>   extern const uk_ctor_func_t __preinit_array_end;
>   extern const uk_ctor_func_t __init_array_start[];
>   extern const uk_ctor_func_t __init_array_end;
> -extern const uk_ctor_func_t uk_ctortab[];
> +extern const uk_ctor_func_t uk_ctortab_start[];
>   extern const uk_ctor_func_t uk_ctortab_end;
>   
>   /**
>    * Register a Unikraft constructor function that is
>    * called during bootstrap (uk_ctortab)
>    *
> - * @param lvl
> - *   Priority level (0 (higher) to 9 (least))
> - *   Note: Any other value for level will be ignored
> - * @param ctorf
> + * @param fn
>    *   Constructor function to be called
> + * @param prio
> + *   Priority level (0 (earliest) to 9 (latest))
> + *   Note: Any other value for level will be ignored
> + */
> +#define __UK_CTORTAB(fn, prio)                               \
> +     static const uk_ctor_func_t                     \
> +     __used __section(".uk_ctortab" #prio)           \
> +     __uk_ctortab ## prio ## _ ## fn = (fn)
> +
> +#define _UK_CTORTAB(fn, prio)                                \
> +     __UK_CTORTAB(fn, prio)
> +
> +#define UK_CTOR_PRIO(fn, prio)                               \
> +     _UK_CTORTAB(fn, prio)
> +
> +/**
> + * Similar interface without priority.
>    */
> -#define __UK_CTOR_FUNC(lvl, ctorf) \
> -             static const uk_ctor_func_t     \
> -             __used __section(".uk_ctortab" #lvl)    \
> -             __uk_ctab ## lvl ## _ ## ctorf = (ctorf)
> -#define UK_CTOR_FUNC(lvl, ctorf) __UK_CTOR_FUNC(lvl, ctorf)
> +#define UK_CTOR(fn) UK_CTOR_PRIO(fn, 9)
> +
> +/* DELETEME: Compatibility wrapper for existing code, to be removed! */
> +#define UK_CTOR_FUNC(lvl, ctorf) \
> +     _UK_CTORTAB(ctorf, lvl)
>   
>   /**
> - * Helper macro for iterating over constructor pointer arrays
> - * Please note that the array may contain NULL pointer entries
> + * Helper macro for iterating over constructor pointer tables
> + * Please note that the table may contain NULL pointer entries
>    *
> - * @param arr_start
> - *   Start address of pointer array (type: const uk_ctor_func_t const [])
> - * @param arr_end
> - *   End address of pointer array
> - * @param i
> - *   Iterator variable (integer) which should be used to access the
> - *   individual fields
> + * @param itr
> + *   Iterator variable (uk_ctor_func_t *) which points to the individual
> + *   table entries during iteration
> + * @param ctortab_start
> + *   Start address of table (type: const uk_ctor_func_t[])
> + * @param ctortab_end
> + *   End address of table (type: const uk_ctor_func_t)
>    */
> -#define uk_ctor_foreach(arr_start, arr_end, i)                       \
> -     for ((i) = 0;                                           \
> -          &((arr_start)[i]) < &(arr_end);                    \
> -          ++(i))
> +#define uk_ctortab_foreach(itr, ctortab_start, ctortab_end)  \
> +     for ((itr) = DECONST(uk_ctor_func_t*, ctortab_start);   \
> +          (itr) < &(ctortab_end);                            \
> +          (itr)++)
>   
>   #ifdef __cplusplus
>   }
> diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
> index 9bd15ca8..fc2cf52a 100644
> --- a/lib/ukboot/boot.c
> +++ b/lib/ukboot/boot.c
> @@ -77,6 +77,7 @@ static void main_thread_func(void *arg)
>       int ret;
>       struct thread_main_arg *tma = arg;
>       uk_init_t *itr;
> +     uk_ctor_func_t *ctorfn;
>   
>       /**
>        * Run init table
> @@ -112,25 +113,24 @@ static void main_thread_func(void *arg)
>        * from its OS being initialized.
>        */
>       uk_pr_info("Pre-init table at %p - %p\n",
> -                __preinit_array_start, &__preinit_array_end);
> -     uk_ctor_foreach(__preinit_array_start, __preinit_array_end, i) {
> -             if (__preinit_array_start[i]) {
> -                     uk_pr_debug("Call pre-init constructor (entry %d (%p): 
> %p())...\n",
> -                                 i, &__preinit_array_start[i],
> -                                 __preinit_array_start[i]);
> -                     __preinit_array_start[i]();
> -             }
> +                &__preinit_array_start[0], &__preinit_array_end);
> +     uk_ctortab_foreach(ctorfn,
> +                        __preinit_array_start, __preinit_array_end) {
> +             if (!*ctorfn)
> +                     continue;
> +
> +             uk_pr_debug("Call pre-init constructor: %p()...\n", *ctorfn);
> +             (*ctorfn)();
>       }
>   
>       uk_pr_info("Constructor table at %p - %p\n",
> -                     __init_array_start, &__init_array_end);
> -     uk_ctor_foreach(__init_array_start, __init_array_end, i) {
> -             if (__init_array_start[i]) {
> -                     uk_pr_debug("Call constructor (entry %d (%p): 
> %p())...\n",
> -                                     i, &__init_array_start[i],
> -                                     __init_array_start[i]);
> -                     __init_array_start[i]();
> -             }
> +                &__init_array_start[0], &__init_array_end);
> +     uk_ctortab_foreach(ctorfn, __init_array_start, __init_array_end) {
> +             if (!*ctorfn)
> +                     continue;
> +
> +             uk_pr_debug("Call constructor: %p()...\n", *ctorfn);
> +             (*ctorfn)();
>       }
>   
>       uk_pr_info("Calling main(%d, [", tma->argc);
> @@ -171,7 +171,6 @@ void ukplat_entry_argp(char *arg0, char *argb, __sz 
> argb_len)
>   void ukplat_entry(int argc, char *argv[])
>   {
>       struct thread_main_arg tma;
> -     int i;
>       int kern_args = 0;
>       int rc __maybe_unused = 0;
>   #if CONFIG_LIBUKALLOC
> @@ -184,11 +183,14 @@ void ukplat_entry(int argc, char *argv[])
>       struct uk_sched *s = NULL;
>       struct uk_thread *main_thread = NULL;
>   #endif
> +     uk_ctor_func_t *ctorfn;
>   
> -     uk_pr_info("Unikraft constructors table at %p\n", uk_ctortab);
> -     uk_ctor_foreach(uk_ctortab, uk_ctortab_end, i) {
> -             uk_pr_debug("Call constructor %p\n", uk_ctortab[i]);
> -             uk_ctortab[i]();
> +     uk_pr_info("Unikraft constructor table at %p - %p\n",
> +                &uk_ctortab_start[0], &uk_ctortab_end);
> +     uk_ctortab_foreach(ctorfn, uk_ctortab_start, uk_ctortab_end) {
> +             UK_ASSERT(*ctorfn);
> +             uk_pr_debug("Call constructor: %p())...\n", *ctorfn);
> +             (*ctorfn)();
>       }
>   
>   #ifdef CONFIG_LIBUKLIBPARAM
> diff --git a/lib/uklibparam/include/uk/libparam.h 
> b/lib/uklibparam/include/uk/libparam.h
> index 2a271ed3..f8f8ba4b 100644
> --- a/lib/uklibparam/include/uk/libparam.h
> +++ b/lib/uklibparam/include/uk/libparam.h
> @@ -300,7 +300,7 @@ void _uk_libparam_lib_add(struct uk_lib_section *lib_sec);
>   #define UK_LIB_CTOR_PRIO    1
>   
>   #define UK_LIB_CONSTRUCTOR_SETUP(prio, name)                                
> \
> -     __UK_CTOR_FUNC(prio, name)
> +     UK_CTOR_PRIO(name, prio)
>   
>   /**
>    * Create a constructor to initialize the parameters in the library.
> diff --git a/plat/common/include/uk/plat/common/common.lds.h 
> b/plat/common/include/uk/plat/common/common.lds.h
> index 593e6699..d31aa1dd 100644
> --- a/plat/common/include/uk/plat/common/common.lds.h
> +++ b/plat/common/include/uk/plat/common/common.lds.h
> @@ -87,7 +87,7 @@
>   
>   #define CTORTAB_SECTION                                                     
> \
>       . = ALIGN(__PAGE_SIZE);                                         \
> -     uk_ctortab = .;                                                 \
> +     uk_ctortab_start = .;                                           \
>       .uk_ctortab :                                                   \
>       {                                                               \
>               KEEP(*(SORT_BY_NAME(.uk_ctortab[0-9])))                 \
_______________________________________________
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®.