Regression on colibri-imx7 due to commit 9c1b13b3fd27 ("cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()")
Subsystems (3)
Hi,
I found that Colibri iMX7 no longer boots when commit 9c1b13b3fd27 ("cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()") is applied. Nothing is printed on the serial.
I bisected the issue: booting the parent commit works fine, and reverting this patch on top of current main also restores boot. It's not yet obvious to me what in this change causes the regression.
Would it make sense to revert it until the root cause is found?
Thanks,
Emanuele
On 7/23/26 4:53 PM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 10 lines
I found that Colibri iMX7 no longer boots when commit
9c1b13b3fd27("cyclic: reduceget_timer_us()calls insidehlist_for_each_entry_safe()") is applied. Nothing is printed on the serial.I bisected the issue: booting the parent commit works fine, and reverting this patch on top of current main also restores boot. It's not yet obvious to me what in this change causes the regression.
Would it make sense to revert it until the root cause is found?
Give Patrice a bit of time to analyze the problem.
Signature · 2 lines
Best regards, Marek Vasut
Quoted 8 lines · Marek Vasut
On 7/23/26 4:53 PM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 4 lines
I found that Colibri iMX7 no longer boots when commit
9c1b13b3fd27("cyclic: reduceget_timer_us()calls insidehlist_for_each_entry_safe()") is applied. Nothing is printed on the serial.
Quoted 9 lines
Quoted 6 lines
I bisected the issue: booting the parent commit works fine, and reverting this patch on top of current main also restores boot. It's not yet obvious to me what in this change causes the regression.
Would it make sense to revert it until the root cause is found?
Give Patrice a bit of time to analyze the problem.
Hello,
after the regression, get_timer_us() is called on every cyclic_run() call, even when the cyclic list is empty. On imx7 this happens earlier than before, when the timer has not yet been initialized: get_timer_us() calls get_tbclk(), whose value is zero, and uses it as a divisor in tick_to_time_us(), leading to a division by zero.
I would fix this by ensuring get_tbclk() returns at least 1 on imx7, but we could hide bugs in this way. However, this bug could also be present on other architectures, so I would just guard against entering the cyclic loop by checking whether the list is empty before doing anything else, so get_timer_us() is called "at the same point in time" as before. Something like:
if (hlist_empty(cyclic_get_list())) {
gd->flags &= ~GD_FLG_CYCLIC_RUNNING;
return;
}Kind regards,
Emanuele
Quoted 35 lines · Emanuele Ghidoli
Quoted 8 lines · Marek Vasut
On 7/23/26 4:53 PM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 4 lines
I found that Colibri iMX7 no longer boots when commit
9c1b13b3fd27("cyclic: reduceget_timer_us()calls insidehlist_for_each_entry_safe()") is applied. Nothing is printed on the serial.Quoted 9 lines
Quoted 6 lines
I bisected the issue: booting the parent commit works fine, and reverting this patch on top of current main also restores boot. It's not yet obvious to me what in this change causes the regression.
Would it make sense to revert it until the root cause is found?
Give Patrice a bit of time to analyze the problem.
Hello,
after the regression,
get_timer_us()is called on everycyclic_run()call, even when the cyclic list is empty. On imx7 this happens earlier than before, when the timer has not yet been initialized:get_timer_us()callsget_tbclk(), whose value is zero, and uses it as a divisor intick_to_time_us(), leading to a division by zero.I would fix this by ensuring
get_tbclk()returns at least 1 on imx7, but we could hide bugs in this way. However, this bug could also be present on other architectures, so I would just guard against entering the cyclic loop by checking whether the list is empty before doing anything else, soget_timer_us()is called "at the same point in time" as before. Something like:
Quoted 4 lines
if (hlist_empty(cyclic_get_list())) {
gd->flags &= ~GD_FLG_CYCLIC_RUNNING;
return;
}It looks like there are two topics -- optimize the cyclic run and fix the MX7 timer.
I agree the cyclic run should exit if the list is empty, but please wait for input from Rasmus on that.
Regarding the timer, how come the timer is initialized so late on MX7 ?
The Cortex-A7 should have its own ARM timer, that should be available right from the beginning. Is that ARM timer in use on your system, or does your system use GPT timer ?
Which board is this ?
+CC Peng
Quoted 40 lines · Marek Vasut
Quoted 35 lines · Emanuele Ghidoli
Quoted 8 lines · Marek Vasut
On 7/23/26 4:53 PM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 4 lines
I found that Colibri iMX7 no longer boots when commit
9c1b13b3fd27("cyclic: reduceget_timer_us()calls insidehlist_for_each_entry_safe()") is applied. Nothing is printed on the serial.Quoted 9 lines
Quoted 6 lines
I bisected the issue: booting the parent commit works fine, and reverting this patch on top of current main also restores boot. It's not yet obvious to me what in this change causes the regression.
Would it make sense to revert it until the root cause is found?
Give Patrice a bit of time to analyze the problem.
Hello,
after the regression,
get_timer_us()is called on everycyclic_run()call, even when the cyclic list is empty. On imx7 this happens earlier than before, when the timer has not yet been initialized:get_timer_us()callsget_tbclk(), whose value is zero, and uses it as a divisor intick_to_time_us(), leading to a division by zero.I would fix this by ensuring
get_tbclk()returns at least 1 on imx7, but we could hide bugs in this way. However, this bug could also be present on other architectures, so I would just guard against entering the cyclic loop by checking whether the list is empty before doing anything else, soget_timer_us()is called "at the same point in time" as before. Something like:Quoted 4 lines
if (hlist_empty(cyclic_get_list())) { gd->flags &= ~GD_FLG_CYCLIC_RUNNING; return; }
Quoted 6 lines
It looks like there are two topics -- optimize the cyclic run and fix the MX7 timer.
I agree the cyclic run should exit if the list is empty, but please wait for input from Rasmus on that.
Yes, we could/should definitely exit early if the list is empty, but don't mix it up with the GD_FLG_CYCLIC_RUNNING bit. Just add it as a separate early exit condition. But a future reader might read that as "just" an optimization, seeing that the loop would just do nothing, I think it also requires an explanation. Something like
common/cyclic.c +13 -0
@@ -69,6 +69,19 @@ static void cyclic_run(void)struct hlist_node *tmp;u64 now, after, cpu_time; +/* +* Nothing to do if the list is empty. Also, schedule() can be +* called before timer infrastructure is ready, in which case +* calling get_timer_us() before the (empty) loop could cause +* a divide-by-0 or otherwise crash the system. No clients +* should be registered before the timer infrastructure is up, +* so the check for the list being empty should be +* ok. Otherwise, we would need a new GD_FLG_TIMERS_READY +* flag. +*/ +if (hlist_empty (cyclic_get_list ())) +return ; +/* Prevent recursion */ if (gd->flags &GD_FLG_CYCLIC_RUNNING )return ;
Completely unrelated, but now that I see a new use of that cyclic_get_list() helper, I think it's time to get rid of that and just spell it &gd->cyclic_list. It was only needed back when gd was volatile-qualified.
Rasmus
Quoted 40 lines · Marek Vasut
Quoted 29 lines · Emanuele Ghidoli
Quoted 8 lines · Marek Vasut
On 7/23/26 4:53 PM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 4 lines
I found that Colibri iMX7 no longer boots when commit
9c1b13b3fd27("cyclic: reduceget_timer_us()calls insidehlist_for_each_entry_safe()") is applied. Nothing is printed on the serial.Quoted 9 lines
Quoted 6 lines
I bisected the issue: booting the parent commit works fine, and reverting this patch on top of current main also restores boot. It's not yet obvious to me what in this change causes the regression.
Would it make sense to revert it until the root cause is found?
Give Patrice a bit of time to analyze the problem.
Hello,
after the regression,
get_timer_us()is called on everycyclic_run()call, even when the cyclic list is empty. On imx7 this happens earlier than before, when the timer has not yet been initialized:get_timer_us()callsget_tbclk(), whose value is zero, and uses it as a divisor intick_to_time_us(), leading to a division by zero.Quoted 10 lines
I would fix this by ensuring
get_tbclk()returns at least 1 on imx7, but we could hide bugs in this way. However, this bug could also be present on other architectures, so I would just guard against entering the cyclic loop by checking whether the list is empty before doing anything else, soget_timer_us()is called "at the same point in time" as before. Something like:
if (hlist_empty(cyclic_get_list())) {
gd->flags &= ~GD_FLG_CYCLIC_RUNNING;
return;
}
Quoted 7 lines
It looks like there are two topics -- optimize the cyclic run and fix the MX7 timer.
I agree the cyclic run should exit if the list is empty, but please wait for input from Rasmus on that.
Regarding the timer, how come the timer is initialized so late on MX7 ?
timer_init() called in initcall_run_f().>
Quoted 3 lines
The Cortex-A7 should have its own ARM timer, that should be available right from the beginning. Is that ARM timer in use on your system, or does your system use GPT timer ?
iMX7 uses arch/arm/mach-imx/syscounter.c.
udelay() is called in initcall_run_f(), before timer_init(). arch_cpu_init() (arch/arm/mach-imx/mx7/soc.c) -> imx_gpcv2_init -> udelay (which runs schedule/cyclic).
And this is interesting, udelay() before timer_init() leads to a 0 us delay, so there is another bug.
I have verified that removing this udelay(65) the board boots.
Quoted 2 lines
Which board is this ?
board/toradex/colibri_imx7/
Quoted 2 lines
+CC Peng
Kind regards,
Emanuele
On 7/24/26 9:36 AM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 10 lines
Quoted 1 line
Regarding the timer, how come the timer is initialized so late on MX7 ?
timer_init()called ininitcall_run_f().>Quoted 3 lines
The Cortex-A7 should have its own ARM timer, that should be available right from the beginning. Is that ARM timer in use on your system, or does your system use GPT timer ?
iMX7 uses
arch/arm/mach-imx/syscounter.c.
udelay()is called ininitcall_run_f(), beforetimer_init().arch_cpu_init()(arch/arm/mach-imx/mx7/soc.c) ->imx_gpcv2_init-> udelay (which runs schedule/cyclic).
Yikes.
Quoted 4 lines
And this is interesting,
udelay()beforetimer_init()leads to a 0 us delay, so there is another bug.I have verified that removing this udelay(65) the board boots.
Can we start the syscounter sooner ? Something like this:
arch/arm/include/asm/arch-mx6/sys_proto.h +2 -0
@@ -36,4 +36,6 @@ static inline void iomuxc_set_rgmii_io_voltage(int io_vol) __raw_writel(io_vol, IOMUXC_SW_PAD_CTL_GRP_DDR_TYPE_RGMII); } +void syscounter_init (void ); +#endif /* __SYS_PROTO_IMX6_ */
arch/arm/include/asm/arch-mx7/sys_proto.h +2 -0
@@ -11,4 +11,6 @@ struct wdog_regs;void set_wdog_reset (struct wdog_regs *wdog); +void syscounter_init (void ); +#endif /* __SYS_PROTO_IMX7_ */
arch/arm/mach-imx/mx6/soc.c +2 -0
@@ -437,6 +437,8 @@ int arch_cpu_init(void)*/ if (mxc_get_clock (MXC_ARM_CLK ) ==396000000 )set_ahb_rate (132000000 ); + }else { +syscounter_init (); }if (is_mx6ul ()) {
arch/arm/mach-imx/mx7/soc.c +2 -0
@@ -331,6 +331,8 @@ int arch_cpu_init(void)init_snvs (); +syscounter_init (); +imx_gpcv2_init ();enable_ca7_smp ();
arch/arm/mach-imx/syscounter.c +7 -1
@@ -60,7 +60,7 @@ static inline unsigned long long us_to_tick(unsigned long long usec) }#if !CONFIG_IS_ENABLED (SKIP_LOWLEVEL_INIT ) ||IS_ENABLED (CONFIG_XPL_BUILD ) -int timer_init (void ) +void syscounter_init (void ) {struct sctr_regs *sctr = (struct sctr_regs *)SCTR_BASE_ADDR ;unsigned long val, freq;
@@ -80,6 +80,12 @@ int timer_init(void) gd->arch.tbu =0 ; gd->arch.timer_rate_hz = freq; + + return 0; +} + +int timer_init (void ) +{return 0 ; }#endif
Quoted 90 lines · Marek Vasut
On 7/24/26 9:36 AM, Emanuele Ghidoli wrote:
Hello everyone,
Quoted 10 lines
Quoted 1 line
Regarding the timer, how come the timer is initialized so late on MX7 ?
timer_init()called ininitcall_run_f().>Quoted 3 lines
The Cortex-A7 should have its own ARM timer, that should be available right from the beginning. Is that ARM timer in use on your system, or does your system use GPT timer ?
iMX7 uses
arch/arm/mach-imx/syscounter.c.
udelay()is called ininitcall_run_f(), beforetimer_init().arch_cpu_init()(arch/arm/mach-imx/mx7/soc.c) ->imx_gpcv2_init-> udelay (which runs schedule/cyclic).Yikes.
Quoted 4 lines
And this is interesting,
udelay()beforetimer_init()leads to a 0 us delay, so there is another bug.I have verified that removing this udelay(65) the board boots.
Can we start the syscounter sooner ? Something like this:
arch/arm/include/asm/ renamed from arch/arm/include/asm/arch-mx6/sys_proto.h +0
-0
arch-mx6/sys_proto.h
index7845fa8e569..5f6759a3306100644arch/arm/include/asm/arch-mx6/sys_proto.h +2
-0@@ -36,4 +36,6 @@ static inline void iomuxc_set_rgmii_io_voltage(int io_vol) __raw_writel(io_vol, IOMUXC_SW_PAD_CTL_GRP_DDR_TYPE_RGMII); } +void syscounter_init (void ); + #endif /* __SYS_PROTO_IMX6_ */arch/arm/include/asm/ renamed from arch/arm/include/asm/arch-mx7/sys_proto.h +0
-0
arch-mx7/sys_proto.h
index5da0037b2c6..765764cf1bc100644arch/arm/include/asm/arch-mx7/sys_proto.h +2
-0@@ -11,4 +11,6 @@ struct wdog_regs; void set_wdog_reset(struct wdog_regs *wdog); +void syscounter_init (void ); + #endif /* __SYS_PROTO_IMX7_ */arch/arm/mach-imx/mx6/soc.c +2
-0@@ -437,6 +437,8 @@ int arch_cpu_init(void)*/ if (mxc_get_clock(MXC_ARM_CLK) == 396000000) set_ahb_rate(132000000); + } else { + syscounter_init(); } if (is_mx6ul()) {arch/arm/mach-imx/mx7/soc.c +2
-0@@ -331,6 +331,8 @@ int arch_cpu_init(void) init_snvs(); + syscounter_init(); + imx_gpcv2_init(); enable_ca7_smp();arch/arm/mach-imx/syscounter.c +1
-1@@ -60,7 +60,7 @@ static inline unsigned long long us_to_tick(unsigned long long usec) } #if !CONFIG_IS_ENABLED(SKIP_LOWLEVEL_INIT) || IS_ENABLED(CONFIG_XPL_BUILD) -int timer_init (void ) +void syscounter_init (void ) { struct sctr_regs *sctr = (struct sctr_regs *)SCTR_BASE_ADDR;unsigned long val, freq;
arch/arm/mach-imx/syscounter.c +0
-0@@ -80,6 +80,12 @@ int timer_init(void) gd->arch.tbu = 0;
arch/arm/mach-imx/syscounter.c int timer_init(void) · line 91
Quoted 10 lines
arch/arm/mach-imx/syscounter.c +6
-0gd->arch.timer_rate_hz = freq; + + return 0; +} + +int timer_init (void ) +{ return 0; } #endif
Hello Marek,
thanks for the suggestion.
It works, build and tested on Colibri iMX7.
But imx6 is obviously broken:/home/emanuele/tdx/u-boot-build/u-boot/arch/arm/mach-imx/mx6/soc.c:441:
undefined reference to `syscounter_init'
Emanuele
On 7/28/26 11:46 AM, Emanuele Ghidoli wrote:
Hello Emanuele,
Quoted 21 lines
Quoted 7 lines
arch/arm/mach-imx/syscounter.c +1
-0+void syscounter_init (void ) { struct sctr_regs *sctr = (struct sctr_regs *)SCTR_BASE_ADDR; unsigned long val, freq;@@ -80,6 +80,12 @@ int timer_init(void) gd->arch.tbu = 0;arch/arm/mach-imx/syscounter.c int timer_init(void) · line 91
Quoted 10 lines
arch/arm/mach-imx/syscounter.c +6
-0gd->arch.timer_rate_hz = freq; + + return 0; +} + +int timer_init (void ) +{ return 0; } #endifHello Marek,
thanks for the suggestion.
Quoted 5 lines
It works, build and tested on Colibri iMX7.
But imx6 is obviously broken:
/home/emanuele/tdx/u-boot-build/u-boot/arch/arm/mach-imx/mx6/soc.c:441:
undefined reference to `syscounter_init'
Excellent, could you please submit this timer patch as a proper fix / patch ?
Thank you !