public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] soc: qcom: stats: fix 64-bit division
@ 2023-12-06 12:37 Arnd Bergmann
  2023-12-06 12:37 ` [PATCH 2/2] soc: qcom_stats: add AOSS_QMP dependency Arnd Bergmann
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arnd Bergmann @ 2023-12-06 12:37 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Arnd Bergmann, Andy Gross, Konrad Dybcio, Stephen Boyd,
	Uwe Kleine-König, linux-arm-msm, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/soc/qcom/qcom_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/qcom_stats.c b/drivers/soc/qcom/qcom_stats.c
index 4763d62a8cb0..5ec8a754b22b 100644
--- a/drivers/soc/qcom/qcom_stats.c
+++ b/drivers/soc/qcom/qcom_stats.c
@@ -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++)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] soc: qcom_stats: add AOSS_QMP dependency
  2023-12-06 12:37 [PATCH 1/2] soc: qcom: stats: fix 64-bit division Arnd Bergmann
@ 2023-12-06 12:37 ` Arnd Bergmann
  2023-12-06 14:16 ` [PATCH 1/2] soc: qcom: stats: fix 64-bit division Uwe Kleine-König
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2023-12-06 12:37 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio
  Cc: Arnd Bergmann, Dmitry Baryshkov, Neil Armstrong, Ulf Hansson,
	AngeloGioacchino Del Regno, Souradeep Chowdhury, linux-arm-msm,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/soc/qcom/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index bf213b514a52..a55f9d6c392a 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -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
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] soc: qcom: stats: fix 64-bit division
  2023-12-06 12:37 [PATCH 1/2] soc: qcom: stats: fix 64-bit division Arnd Bergmann
  2023-12-06 12:37 ` [PATCH 2/2] soc: qcom_stats: add AOSS_QMP dependency Arnd Bergmann
@ 2023-12-06 14:16 ` Uwe Kleine-König
  2023-12-07 15:24 ` Bjorn Andersson
  2023-12-08 14:55 ` (subset) " Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2023-12-06 14:16 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Bjorn Andersson, Arnd Bergmann, Andy Gross, Konrad Dybcio,
	Stephen Boyd, linux-arm-msm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]

Hallo Arnd,

On Wed, Dec 06, 2023 at 01:37:06PM +0100, Arnd Bergmann wrote:
> 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.

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] soc: qcom: stats: fix 64-bit division
  2023-12-06 12:37 [PATCH 1/2] soc: qcom: stats: fix 64-bit division Arnd Bergmann
  2023-12-06 12:37 ` [PATCH 2/2] soc: qcom_stats: add AOSS_QMP dependency Arnd Bergmann
  2023-12-06 14:16 ` [PATCH 1/2] soc: qcom: stats: fix 64-bit division Uwe Kleine-König
@ 2023-12-07 15:24 ` Bjorn Andersson
  2023-12-08 14:55 ` (subset) " Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Andersson @ 2023-12-07 15:24 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Arnd Bergmann, Andy Gross, Konrad Dybcio, Stephen Boyd,
	Uwe Kleine-König, linux-arm-msm, linux-kernel

On Wed, Dec 06, 2023 at 01:37:06PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

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

> ---
>  drivers/soc/qcom/qcom_stats.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/qcom/qcom_stats.c b/drivers/soc/qcom/qcom_stats.c
> index 4763d62a8cb0..5ec8a754b22b 100644
> --- a/drivers/soc/qcom/qcom_stats.c
> +++ b/drivers/soc/qcom/qcom_stats.c
> @@ -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++)
> -- 
> 2.39.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (subset) [PATCH 1/2] soc: qcom: stats: fix 64-bit division
  2023-12-06 12:37 [PATCH 1/2] soc: qcom: stats: fix 64-bit division Arnd Bergmann
                   ` (2 preceding siblings ...)
  2023-12-07 15:24 ` Bjorn Andersson
@ 2023-12-08 14:55 ` Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Andersson @ 2023-12-08 14:55 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Arnd Bergmann, Andy Gross, Konrad Dybcio, Stephen Boyd,
	Uwe Kleine-König, linux-arm-msm, linux-kernel


On Wed, 06 Dec 2023 13:37:06 +0100, Arnd Bergmann wrote:
> 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,
-- 
Bjorn Andersson <andersson@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-08 14:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 12:37 [PATCH 1/2] soc: qcom: stats: fix 64-bit division Arnd Bergmann
2023-12-06 12:37 ` [PATCH 2/2] soc: qcom_stats: add AOSS_QMP dependency Arnd Bergmann
2023-12-06 14:16 ` [PATCH 1/2] soc: qcom: stats: fix 64-bit division Uwe Kleine-König
2023-12-07 15:24 ` Bjorn Andersson
2023-12-08 14:55 ` (subset) " Bjorn Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox