Skip to contentSkip to conversation

clocksource: tegra186: avoid 64-bit division

PATCH Applied Arnd Bergmann 5 participants 6 messages Jun 20, 2025 – Jul 25, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: tegra186: avoid 64-bit division

From: Arnd Bergmann <[email protected]>

The newly added function causes a build failure on 32-bit targets with older compiler version such as gcc-10:

arm-linux-gnueabi-ld: drivers/clocksource/timer-tegra186.o: in function `tegra186_wdt_get_timeleft':
timer-tegra186.c:(.text+0x3c2): undefined reference to `__aeabi_uldivmod'

The calculation can trivially be changed to avoid the division entirely, as USEC_PER_SEC is a multiple of 5. Change both such calculation for consistency, even though gcc apparently managed to optimize the other one properly already.

Fixes 28c842c8b0f5 ("clocksource/drivers/timer-tegra186: Add WDIOC_GETTIMELEFT support")
---
 drivers/clocksource/timer-tegra186.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clocksource/timer-tegra186.c +2 -2
index e5394f98a02e..bd3d443e41cd 100644
@@ -159,7 +159,7 @@ static void tegra186_wdt_enable(struct tegra186_wdt *wdt)
 	tmr_writel(wdt->tmr, TMRCSSR_SRC_USEC, TMRCSSR);
 
 	/* configure timer (system reset happens on the fifth expiration) */
-	value = TMRCR_PTV(wdt->base.timeout * USEC_PER_SEC / 5) |
+	value = TMRCR_PTV(wdt->base.timeout * (USEC_PER_SEC / 5)) |
 		TMRCR_PERIODIC | TMRCR_ENABLE;
 	tmr_writel(wdt->tmr, value, TMRCR);
 
@@ -267,7 +267,7 @@ static unsigned int tegra186_wdt_get_timeleft(struct watchdog_device *wdd)
 	 * counter value to the time of the counter expirations that
 	 * remain.
 	 */
-	timeleft += (((u64)wdt->base.timeout * USEC_PER_SEC) / 5) * (4 - expiration);
+	timeleft += (u64)wdt->base.timeout * (USEC_PER_SEC / 5) * (4 - expiration);
 
 	/*
 	 * Convert the current counter value to seconds,
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 33 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added function causes a build failure on 32-bit targets with older compiler version such as gcc-10:

arm-linux-gnueabi-ld: drivers/clocksource/timer-tegra186.o: in function `tegra186_wdt_get_timeleft':
timer-tegra186.c:(.text+0x3c2): undefined reference to `__aeabi_uldivmod'

The calculation can trivially be changed to avoid the division entirely, as USEC_PER_SEC is a multiple of 5. Change both such calculation for consistency, even though gcc apparently managed to optimize the other one properly already.

Fixes 28c842c8b0f5 ("clocksource/drivers/timer-tegra186: Add WDIOC_GETTIMELEFT support")
---
  drivers/clocksource/timer-tegra186.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clocksource/timer-tegra186.c +1 -1
index e5394f98a02e..bd3d443e41cd 100644
@@ -159,7 +159,7 @@ static void tegra186_wdt_enable(struct tegra186_wdt *wdt)
  	tmr_writel(wdt->tmr, TMRCSSR_SRC_USEC, TMRCSSR);
 
  	/* configure timer (system reset happens on the fifth expiration) */
-	value = TMRCR_PTV(wdt->base.timeout * USEC_PER_SEC / 5) |
+	value = TMRCR_PTV(wdt->base.timeout * (USEC_PER_SEC / 5)) |
  		TMRCR_PERIODIC | TMRCR_ENABLE;
  	tmr_writel(wdt->tmr, value, TMRCR);
 

drivers/clocksource/timer-tegra186.c static unsigned int tegra186_wdt_get_timeleft(struct watchdog_device *wdd) · line 273

Quoted 8 lines
drivers/clocksource/timer-tegra186.c +1 -1
@@ -267,7 +267,7 @@ static unsigned int tegra186_wdt_get_timeleft(struct watchdog_device *wdd)
  	 * counter value to the time of the counter expirations that
  	 * remain.
  	 */
-	timeleft += (((u64)wdt->base.timeout * USEC_PER_SEC) / 5) * (4 - expiration);
+	timeleft += (u64)wdt->base.timeout * (USEC_PER_SEC / 5) * (4 - expiration);
 
  	/*
  	 * Convert the current counter value to seconds,

Guenter has also posted a fix for this here [0].

Jon

[0] https://lore.kernel.org/linux-tegra/[email protected]/T/#me403a7afd04bbf24e29d3880123a4faa656eab05

Signature · 1 line
nvpublic
#2 lore raw
Quoted 9 lines · Jon Hunter
Quoted 7 lines · Arnd Bergmann
drivers/clocksource/timer-tegra186.c +1 -1
@@ -267,7 +267,7 @@ static unsigned int tegra186_wdt_get_timeleft(struct watchdog_device *wdd)
  	 * counter value to the time of the counter expirations that
  	 * remain.
  	 */
-	timeleft += (((u64)wdt->base.timeout * USEC_PER_SEC) / 5) * (4 - expiration);
+	timeleft += (u64)wdt->base.timeout * (USEC_PER_SEC / 5) * (4 - expiration);
 
Quoted 6 lines

