Skip to contentSkip to conversation

soc: qcom: stats: fix 64-bit division

PATCH Applied Arnd Bergmann 3 participants 5 messages Dec 6, 2023 – Dec 8, 2023

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

PATCH 1/2 soc: qcom: stats: fix 64-bit division

From: Arnd Bergmann <[email protected]>

Unguarded 64-bit division is not allowed on 32-bit kernels because this is very slow. The result of trying anyway is a link failure:

arm-linux-gnueabi-ld: drivers/soc/qcom/qcom_stats.o: in function `qcom_ddr_stats_show':
qcom_stats.c:(.text+0x334): undefined reference to `__aeabi_uldivmod'

As this function is only used for debugging and not performance critical, rewrite it to use div_u64() instead. ARCH_TIMER_FREQ is a multiple of MSEC_PER_SEC anyway, so there is no loss in precisison.

Fixes e84e61bdb97c ("soc: qcom: stats: Add DDR sleep stats")
---
 drivers/soc/qcom/qcom_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/qcom_stats.c +1 -1
index 4763d62a8cb0..5ec8a754b22b 100644
@@ -221,7 +221,7 @@ static int qcom_ddr_stats_show(struct seq_file *s, void *unused)
 
 	for (i = 0; i < ddr.entry_count; i++) {
 		/* Convert the period to ms */
-		entry[i].dur = mult_frac(MSEC_PER_SEC, entry[i].dur, ARCH_TIMER_FREQ);
+		entry[i].dur = div_u64(entry[i].dur, ARCH_TIMER_FREQ / MSEC_PER_SEC);
 	}
 
 	for (i = 0; i < ddr.entry_count; i++)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 soc: qcom_stats: add AOSS_QMP dependency

From: Arnd Bergmann <[email protected]>

Using the QMP functions fails in a built-in driver when QMP is a loadable module:

aarch64-linux-ld: drivers/soc/qcom/qcom_stats.o: in function `qcom_ddr_stats_show':
qcom_stats.c:(.text+0x6f4): undefined reference to `qmp_send'
aarch64-linux-ld: drivers/soc/qcom/qcom_stats.o: in function `qcom_stats_probe':
qcom_stats.c:(.text+0x117c): undefined reference to `qmp_get'

Fixes e84e61bdb97c ("soc: qcom: stats: Add DDR sleep stats")
---
 drivers/soc/qcom/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/qcom/Kconfig +1 -0
index bf213b514a52..a55f9d6c392a 100644
@@ -222,6 +222,7 @@ config QCOM_STATS
 	tristate "Qualcomm Technologies, Inc. (QTI) Sleep stats driver"
 	depends on (ARCH_QCOM && DEBUG_FS) || COMPILE_TEST
 	depends on QCOM_SMEM
+	depends on QCOM_AOSS_QMP || !QCOM_AOSS_QMP
 	help
 	  Qualcomm Technologies, Inc. (QTI) Sleep stats driver to read
 	  the shared memory exported by the remote processor related to
Signature · 1 line
2.39.2
Reviewed-by on v1 1/2
#2 lore raw
In reply to Arnd Bergmann

Hallo Arnd,

Quoted 9 lines · Arnd Bergmann

Unguarded 64-bit division is not allowed on 32-bit kernels because this is very slow. The result of trying anyway is a link failure:

arm-linux-gnueabi-ld: drivers/soc/qcom/qcom_stats.o: in function `qcom_ddr_stats_show':
qcom_stats.c:(.text+0x334): undefined reference to `__aeabi_uldivmod'

As this function is only used for debugging and not performance critical, rewrite it to use div_u64() instead. ARCH_TIMER_FREQ is a multiple of MSEC_PER_SEC anyway, so there is no loss in precisison.

Maybe add this information in a comment?

We have

	#define ARCH_TIMER_FREQ         19200000

so it's a multiple of MSEC_PER_SEC (= 1000) indeed.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
maintainer
#3 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Unguarded 64-bit division is not allowed on 32-bit kernels because this is very slow. The result of trying anyway is a link failure:

arm-linux-gnueabi-ld: drivers/soc/qcom/qcom_stats.o: in function `qcom_ddr_stats_show':
qcom_stats.c:(.text+0x334): undefined reference to `__aeabi_uldivmod'

Quoted 6 lines

As this function is only used for debugging and not performance critical, rewrite it to use div_u64() instead. ARCH_TIMER_FREQ is a multiple of MSEC_PER_SEC anyway, so there is no loss in precisison.

Fixes e84e61bdb97c ("soc: qcom: stats: Add DDR sleep stats")

I had [1] lined up already, but hadn't pushed the branch out out... Like your version better, so dropping mine.

[1] https://lore.kernel.org/all/20231205-qcom_stats-aeabi_uldivmod-fix-v1-1-f94ecec5e894@quicinc.com/

Thanks,
Bjorn

Quoted 20 lines
---
 drivers/soc/qcom/qcom_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/qcom_stats.c +1 -1
index 4763d62a8cb0..5ec8a754b22b 100644
@@ -221,7 +221,7 @@ static int qcom_ddr_stats_show(struct seq_file *s, void *unused)
 
 	for (i = 0; i < ddr.entry_count; i++) {
 		/* Convert the period to ms */
-		entry[i].dur = mult_frac(MSEC_PER_SEC, entry[i].dur, ARCH_TIMER_FREQ);
+		entry[i].dur = div_u64(entry[i].dur, ARCH_TIMER_FREQ / MSEC_PER_SEC);
 	}
 
 	for (i = 0; i < ddr.entry_count; i++)
Signature · 1 line
2.39.2
maintainer Applied
#4 lore raw

Re: (subset) [PATCH 1/2] soc: qcom: stats: fix 64-bit division

In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

Unguarded 64-bit division is not allowed on 32-bit kernels because this is very slow. The result of trying anyway is a link failure:

arm-linux-gnueabi-ld: drivers/soc/qcom/qcom_stats.o: in function `qcom_ddr_stats_show':
qcom_stats.c:(.text+0x334): undefined reference to `__aeabi_uldivmod'

As this function is only used for debugging and not performance critical, rewrite it to use div_u64() instead. ARCH_TIMER_FREQ is a multiple of MSEC_PER_SEC anyway, so there is no loss in precisison.

[...]

Applied, thanks!

[1/2] soc: qcom: stats: fix 64-bit division

      commit: 73380e2573c34a45e01786750a4a2efafc2248bd

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>