From f3b37ea70953f9c8ac8526c1fed483be9587bbfb Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 15 Jul 2025 12:33:30 -0400 Subject: [PATCH 1/4] Revert "cmake: Add service section to commo-rom linker generator" This reverts commit 49a96f67a21f6c8a3ecc1eaf27fc6593d758718a. Signed-off-by: Anas Nashif --- cmake/linker_script/common/common-rom.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/linker_script/common/common-rom.cmake b/cmake/linker_script/common/common-rom.cmake index c56ccd3670be..087e106c8e62 100644 --- a/cmake/linker_script/common/common-rom.cmake +++ b/cmake/linker_script/common/common-rom.cmake @@ -12,7 +12,6 @@ zephyr_linker_section_obj_level(SECTION init LEVEL APPLICATION) zephyr_linker_section_obj_level(SECTION init LEVEL SMP) zephyr_iterable_section(NAME device NUMERIC KVMA RAM_REGION GROUP RODATA_REGION) -zephyr_iterable_section(NAME service NUMERIC KVMA RAM_REGION GROUP RODATA_REGION) if(CONFIG_GEN_SW_ISR_TABLE AND NOT CONFIG_DYNAMIC_INTERRUPTS) # ld align has been changed to subalign to provide identical behavior scatter vs. ld. From 78616cf09b390187a613d5d40d0ca32fcf7c452e Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 15 Jul 2025 12:33:32 -0400 Subject: [PATCH 2/4] Revert "tests: misc: Fixing expected output on check_init_priorities test" This reverts commit c341f5389d8c1875e3d4dd449b78552a0738b55e. Signed-off-by: Anas Nashif --- .../validate_check_init_priorities_output.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/misc/check_init_priorities/validate_check_init_priorities_output.py b/tests/misc/check_init_priorities/validate_check_init_priorities_output.py index 7dfbc054f4f2..f5d322164c6f 100755 --- a/tests/misc/check_init_priorities/validate_check_init_priorities_output.py +++ b/tests/misc/check_init_priorities/validate_check_init_priorities_output.py @@ -9,10 +9,10 @@ REFERENCE_OUTPUT = [ "ERROR: Device initialization priority validation failed, the sequence of initialization calls does not match the devicetree dependencies.", - "ERROR: /i2c@11112222/test-i2c-dev@10 is initialized before its dependency /gpio@ffff (PRE_KERNEL_1+0 < PRE_KERNEL_1+1)", - "ERROR: /i2c@11112222/test-i2c-dev@10 is initialized before its dependency /i2c@11112222 (PRE_KERNEL_1+0 < PRE_KERNEL_1+2)", - "INFO: /i2c@11112222/test-i2c-dev@11 PRE_KERNEL_1+3 > /gpio@ffff PRE_KERNEL_1+1", - "INFO: /i2c@11112222/test-i2c-dev@11 PRE_KERNEL_1+3 > /i2c@11112222 PRE_KERNEL_1+2", + "ERROR: /i2c@11112222/test-i2c-dev@10 is initialized before its dependency /gpio@ffff (PRE_KERNEL_1+0 < PRE_KERNEL_1+1)", + "ERROR: /i2c@11112222/test-i2c-dev@10 is initialized before its dependency /i2c@11112222 (PRE_KERNEL_1+0 < PRE_KERNEL_1+2)", + "INFO: /i2c@11112222/test-i2c-dev@11 PRE_KERNEL_1+3 > /gpio@ffff PRE_KERNEL_1+1", + "INFO: /i2c@11112222/test-i2c-dev@11 PRE_KERNEL_1+3 > /i2c@11112222 PRE_KERNEL_1+2", ] if len(sys.argv) != 2: From 8ef1eea441a246761d9f20509d7d2d02396149af Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 15 Jul 2025 12:33:33 -0400 Subject: [PATCH 3/4] Revert "scripts: Removing init function pointer from check_init_priorities.py" This reverts commit 653f1bf12365cf299e960914dbe58a56bdeb14e5. Signed-off-by: Anas Nashif --- scripts/build/check_init_priorities.py | 21 +++++++++++---------- scripts/build/check_init_priorities_test.py | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/scripts/build/check_init_priorities.py b/scripts/build/check_init_priorities.py index 1ae2772a5494..dc028aa31de2 100755 --- a/scripts/build/check_init_priorities.py +++ b/scripts/build/check_init_priorities.py @@ -202,14 +202,15 @@ def _process_initlevels(self): raise ValueError(f"no symbol at addr {addr:08x}") obj, size, shidx = self._objects[addr] - arg_name = self._object_name(self._initlevel_pointer(addr, 0, shidx)) + arg0_name = self._object_name(self._initlevel_pointer(addr, 0, shidx)) + arg1_name = self._object_name(self._initlevel_pointer(addr, 1, shidx)) - self.initlevels[level].append(f"{obj}: {arg_name}") + self.initlevels[level].append(f"{obj}: {arg0_name}({arg1_name})") - ordinal = self._device_ord_from_name(arg_name) + ordinal = self._device_ord_from_name(arg1_name) if ordinal: prio = Priority(level, priority) - self.devices[ordinal] = prio + self.devices[ordinal] = (prio, arg0_name) addr += size priority += 1 @@ -255,8 +256,8 @@ def _check_dep(self, dev_ord, dep_ord): self.log.info(f"Ignoring priority: {dev_node._binding.compatible}") return - dev_prio = self._obj.devices.get(dev_ord, None) - dep_prio = self._obj.devices.get(dep_ord, None) + dev_prio, dev_init = self._obj.devices.get(dev_ord, (None, None)) + dep_prio, dep_init = self._obj.devices.get(dep_ord, (None, None)) if not dev_prio or not dep_prio: return @@ -271,12 +272,12 @@ def _check_dep(self, dev_ord, dep_ord): "the devicetree dependencies.") self.errors += 1 self.log.error( - f"{dev_node.path} is initialized before its dependency " - f"{dep_node.path} ({dev_prio} < {dep_prio})") + f"{dev_node.path} <{dev_init}> is initialized before its dependency " + f"{dep_node.path} <{dep_init}> ({dev_prio} < {dep_prio})") else: self.log.info( - f"{dev_node.path} {dev_prio} > " - f"{dep_node.path} {dep_prio}") + f"{dev_node.path} <{dev_init}> {dev_prio} > " + f"{dep_node.path} <{dep_init}> {dep_prio}") def check_edt(self): """Scan through all known devices and validate the init priorities.""" diff --git a/scripts/build/check_init_priorities_test.py b/scripts/build/check_init_priorities_test.py index e249321a6208..16cf9af74065 100755 --- a/scripts/build/check_init_priorities_test.py +++ b/scripts/build/check_init_priorities_test.py @@ -215,8 +215,12 @@ def test_process_initlevels(self, mock_zilinit, mock_ip, mock_on): def mock_obj_name(*args): if args[0] == (0, 0, 0): + return "i0" + elif args[0] == (0, 1, 0): return "__device_dts_ord_11" elif args[0] == (4, 0, 0): + return "i1" + elif args[0] == (4, 1, 0): return "__device_dts_ord_22" return f"name_{args[0][0]}_{args[0][1]}" mock_on.side_effect = mock_obj_name @@ -226,15 +230,14 @@ def mock_obj_name(*args): self.assertDictEqual(obj.initlevels, { "EARLY": [], "PRE_KERNEL_1": [], - "PRE_KERNEL_2": ["a: __device_dts_ord_11", "b: __device_dts_ord_22"], - "POST_KERNEL": ["c: name_8_0"], + "PRE_KERNEL_2": ["a: i0(__device_dts_ord_11)", "b: i1(__device_dts_ord_22)"], + "POST_KERNEL": ["c: name_8_0(name_8_1)"], "APPLICATION": [], "SMP": [], }) - self.assertDictEqual(obj.devices, { - 11: check_init_priorities.Priority("PRE_KERNEL_2", 0), - 22: check_init_priorities.Priority("PRE_KERNEL_2", 1), + 11: (check_init_priorities.Priority("PRE_KERNEL_2", 0), "i0"), + 22: (check_init_priorities.Priority("PRE_KERNEL_2", 1), "i1"), }) class testValidator(unittest.TestCase): @@ -300,14 +303,14 @@ def test_check(self, mock_vinit): validator._ord2node[2]._binding = None validator._ord2node[2].path = "/2" - validator._obj.devices = {1: 10, 2: 20} + validator._obj.devices = {1: (10, "i1"), 2: (20, "i2")} validator._check_dep(2, 1) validator._check_dep(1, 2) - validator.log.info.assert_called_once_with("/2 20 > /1 10") + validator.log.info.assert_called_once_with("/2 20 > /1 10") validator.log.error.assert_has_calls([ - mock.call("/1 is initialized before its dependency /2 (10 < 20)") + mock.call("/1 is initialized before its dependency /2 (10 < 20)") ]) self.assertEqual(validator.errors, 1) @@ -324,7 +327,7 @@ def test_check_same_prio_assert(self, mock_vinit): validator._ord2node[2]._binding = None validator._ord2node[2].path = "/2" - validator._obj.devices = {1: 10, 2: 10,} + validator._obj.devices = {1: (10, "i1"), 2: (10, "i2")} with self.assertRaises(ValueError): validator._check_dep(1, 2) From 54885200139e522bd08ac32bcdc832471341f760 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 15 Jul 2025 12:33:34 -0400 Subject: [PATCH 4/4] Revert "init: Make entry init-function less and introduce service objects" This reverts commit 175da6bdb0da7c6b626c4e2d62520764998ebc07. Signed-off-by: Anas Nashif --- include/zephyr/device.h | 1 + include/zephyr/init.h | 22 ++--- .../common-rom/common-rom-kernel-devices.ld | 2 - include/zephyr/service.h | 92 ------------------- kernel/init.c | 26 +----- subsys/net/lib/sockets/sockets_service.c | 2 +- 6 files changed, 15 insertions(+), 130 deletions(-) delete mode 100644 include/zephyr/service.h diff --git a/include/zephyr/device.h b/include/zephyr/device.h index 152b1257af6b..07fea3c2d1fc 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -1263,6 +1263,7 @@ device_get_dt_nodelabels(const struct device *dev) static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \ level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \ Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ + .init_fn = NULL, \ .dev = (const struct device *)&DEVICE_NAME_GET(dev_id), \ } diff --git a/include/zephyr/init.h b/include/zephyr/init.h index 75c9d29092aa..d7f254c3c51b 100644 --- a/include/zephyr/init.h +++ b/include/zephyr/init.h @@ -13,8 +13,6 @@ #include #include -#include - #ifdef __cplusplus extern "C" { #endif @@ -67,14 +65,15 @@ struct device; */ struct init_entry { /** - * An init entry can be about a device or a service, _init_object - * will be used to differentiate depending on relative sections. + * If the init function belongs to a SYS_INIT, this field stored the + * initialization function, otherwise it is set to NULL. + */ + int (*init_fn)(void); + /** + * If the init entry belongs to a device, this fields stores a + * reference to it, otherwise it is set to NULL. */ - union { - const void *_init_object; - const struct device *dev; - const struct service *srv; - }; + const struct device *dev; }; /** @cond INTERNAL_HIDDEN */ @@ -165,12 +164,9 @@ struct init_entry { * @see SYS_INIT() */ #define SYS_INIT_NAMED(name, init_fn_, level, prio) \ - Z_SERVICE_DEFINE(name, init_fn_, level, prio); \ static const Z_DECL_ALIGN(struct init_entry) \ Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \ - Z_INIT_ENTRY_NAME(name) = { \ - .srv = (const struct service *)&Z_SERVICE_NAME_GET(name) \ - } + Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_), .dev = NULL} \ /** @} */ diff --git a/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld b/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld index 2bb7d2c509ce..656a4b075d99 100644 --- a/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld +++ b/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld @@ -22,8 +22,6 @@ ITERABLE_SECTION_ROM_NUMERIC(device, Z_LINK_ITERABLE_SUBALIGN) - ITERABLE_SECTION_ROM_NUMERIC(service, Z_LINK_ITERABLE_SUBALIGN) - #if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_SHARED_INTERRUPTS) /* since z_shared_isr() is not referenced anywhere when * zephyr_pre0.elf is built, the linker will end up dropping it. diff --git a/include/zephyr/service.h b/include/zephyr/service.h deleted file mode 100644 index cbeaeecefcf6..000000000000 --- a/include/zephyr/service.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2024 Tomasz Bursztyka. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_INCLUDE_SERVICE_H_ -#define ZEPHYR_INCLUDE_SERVICE_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup service System service - * @ingroup os_services - * - * A system service is a one-shot initialized software component, instantiated - * via SYS_INIT() or SYS_INIT_NAMED(). It does not provide any public API. - * - * @{ - */ - -/** - * @brief Structure to store service instance - * - * This will be defined through SYS_INIT/SYS_INIT_NAMED - */ -struct service { - /** - * Initialization function - */ - int (*init)(void); -}; - -/** @cond INTERNAL_HIDDEN */ - -/** - * @brief Expands to the name of a global service object - * - * @param name Service name. - * - * @return The full name of the service object defined by the service - * definition macro. - */ -#define Z_SERVICE_NAME_GET(name) _CONCAT(__service_, name) - -/** - * @brief Initializer for @ref service - * - * @param init_fn Initialization function (mandatory). - */ -#define Z_SERVICE_INIT(init_fn) \ - { \ - .init = (init_fn) \ - } - -/** - * @brief Service section name (used for sorting purposes). - * - * @param level Initialization level. - * @param prio Initialization priority. - */ -#define Z_SERVICE_SECTION_NAME(level, prio) \ - _CONCAT(INIT_LEVEL_ORD(level), _##prio) - -/** - * @brief Define a @ref service - * - * @param name Service name. - * @param init_fn Initialization function. - * @param level Initialization level. - * @param prio Initialization priority. - */ -#define Z_SERVICE_DEFINE(name, init_fn, level, prio) \ - static const \ - STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \ - service, service, \ - Z_SERVICE_SECTION_NAME(level, prio), \ - Z_SERVICE_NAME_GET(name)) = Z_SERVICE_INIT(init_fn) - -/** @endcond */ - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_SERVICE_H_ */ diff --git a/kernel/init.c b/kernel/init.c index 2ab9804c7cf0..dd9f3d7258f5 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -136,9 +136,6 @@ enum init_level { extern const struct init_entry __init_SMP_start[]; #endif /* CONFIG_SMP */ -TYPE_SECTION_START_EXTERN(struct service, service); -TYPE_SECTION_END_EXTERN(struct service, service); - /* * storage space for the interrupt stack * @@ -340,12 +337,6 @@ static int do_device_init(const struct device *dev) return rc; } -static inline bool is_entry_about_service(const void *obj) -{ - return (obj >= (void *)_service_list_start && - obj < (void *)_service_list_end); -} - /** * @brief Execute all the init entry initialization functions at a given level * @@ -374,26 +365,17 @@ static void z_sys_init_run_level(enum init_level level) const struct init_entry *entry; for (entry = levels[level]; entry < levels[level+1]; entry++) { + const struct device *dev = entry->dev; int result = 0; - if (unlikely(entry->_init_object == NULL)) { - continue; - } - sys_trace_sys_init_enter(entry, level); - - if (is_entry_about_service(entry->_init_object)) { - const struct service *srv = entry->srv; - - result = srv->init(); - } else { - const struct device *dev = entry->dev; - + if (dev != NULL) { if ((dev->flags & DEVICE_FLAG_INIT_DEFERRED) == 0U) { result = do_device_init(dev); } + } else { + result = entry->init_fn(); } - sys_trace_sys_init_exit(entry, level, result); } } diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c index d022e1c37355..f0f9b9c4e4b9 100644 --- a/subsys/net/lib/sockets/sockets_service.c +++ b/subsys/net/lib/sockets/sockets_service.c @@ -28,7 +28,7 @@ static K_CONDVAR_DEFINE(wait_start); STRUCT_SECTION_START_EXTERN(net_socket_service_desc); STRUCT_SECTION_END_EXTERN(net_socket_service_desc); -static struct service_context { +static struct service { struct zsock_pollfd events[CONFIG_ZVFS_POLL_MAX]; int count; } ctx;