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

[Minios-devel] [UNIKRAFT PATCH 4/9] include: Introduce <uk/prio.h>



This patch introduces <uk/prio.h>, helper macros for computing
priority levels with the pre-processor.
The macros can be used for Unikraft constructors and Unikraft init
function priorities. Their intended use is to define initialization
dependencies. Because the Constrcutor and Init function definitions are
based on macros, standard C arithmetic operations do not work.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 include/uk/ctors.h |  4 ++-
 include/uk/init.h  | 14 ++++----
 include/uk/prio.h  | 82 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 7 deletions(-)
 create mode 100644 include/uk/prio.h

diff --git a/include/uk/ctors.h b/include/uk/ctors.h
index d8a1c838..db98b664 100644
--- a/include/uk/ctors.h
+++ b/include/uk/ctors.h
@@ -38,6 +38,7 @@
 #define __UK_CTORS_H__
 
 #include <uk/essentials.h>
+#include <uk/prio.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -64,6 +65,7 @@ extern const uk_ctor_func_t uk_ctortab_end;
  *   Constructor function to be called
  * @param prio
  *   Priority level (0 (earliest) to 9 (latest))
+ *   Use the UK_PRIO_AFTER() helper macro for computing priority dependencies.
  *   Note: Any other value for level will be ignored
  */
 #define __UK_CTORTAB(fn, libname, prio)                        \
@@ -80,7 +82,7 @@ extern const uk_ctor_func_t uk_ctortab_end;
 /**
  * Similar interface without priority.
  */
-#define UK_CTOR(fn) UK_CTOR_PRIO(fn, 9)
+#define UK_CTOR(fn) UK_CTOR_PRIO(fn, UK_PRIO_LATEST)
 
 /* DELETEME: Compatibility wrapper for existing code, to be removed! */
 #define UK_CTOR_FUNC(lvl, ctorf) \
diff --git a/include/uk/init.h b/include/uk/init.h
index 149b4926..1f26c504 100644
--- a/include/uk/init.h
+++ b/include/uk/init.h
@@ -36,6 +36,7 @@
 
 #include <uk/config.h>
 #include <uk/essentials.h>
+#include <uk/prio.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -53,6 +54,7 @@ typedef int (*uk_init_func_t)(void);
  *   Initialization class (1 (earliest) to 6 (latest))
  * @param prio
  *   Priority level (0 (earliest) to 9 (latest)), must be a constant.
+ *   Use the UK_PRIO_AFTER() helper macro for computing priority dependencies.
  *   Note: Any other value for level will be ignored
  */
 #define __UK_INITTAB(libname, fn, base, prio)                          \
@@ -104,12 +106,12 @@ typedef int (*uk_init_func_t)(void);
 /**
  * Similar interface without priority.
  */
-#define uk_early_initcall(fn)     uk_early_initcall_prio(fn, 9)
-#define uk_plat_initcall(fn)      uk_plat_initcall_prio(fn, 9)
-#define uk_lib_initcall(fn)       uk_lib_initcall_prio(fn, 9)
-#define uk_rootfs_initcall(fn)    uk_rootfs_initcall_prio(fn, 9)
-#define uk_sys_initcall(fn)       uk_sys_initcall_prio(fn, 9)
-#define uk_late_initcall(fn)      uk_late_initcall_prio(fn, 9)
+#define uk_early_initcall(fn)     uk_early_initcall_prio(fn, UK_PRIO_LATEST)
+#define uk_plat_initcall(fn)      uk_plat_initcall_prio(fn, UK_PRIO_LATEST)
+#define uk_lib_initcall(fn)       uk_lib_initcall_prio(fn, UK_PRIO_LATEST)
+#define uk_rootfs_initcall(fn)    uk_rootfs_initcall_prio(fn, UK_PRIO_LATEST)
+#define uk_sys_initcall(fn)       uk_sys_initcall_prio(fn, UK_PRIO_LATEST)
+#define uk_late_initcall(fn)      uk_late_initcall_prio(fn, UK_PRIO_LATEST)
 
 extern const uk_init_func_t uk_inittab_start[];
 extern const uk_init_func_t uk_inittab_end;
diff --git a/include/uk/prio.h b/include/uk/prio.h
new file mode 100644
index 00000000..c49b784f
--- /dev/null
+++ b/include/uk/prio.h
@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ *
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#ifndef __UK_PRIO_H__
+#define __UK_PRIO_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Computes the priority level that has one lower priority than
+ * the given priority level. This macro can be used to state
+ * initialization dependencies. It is intended to be used for
+ * declaring macro constants.
+ * NOTE: This macro should only be used for Unikraft constructors
+ * (UK_CTOR_PRIO(), UK_CTOR()) and Unikraft init table entries.
+ *
+ * @param x
+ *  Given Unikraft priority level
+ * @return
+ *  Priority level that has one priority less than x
+ */
+#define __UK_PRIO_AFTER_0 1
+#define __UK_PRIO_AFTER_1 2
+#define __UK_PRIO_AFTER_2 3
+#define __UK_PRIO_AFTER_3 4
+#define __UK_PRIO_AFTER_4 5
+#define __UK_PRIO_AFTER_5 6
+#define __UK_PRIO_AFTER_6 7
+#define __UK_PRIO_AFTER_7 8
+#define __UK_PRIO_AFTER_8 9
+#define __UK_PRIO_AFTER_9 __UK_PRIO_OUT_OF_BOUNDS
+#define __UK_PRIO_AFTER(x) __UK_PRIO_AFTER_##x
+#define UK_PRIO_AFTER(x)   __UK_PRIO_AFTER(x)
+
+#define UK_PRIO_EARLIEST 0
+#define UK_PRIO_LATEST   9
+
+/* Stop compilation if priority is getting out of bounds */
+#ifdef __GNUC__
+#pragma GCC poison __UK_PRIO_OUT_OF_BOUNDS
+#else
+#error Out of bounds pragma not defined
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UK_PRIO_H__ */
-- 
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®.