drivers/clocksource/timer-tegra186.c static unsigned int tegra186_wdt_get_timeleft(struct watchdog_device *wdd) · line 273

Quoted 2 lines
drivers/clocksource/timer-tegra186.c +0 -0
  	/*
  	 * Convert the current counter value to seconds,

Guenter has also posted a fix for this here [0].

Right, that one looks better than mine, as it avoids another division entirely.

Arnd

#3 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added function causes a build failure on 32-bit targets with older compiler version such as gcc-10:

arm-linux-gnueabi-ld: drivers/clocksource/timer-tegra186.o: in function `tegra186_wdt_get_timeleft':
timer-tegra186.c:(.text+0x3c2): undefined reference to `__aeabi_uldivmod'

Quoted 8 lines

The calculation can trivially be changed to avoid the division entirely, as USEC_PER_SEC is a multiple of 5. Change both such calculation for consistency, even though gcc apparently managed to optimize the other one properly already.

Fixes 28c842c8b0f5 ("clocksource/drivers/timer-tegra186: Add WDIOC_GETTIMELEFT support")

---

Applied, thanks

Fixed conflict with https://lore.kernel.org/r/[email protected]

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
merge bot Applied
#4 lore raw

[tip: timers/clocksource] clocksource/drivers/tegra186: Avoid 64-bit division

In reply to Arnd Bergmann
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     7e11b4f49b5147817cd87489d4e63ca9fc92753c
Gitweb:        https://git.kernel.org/tip/7e11b4f49b5147817cd87489d4e63ca9fc92753c
Author:        Arnd Bergmann <[email protected]>
AuthorDate:    Fri, 20 Jun 2025 13:19:35 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 15 Jul 2025 13:09:35 +02:00

clocksource/drivers/tegra186: Avoid 64-bit division

The newly added function causes a build failure on 32-bit targets with older compiler version such as gcc-10:

arm-linux-gnueabi-ld: drivers/clocksource/timer-tegra186.o: in function `tegra186_wdt_get_timeleft':
timer-tegra186.c:(.text+0x3c2): undefined reference to `__aeabi_uldivmod'

The calculation can trivially be changed to avoid the division entirely, as USEC_PER_SEC is a multiple of 5. Change both such calculation for consistency, even though gcc apparently managed to optimize the other one properly already.

Fixes 28c842c8b0f5 ("clocksource/drivers/timer-tegra186: Add WDIOC_GETTIMELEFT support")

[dlezcano] : Fixed conflict with [email protected]

---
 drivers/clocksource/timer-tegra186.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clocksource/timer-tegra186.c +1 -1
index d403a3f..1ec7b38 100644
@@ -159,7 +159,7 @@ static void tegra186_wdt_enable(struct tegra186_wdt *wdt)
 	tmr_writel(wdt->tmr, TMRCSSR_SRC_USEC, TMRCSSR);
 
 	/* configure timer (system reset happens on the fifth expiration) */
-	value = TMRCR_PTV(wdt->base.timeout * USEC_PER_SEC / 5) |
+	value = TMRCR_PTV(wdt->base.timeout * (USEC_PER_SEC / 5)) |
 		TMRCR_PERIODIC | TMRCR_ENABLE;
 	tmr_writel(wdt->tmr, value, TMRCR);
 
merge bot Applied
#5 lore raw

[tip: timers/clocksource] clocksource/drivers/tegra186: Avoid 64-bit division

In reply to Arnd Bergmann
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     836758dc1e43928aa1a357009f5c3164a00cbfb0
Gitweb:        https://git.kernel.org/tip/836758dc1e43928aa1a357009f5c3164a00cbfb0
Author:        Arnd Bergmann <[email protected]>
AuthorDate:    Fri, 20 Jun 2025 13:19:35 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 12:06:46 +02:00

clocksource/drivers/tegra186: Avoid 64-bit division

The newly added function causes a build failure on 32-bit targets with older compiler version such as gcc-10:

arm-linux-gnueabi-ld: drivers/clocksource/timer-tegra186.o: in function `tegra186_wdt_get_timeleft':
timer-tegra186.c:(.text+0x3c2): undefined reference to `__aeabi_uldivmod'

The calculation can trivially be changed to avoid the division entirely, as USEC_PER_SEC is a multiple of 5. Change both such calculation for consistency, even though gcc apparently managed to optimize the other one properly already.

[ dlezcano : Fixed conflict with [email protected] ]

Fixes 28c842c8b0f5 ("clocksource/drivers/timer-tegra186: Add WDIOC_GETTIMELEFT support")
---
 drivers/clocksource/timer-tegra186.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clocksource/timer-tegra186.c +1 -1
index d403a3f..1ec7b38 100644
@@ -159,7 +159,7 @@ static void tegra186_wdt_enable(struct tegra186_wdt *wdt)
 	tmr_writel(wdt->tmr, TMRCSSR_SRC_USEC, TMRCSSR);
 
 	/* configure timer (system reset happens on the fifth expiration) */
-	value = TMRCR_PTV(wdt->base.timeout * USEC_PER_SEC / 5) |
+	value = TMRCR_PTV(wdt->base.timeout * (USEC_PER_SEC / 5)) |
 		TMRCR_PERIODIC | TMRCR_ENABLE;
 	tmr_writel(wdt->tmr, value, TMRCR);