Static initcalls
Subsystems (4)
v2 cover Static initcalls
This series replaces the dynamic initcalls (with function pointers) with static calls, and gets rid of initcall_run_list(), init_sequence_f, init_sequence_f_r and init_sequence_r. This makes the code simpler and the binary slighlty smaller: -2281 bytes/-0.21 % with LTO enabled and -510 bytes/-0.05 % with LTO disabled (xilinx_zynqmp_kria_defconfig).
Execution time doesn't seem to change noticeably. There is no impact on the SPL.
The inline assembly fixes, although they look unrelated, are triggered on some platforms with LTO enabled. For example: kirkwood_defconfig.
Azure CI passed [1] except:
- World build, imx8ulp_evk (and other imx*): "bl31.bin: Can't open: No such file or directory"
- World build, xilinx_zynqmp_kria: "file not found: pmu_obj.bin" ...which are clearly unrelated to this series.
[1] https://dev.azure.com/u-boot/u-boot/_build/results?buildId=10405
Changes in v5:
- Fix mistake in initcall_run_r(): CONFIG_IS_ENABLED(SYS_EARLY_PCI_INIT)
should have been !CONFIG_IS_ENABLED(...). As a result, several CI tests
were failing. (Tom R.)
- Restore fixes in test/py/tests/test_trace.py and arch/sh/lib/board.c
which had unexpectedly disappeared from v4 and caused CI errors.
- Fix CI error caused by wrong conditionals on the fix_fdt() call:
tools/buildman/buildman -o /tmp -seP powerpc
[...]
common/board_f.c:752:12: error: 'fix_fdt' defined but not used [-Werror=unused-function]
- Add "arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set"
to fix a build error with LTO detecting mcr/mrc instructions emitted in
Thumb mode on a CPU that doesn't support it:
make sheevaplug_defconfig
make -j$(nproc) CROSS_COMPILE="ccache arm-linux-gnueabi-"
[...]
LTO u-boot
{standard input}: Assembler messages:
{standard input}:9241: Error: selected processor does not support mcr p15,1,r0,c15,c11,0' in Thumb mode {standard input}:19196: Error: selected processor does not support mrc p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19223: Error: selected processor does not support mcr p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19241: Error: selected processor does not support mrc p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19268: Error: selected processor does not support mcr p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19286: Error: selected processor does not support mrc p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19321: Error: selected processor does not support mcr p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19341: Error: selected processor does not support mrc p15,0,r3,c1,c0,0' in Thumb mode {standard input}:19372: Error: selected processor does not support `mcr p15,0,r3,c1,c0,0' in Thumb mode make[1]: *** [/tmp/ccu1wZWX.mk:11: /tmp/ccIab81n.ltrans3.ltrans.o] Error 1
Changes in v4:
- Fold all changes to board_init_*() into a single patch
- Use '#if CONFIG_IS_ENABLED(FOO) INITCALL(init_foo) #endif' instead of 'CONFIG_IS_ENABLED(FOO, (INITCALL(init_foo);));' (Caleb C., Simon G.). As a consequence, drop Michal's patch ("common: board: Simplify array with function pointers with CONFIG_IS_ENABLED").
- Rebase on next
Changes in v3:
- Use printf() rather than debug() to report initcall failures (Quentin S.)
- initcall_run_f(): replace one erroneous call to WATCHDOG_INIT() with WATCHDOG_RESET() (Ilias A.)
- Fix relocate_code() in arch/sh/lib/board.c to address CI failures with r2dplus (https://lists.denx.de/pipermail/u-boot/2025-January/576213.html)
(Tom R.)
- Add comments to initcall_run_f() and initcall_run_r() (Simon G.)
Changes in v2:
- INTICALL() and INITCALL_EVT() now call hang() immediately on error
- Fixed typo: s/intcall_run_f_r/initcall_run_f_r/
Jerome Forissier (3):
arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set
common: board: make initcalls static
initcall: remove initcall_run_list()
arch/arm/include/asm/system.h | 22 +- arch/arm/lib/cache.c | 5 +- arch/arm/mach-kirkwood/include/mach/cpu.h | 9 +- arch/sh/lib/board.c | 9 +- common/board_f.c | 223 +++++++++---------- common/board_r.c | 251 +++++++++++----------- include/initcall.h | 45 ++-- lib/Makefile | 1 - lib/initcall.c | 102 --------- test/py/tests/test_trace.py | 8 +- 10 files changed, 297 insertions(+), 378 deletions(-) delete mode 100644 lib/initcall.c
Signature · 1 line
2.43.0
PATCH v2 1/3 arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set
The mcr and msr instructions are available in Thumb mode only if Thumb2 is supported. Therefore, if __thumb2__ is not set, make sure we switch to ARM mode by inserting a .arm directive in the inline assembly.
Fixes LTO link errors with kirkwood platforms, triggered by a later commit:
tools/buildman/buildman -o /tmp/build -eP sheevaplug
[...]
{standard input}:24085: Error: selected processor does not support `mrc p15,0,r3,c1,c0,0' in Thumb mode
--- arch/arm/include/asm/system.h | 22 +++++++++++++++++----- arch/arm/lib/cache.c | 5 +++-- arch/arm/mach-kirkwood/include/mach/cpu.h | 9 +++++---- 3 files changed, 25 insertions(+), 11 deletions(-)
arch/arm/include/asm/system.h +17 -5
@@ -394,11 +394,21 @@ void switch_to_hypervisor_ret(void);#define wfi ()#endif +#if !defined(__thumb2__) +/* +* We will need to switch to ARM mode (.arm) for some instructions such as +* mrc p15 etc. +*/ +#define asm_arm_or_thumb2 (insn) asm volatile(".arm\n\t" insn) +#else +#define asm_arm_or_thumb2 (insn) asm volatile(insn) +#endif +static inline unsigned long read_mpidr (void ) {unsigned long val; - asmvolatile ("mrc p15, 0, %0, c0, c0, 5" :"=r" (val)); + asm_arm_or_thumb2("mrc p15, 0, %0, c0, c0, 5" : "=r" (val));return val; }
@@ -427,11 +437,13 @@ static inline unsigned int get_cr(void)unsigned int val;if (is_hyp ()) - asmvolatile ("mrc p15, 4, %0, c1, c0, 0 @ get CR" :"=r" (val) + asm_arm_or_thumb2("mrc p15, 4, %0, c1, c0, 0 @ get CR" + : "=r" (val) : : "cc");else - asmvolatile ("mrc p15, 0, %0, c1, c0, 0 @ get CR" :"=r" (val) + asm_arm_or_thumb2("mrc p15, 0, %0, c1, c0, 0 @ get CR" + : "=r" (val) : : "cc");return val;
@@ -440,11 +452,11 @@ static inline unsigned int get_cr(void)static inline void set_cr (unsigned int val) {if (is_hyp ()) - asmvolatile ("mcr p15, 4, %0, c1, c0, 0 @ set CR" : + asm_arm_or_thumb2("mcr p15, 4, %0, c1, c0, 0 @ set CR" : : "r" (val) : "cc");else - asmvolatile ("mcr p15, 0, %0, c1, c0, 0 @ set CR" : + asm_arm_or_thumb2("mcr p15, 0, %0, c1, c0, 0 @ set CR" : : "r" (val) : "cc");isb ();
arch/arm/lib/cache.c +3 -2
@@ -10,6 +10,7 @@#include <malloc.h> #include <asm/cache.h> #include <asm/global_data.h> +#include <asm/system.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -125,8 +126,8 @@ void invalidate_l2_cache(void) {unsigned int val =0 ; - asmvolatile ("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache" - : :"r" (val) :"cc" ); + asm_arm_or_thumb2("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache" + : : "r" (val) : "cc"); isb(); }#endif
arch/arm/mach-kirkwood/include/mach/cpu.h +5 -4
@@ -85,8 +85,9 @@ struct mbus_win {static inline unsigned int readfr_extra_feature_reg (void ) {unsigned int val; - asmvolatile ("mrc p15, 1, %0, c15, c1, 0 @ readfr exfr" :"=r" - (val)::"cc" ); + + asm_arm_or_thumb2("mrc p15, 1, %0, c15, c1, 0 @ readfr exfr":"=r" + (val)::"cc");return val; }
@@ -96,8 +97,8 @@ static inline unsigned int readfr_extra_feature_reg(void)*/ static inline void writefr_extra_feature_reg (unsigned int val) { - asmvolatile ("mcr p15, 1, %0, c15, c1, 0 @ writefr exfr" ::"r" - (val):"cc" ); + asm_arm_or_thumb2("mcr p15, 1, %0, c15, c1, 0 @ writefr exfr"::"r" + (val):"cc");isb (); }
Signature · 1 line
2.43.0
PATCH v2 2/3 common: board: make initcalls static
In reply to Jerome ForissierChange board_init_f(), board_init_f_r() and board_init_r() to make static calls instead of iterating over the init_sequence_f, init_sequence_f_r and init_sequence_r arrays, respectively. This makes the code a simpler (and even more so when initcall_run_list() is later removed) and it reduces the binary size as well. Tested with xilinx_zynqmp_kria_defconfig; bloat-o-meter results:
- With LTO
add/remove: 106/196 grow/shrink: 10/28 up/down: 31548/-33829 (-2281)
Total: Before=1070471, After=1068190, chg -0.21%
- Without LTO
add/remove: 0/54 grow/shrink: 3/0 up/down: 2322/-2832 (-510)
Total: Before=1121723, After=1121213, chg -0.05%
Execution time does not change in a noticeable way.
--- arch/sh/lib/board.c | 9 +- common/board_f.c | 223 ++++++++++++++++---------------- common/board_r.c | 251 ++++++++++++++++++------------------ include/initcall.h | 27 ++++ test/py/tests/test_trace.py | 8 +- 5 files changed, 275 insertions(+), 243 deletions(-)
arch/sh/lib/board.c +2 -7
@@ -19,18 +19,13 @@ int dram_init(void)void relocate_code (ulong start_addr_sp,gd_t *new_gd,ulong relocaddr) { -void (*reloc_board_init_r)(gd_t *gd,ulong dest) = board_init_r; - -if (new_gd->reloc_off) { +if (new_gd->reloc_off)memcpy ((void *)new_gd->relocaddr, (void *)(new_gd->relocaddr - new_gd->reloc_off), new_gd->mon_len); - reloc_board_init_r += new_gd->reloc_off; - } - __asm__ __volatile__("mov.l %0, r15\n" : :"m" (new_gd->start_addr_sp));while (1 ) -reloc_board_init_r (new_gd,0x0 ); +board_init_r (new_gd,0x0 ); }
common/board_f.c +114 -109
302 lines not on this page · raw message
common/board_r.c +128 -123
328 lines not on this page · raw message
include/initcall.h +27 -0
@@ -8,6 +8,7 @@#include <asm/types.h> #include <event.h> +#include <hang.h> _Static_assert (EVT_COUNT <256 ,"Can only support 256 event types with 8 bits" );
@@ -35,4 +36,30 @@ typedef int (*init_fnc_t)(void);*/ int initcall_run_list (const init_fnc_t init_sequence[]); +#define INITCALL (_call) \ + do { \ + if (_call()) { \ + printf("%s(): initcall %s() failed\n", __func__, \ + #_call); \ + hang(); \ + } \ + } while (0) + +#define INITCALL_EVT (_evt) \ + do { \ + if (event_notify_null(_evt)) { \ + printf("%s(): event %d/%s failed\n", __func__, _evt, \ + event_type_name(_evt)) ; \ + hang(); \ + } \ + } while (0) + +#if defined(CONFIG_WATCHDOG ) || defined(CONFIG_HW_WATCHDOG ) +#define WATCHDOG_INIT () INITCALL(init_func_watchdog_init) +#define WATCHDOG_RESET () INITCALL(init_func_watchdog_reset) +#else +#define WATCHDOG_INIT () +#define WATCHDOG_RESET () +#endif +#endif
test/py/tests/test_trace.py +4 -4
@@ -201,7 +201,7 @@ def check_funcgraph(cons, fname, proftool, map_fname, trace_dat): # Then look for this: # u-boot-1 0..... 282.101375: funcgraph_exit: 0.006 us | } # Then check for this: - # u-boot-1 0..... 282.101375: funcgraph_entry: 0.000 us | calc_reloc_ofs(); + # u-boot-1 0..... 282.101375: funcgraph_entry: 0.000 us | event_init(); expected_indent = None found_start = False
@@ -224,8 +224,8 @@ def check_funcgraph(cons, fname, proftool, map_fname, trace_dat): found_end = True # The next function after initf_bootstage() exits should be - # initcall_is_event() - assert upto == 'calc_reloc_ofs()' + # event_init() + assert upto == 'event_init()' # Now look for initf_dm() and dm_timer_init() so we can check the bootstage # time
@@ -274,7 +274,7 @@ def check_flamegraph(cons, fname, proftool, map_fname, trace_fg): # We expect dm_timer_init() to be called twice: once before relocation and # once after look1 = 'initf_dm;dm_timer_init 1' - look2 = 'board_init_r;initcall_run_list;initr_dm_devices;dm_timer_init 1' + look2 = 'board_init_r;initcall_run_r;initr_dm_devices;dm_timer_init 1' found = 0 with open(trace_fg, 'r') as fd: for line in fd:
Signature · 1 line
2.43.0
Re: [PATCH v2 2/3] common: board: make initcalls static
include/initcall.h typedef int (*init_fnc_t)(void); · line 46
Quoted 8 lines · Jerome Forissier
include/initcall.h +8
-0+#define INITCALL (_call) \ + do { \ + if (_call()) { \ + printf("%s(): initcall %s() failed\n", __func__, \ + #_call); \ + hang(); \ + } \ + } while (0)
Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Re: [PATCH v2 2/3] common: board: make initcalls static
Quoted 11 lines · Marek Vasut
Quoted 8 lines · Jerome Forissier
+#define
INITCALL(_call)\
+ do { \
+ if (_call()) { \
+ printf("%s(): initcall %s() failed\n",__func__, \
+ #_call); \
+hang(); \
+ } \
+ } while (0)Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Doing the below totally kills the space gain (-160 bytes instead of -2281 on zynqmp_kria_defconfig, with LTO). And it prevents from printing the function name in case of error, which is nicer than an address (especially with relocation at play).
============
include/initcall.h +9 -0
@@ -12,6 +12,14 @@_Static_assert (EVT_COUNT <256 ,"Can only support 256 event types with 8 bits" ); +static inline void INITCALL (int (*_call)(void )) +{ +if (_call ()) { +printf ("initcall %p failed\n" , _call); +hang (); + } +} +#if 0 #define INITCALL (_call) \ do { \ if (_call()) { \
@@ -20,6 +28,7 @@ _Static_assert(EVT_COUNT < 256, "Can only support 256 event types with 8 bits"); hang(); \ } \ } while (0) +#endif #define INITCALL_EVT (_evt) \ do { \
============
Regards,
Signature · 1 line
Jerome
Re: [PATCH v2 2/3] common: board: make initcalls static
Quoted 13 lines · Jerome Forissier
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Jerome Forissier
+#define
INITCALL(_call)\
+ do { \
+ if (_call()) { \
+ printf("%s(): initcall %s() failed\n",__func__, \
+ #_call); \
+hang(); \
+ } \
+ } while (0)
Quoted 5 lines
Quoted 1 line
Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Doing the below totally kills the space gain (-160 bytes instead of -2281 on
zynqmp_kria_defconfig, with LTO).
Does the compiler not inline the functions perhaps ?
Quoted 3 lines
And it prevents from printing the
function name in case of error, which is nicer than an address (especially with relocation at play).
That function name can be passed in using __func__ as a parameter.
Re: [PATCH v2 2/3] common: board: make initcalls static
Quoted 14 lines · Marek Vasut
Quoted 13 lines · Jerome Forissier
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Jerome Forissier
+#define
INITCALL(_call)\
+ do { \
+ if (_call()) { \
+ printf("%s(): initcall %s() failed\n",__func__, \
+ #_call); \
+hang(); \
+ } \
+ } while (0)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Doing the below totally kills the space gain (-160 bytes instead of -2281 on
zynqmp_kria_defconfig, with LTO).Does the compiler not inline the functions perhaps ?
It does. inline vs __always_inline makes no difference. The assembly code is pretty difficult to understand in any case (macro or static inline function). There are pieces of called functions all over the place inside initcall_run_f() which is to be expected with LTO I suppose.
Quoted 5 lines
Quoted 4 lines
And it prevents from printing the
function name in case of error, which is nicer than an address (especially with relocation at play).That function name can be passed in using
__func__as a parameter.
True. That being said, the type-checking argument does not seem decisive here, and although I too prefer to use static inline functions over macros when possible, it looks like we have no choice in this case.
Signature · 1 line
Jerome
Re: [PATCH v2 2/3] common: board: make initcalls static
Quoted 35 lines · Jerome Forissier
Quoted 14 lines · Marek Vasut
Quoted 13 lines · Jerome Forissier
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Jerome Forissier
+#define
INITCALL(_call)\
+ do { \
+ if (_call()) { \
+ printf("%s(): initcall %s() failed\n",__func__, \
+ #_call); \
+hang(); \
+ } \
+ } while (0)Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Doing the below totally kills the space gain (-160 bytes instead of -2281 on
zynqmp_kria_defconfig, with LTO).Does the compiler not inline the functions perhaps ?
It does. inline vs
__always_inlinemakes no difference. The assembly code is pretty difficult to understand in any case (macro or static inline function). There are pieces of called functions all over the place insideinitcall_run_f()which is to be expected with LTO I suppose.Quoted 4 lines
Quoted 4 lines
And it prevents from printing the
function name in case of error, which is nicer than an address (especially with relocation at play).
Quoted 6 lines
Quoted 1 line
That function name can be passed in using
__func__as a parameter.True. That being said, the type-checking argument does not seem decisive here, and although I too prefer to use static inline functions over macros when possible, it looks like we have no choice in this case.
Can you try this kind of thing (might need some tweaking):
"
static void check_and_fail(int *ret) {
if (*ret) {
printf("failed\n");
hang(); }
}
static inline void INITCALL(int (*_call)(void))
{
int ret __attribute__((__cleanup__(check_and_fail))) = _call();
}
"
(maybe it really is the passing of pointer to _call() function into the INITCALL() function which confuses gcc into not inlining this right, but let's find out)
Re: [PATCH v2 2/3] common: board: make initcalls static
Quoted 52 lines · Marek Vasut
Quoted 35 lines · Jerome Forissier
Quoted 14 lines · Marek Vasut
Quoted 13 lines · Jerome Forissier
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Jerome Forissier
+#define
INITCALL(_call)\
+ do { \
+ if (_call()) { \
+ printf("%s(): initcall %s() failed\n",__func__, \
+ #_call); \
+hang(); \
+ } \
+ } while (0)Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Doing the below totally kills the space gain (-160 bytes instead of -2281 on
zynqmp_kria_defconfig, with LTO).Does the compiler not inline the functions perhaps ?
It does. inline vs
__always_inlinemakes no difference. The assembly code is pretty difficult to understand in any case (macro or static inline function). There are pieces of called functions all over the place insideinitcall_run_f()which is to be expected with LTO I suppose.Quoted 4 lines
Quoted 4 lines
And it prevents from printing the
function name in case of error, which is nicer than an address (especially with relocation at play).Quoted 6 lines
Quoted 1 line
That function name can be passed in using
__func__as a parameter.True. That being said, the type-checking argument does not seem decisive here, and although I too prefer to use static inline functions over macros when possible, it looks like we have no choice in this case.
Can you try this kind of thing (might need some tweaking):
"
static voidcheck_and_fail(int *ret){
if (*ret) {
printf("failed\n");
hang();
}
}
Quoted 7 lines
static inline void
INITCALL(int (*_call)(void))
{
int ret __attribute__((__cleanup__(check_and_fail))) =_call(); }
"(maybe it really is the passing of pointer to
_call()function into theINITCALL()function which confuses gcc into not inlining this right, but let's find out)
It seems to be working as expected (size-wise). Comparing the macro version with yours, without LTO then with LTO:
$ ../linux/scripts/bloat-o-meter /tmp/u-boot.macro /tmp/u-boot.inlinefn add/remove: 2/0 grow/shrink: 1/2 up/down: 1386/-1700 (-314) Function old new delta initcall_run_f - 1316 +1316 check_and_fail.isra - 64 +64 version_string 70 76 +6 board_init_r 836 664 -172 board_init_f 1572 44 -1528 Total: Before=1121213, After=1120899, chg -0.03%
$ ../linux/scripts/bloat-o-meter /tmp/u-boot.macro.lto /tmp/u-boot.inlinefn.lto add/remove: 5/3 grow/shrink: 2/3 up/down: 11418/-11072 (346) Function old new delta initcall_run_r - 7532 +7532 initcall_run_f - 3540 +3540 add_to_list.lto_priv - 248 +248 zynqmp_power - 48 +48 check_and_fail.isra - 32 +32 __func__ 975 987 +12 version_string 70 76 +6 __func__.lto_priv 3700 3688 -12 zynqmp_power.lto_priv 48 - -48 add_to_list 248 - -248 get_mem_top 568 - -568 board_init_f 2880 56 -2824 board_init_r 7424 52 -7372 Total: Before=1068190, After=1068536, chg +0.03%
But note that the two are not equivalent since yours doesn't print the initcall name in case of failure.
Regards,
Signature · 1 line
Jerome
Re: [PATCH v2 2/3] common: board: make initcalls static
Gentle ping. Can we keep the macro?
Thanks,
Signature · 1 line
Jerome
Quoted 98 lines · Jerome Forissier
Quoted 52 lines · Marek Vasut
Quoted 35 lines · Jerome Forissier
Quoted 14 lines · Marek Vasut
Quoted 13 lines · Jerome Forissier
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Jerome Forissier
+#define
INITCALL(_call)\
+ do { \
+ if (_call()) { \
+ printf("%s(): initcall %s() failed\n",__func__, \
+ #_call); \
+hang(); \
+ } \
+ } while (0)Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can this be turned into some static inline function too , so typechecking would be retained ? Maybe the function can be passed in a function pointer to call ?
Doing the below totally kills the space gain (-160 bytes instead of -2281 on
zynqmp_kria_defconfig, with LTO).Does the compiler not inline the functions perhaps ?
It does. inline vs
__always_inlinemakes no difference. The assembly code is pretty difficult to understand in any case (macro or static inline function). There are pieces of called functions all over the place insideinitcall_run_f()which is to be expected with LTO I suppose.Quoted 4 lines
Quoted 4 lines
And it prevents from printing the
function name in case of error, which is nicer than an address (especially with relocation at play).Quoted 6 lines
Quoted 1 line
That function name can be passed in using
__func__as a parameter.True. That being said, the type-checking argument does not seem decisive here, and although I too prefer to use static inline functions over macros when possible, it looks like we have no choice in this case.
Can you try this kind of thing (might need some tweaking):
"
static voidcheck_and_fail(int *ret){
if (*ret) {
printf("failed\n");
hang();
}
}Quoted 7 lines
static inline void
INITCALL(int (*_call)(void))
{
int ret __attribute__((__cleanup__(check_and_fail))) =_call(); }
"(maybe it really is the passing of pointer to
_call()function into theINITCALL()function which confuses gcc into not inlining this right, but let's find out)It seems to be working as expected (size-wise). Comparing the macro version with yours, without LTO then with LTO:
$ ../linux/scripts/bloat-o-meter /tmp/u-boot.macro /tmp/u-boot.inlinefn add/remove: 2/0 grow/shrink: 1/2 up/down: 1386/-1700 (-314) Function old new delta initcall_run_f - 1316 +1316 check_and_fail.isra - 64 +64 version_string 70 76 +6 board_init_r 836 664 -172 board_init_f 1572 44 -1528 Total: Before=1121213, After=1120899, chg -0.03%$ ../linux/scripts/bloat-o-meter /tmp/u-boot.macro.lto /tmp/u-boot.inlinefn.lto add/remove: 5/3 grow/shrink: 2/3 up/down: 11418/-11072 (346) Function old new delta initcall_run_r - 7532 +7532 initcall_run_f - 3540 +3540 add_to_list.lto_priv - 248 +248 zynqmp_power - 48 +48 check_and_fail.isra - 32 +32 __func__ 975 987 +12 version_string 70 76 +6 __func__.lto_priv 3700 3688 -12 zynqmp_power.lto_priv 48 - -48 add_to_list 248 - -248 get_mem_top 568 - -568 board_init_f 2880 56 -2824 board_init_r 7424 52 -7372 Total: Before=1068190, After=1068536, chg +0.03%But note that the two are not equivalent since yours doesn't print the initcall name in case of failure.
Regards,
PATCH v2 3/3 initcall: remove initcall_run_list()
In reply to Jerome ForissierNow that all initcalls have been converted to static calls, remove initcall_run_list().
--- include/initcall.h | 24 ----------- lib/Makefile | 1 - lib/initcall.c | 102 --------------------------------------------- 3 files changed, 127 deletions(-) delete mode 100644 lib/initcall.c
include/initcall.h +0 -24
@@ -12,30 +12,6 @@_Static_assert (EVT_COUNT <256 ,"Can only support 256 event types with 8 bits" ); -/** -* init_fnc_t - Init function -* -* Return: 0 if OK -ve on error -*/ -typedef int (*init_fnc_t )(void ); - -/* Top bit indicates that the initcall is an event */ -#define INITCALL_IS_EVENT GENMASK(BITS_PER_LONG - 1, 8) -#define INITCALL_EVENT_TYPE GENMASK(7, 0) - -#define INITCALL_EVENT (_type) (void *)((_type) | INITCALL_IS_EVENT) - -/** -* initcall_run_list() - Run through a list of function calls -* -* This calls functions one after the other, stopping at the first error, or -* when NULL is obtained. -* -* @init_sequence: NULL-terminated init sequence to run -* Return: 0 if OK, or -ve error code from the first failure -*/ -int initcall_run_list (const init_fnc_t init_sequence[]); -#define INITCALL (_call) \ do { \ if (_call()) { \
lib/Makefile +0 -1
@@ -44,7 +44,6 @@ obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o obj-$(CONFIG_SMBIOS_PARSER) += smbios-parser.o obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o -obj-y += initcall.o obj-y += ldiv.o obj-$(CONFIG_XXHASH) += xxhash.o obj-y += net_utils.o
lib/initcall.c deleted +0 -102
102 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 1 line · Jerome Forissier
Re: [PATCH v2 0/3] Static initcalls
Apologies for the wrong reroll count. This is actually v5 as mentioned in the change log.
Signature · 1 line
Jerome
Hi Marek,
Quoted 76 lines · Jerome Forissier
This series replaces the dynamic initcalls (with function pointers) with static calls, and gets rid of
initcall_run_list(),init_sequence_f,init_sequence_f_randinit_sequence_r. This makes the code simpler and the binary slighlty smaller: -2281 bytes/-0.21 % with LTO enabled and -510 bytes/-0.05 % with LTO disabled (xilinx_zynqmp_kria_defconfig).Execution time doesn't seem to change noticeably. There is no impact on the SPL.
The inline assembly fixes, although they look unrelated, are triggered on some platforms with LTO enabled. For example:
kirkwood_defconfig.Azure CI passed [1] except:
- World build,imx8ulp_evk(and other imx*): "bl31.bin: Can't open: No such file or directory"
- World build,xilinx_zynqmp_kria: "file not found: pmu_obj.bin" ...which are clearly unrelated to this series.[1] https://dev.azure.com/u-boot/u-boot/_build/results?buildId=10405
Changes in v5:
- Fix mistake ininitcall_run_r():CONFIG_IS_ENABLED(SYS_EARLY_PCI_INIT)
should have been !CONFIG_IS_ENABLED(...). As a result, several CI tests
were failing. (Tom R.)
- Restore fixes intest/py/tests/test_trace.pyandarch/sh/lib/board.c
which had unexpectedly disappeared from v4 and caused CI errors.
- Fix CI error caused by wrong conditionals on thefix_fdt()call:
tools/buildman/buildman-o /tmp -seP powerpc
[...]
common/board_f.c:752:12: error: 'fix_fdt' defined but not used [-Werror=unused-function]
- Add "arm:asm/system.h: mrc and mcr need .arm if__thumb2__is not set"
to fix a build error with LTO detecting mcr/mrc instructions emitted in
Thumb mode on a CPU that doesn't support it:
makesheevaplug_defconfig
make -j$(nproc) CROSS_COMPILE="ccache arm-linux-gnueabi-"
[...]
LTO u-boot
{standard input}: Assembler messages:
{standard input}:9241: Error: selected processor does not supportmcr p15,1,r0,c15,c11,0' in Thumb mode {standard input}:19196: Error: selected processor does not supportmrc p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19223: Error: selected processor does not supportmcr p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19241: Error: selected processor does not supportmrc p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19268: Error: selected processor does not supportmcr p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19286: Error: selected processor does not supportmrc p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19321: Error: selected processor does not supportmcr p15,1,r3,c15,c1,0' in Thumb mode {standard input}:19341: Error: selected processor does not supportmrc p15,0,r3,c1,c0,0' in Thumb mode {standard input}:19372: Error: selected processor does not support `mcr p15,0,r3,c1,c0,0' in Thumb mode make[1]: *** [/tmp/ccu1wZWX.mk:11:/tmp/ccIab81n.ltrans3.ltrans.o] Error 1Changes in v4:
- Fold all changes to board_init_*() into a single patch
- Use '#ifCONFIG_IS_ENABLED(FOO)INITCALL(init_foo)#endif' instead of 'CONFIG_IS_ENABLED(FOO, (INITCALL(init_foo);));' (Caleb C., Simon G.). As a consequence, drop Michal's patch ("common: board: Simplify array with function pointers withCONFIG_IS_ENABLED").
- Rebase on nextChanges in v3:
- Useprintf()rather thandebug()to report initcall failures (Quentin S.)
-initcall_run_f(): replace one erroneous call toWATCHDOG_INIT()withWATCHDOG_RESET()(Ilias A.)
- Fixrelocate_code()inarch/sh/lib/board.cto address CI failures with r2dplus (https://lists.denx.de/pipermail/u-boot/2025-January/576213.html)
(Tom R.)
- Add comments toinitcall_run_f()andinitcall_run_r()(Simon G.)Changes in v2:
-INTICALL()andINITCALL_EVT()now callhang()immediately on error
- Fixed typo: s/intcall_run_f_r/initcall_run_f_r/Jerome Forissier (3):
arm:asm/system.h: mrc and mcr need .arm if__thumb2__is not set
common: board: make initcalls static
initcall: removeinitcall_run_list()
Quoted 12 lines
arch/arm/include/asm/system.h | 22 +- arch/arm/lib/cache.c | 5 +- arch/arm/mach-kirkwood/include/mach/cpu.h | 9 +- arch/sh/lib/board.c | 9 +- common/board_f.c | 223 +++++++++---------- common/board_r.c | 251 +++++++++++----------- include/initcall.h | 45 ++-- lib/Makefile | 1 - lib/initcall.c | 102 --------- test/py/tests/test_trace.py | 8 +- 10 files changed, 297 insertions(+), 378 deletions(-) delete mode 100644 lib/initcall.c
Do you need something more from me on this series? Thanks!
Signature · 1 line
Jerome