From: David Laight <david.laight.linux@gmail.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: "Harry Wentland" <harry.wentland@amd.com>,
"Leo Li" <sunpeng.li@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Ovidiu Bunea" <ovidiu.bunea@amd.com>, "Ray Wu" <ray.wu@amd.com>,
"Leo Chen" <leo.chen@amd.com>, "Arnd Bergmann" <arnd@arndb.de>,
"Rodrigo Siqueira" <siqueira@igalia.com>,
"Gaghik Khachatrian" <gaghik.khachatrian@amd.com>,
"Dillon Varone" <dillon.varone@amd.com>,
"Chuanyu Tseng" <chuanyu.tseng@amd.com>,
"Linus Probert" <linus.probert@gmail.com>,
"Kees Cook" <kees@kernel.org>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/amd/display: avoid 64-bit division
Date: Fri, 19 Jun 2026 16:21:39 +0100 [thread overview]
Message-ID: <20260619162139.362299f9@pumpkin> (raw)
In-Reply-To: <20260619082313.3583603-1-arnd@kernel.org>
On Fri, 19 Jun 2026 10:23:00 +0200
Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 64-bit division is costly on 32-bit targets and should be avoided:
>
> x86_64-linux-ld: drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.o: in function `get_dp_dto_frequency_100hz':
> dce_clock_source.c:(.text+0x407): undefined reference to `__udivdi3'
> x86_64-linux-ld: drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.o: in function `dcn401_get_dp_dto_frequency_100hz':
> dce_clock_source.c:(.text+0x8b8): undefined reference to `__udivdi3'
>
> Replace the open-coded division with a div_u64() call where necessary.
> This could be done in a more clever way using mul_u64_u32_shr()
> or similar, but since this is called rarely, use the most readable
> variant that works.
>
> Fixes: 6f6483dbfacd ("drm/amd/display: Update get_pixel_clk_frequency() for DCN4x DCCG DP DTO")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
> index 7c293917e6fd..501ab1a3bac2 100644
> --- a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
> +++ b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
> @@ -1229,9 +1229,9 @@ static bool get_dp_dto_frequency_100hz(
> */
> modulo_hz = REG_READ(MODULO[inst]);
> if (modulo_hz) {
> - temp = div_u64((uint64_t)clock_hz * dp_dto_ref_khz * 10, modulo_hz);
> - ASSERT(temp / 100 <= 0xFFFFFFFFUL);
> - *pixel_clk_100hz = (unsigned int)(temp / 100);
> + temp = clock_hz * dp_dto_ref_khz * 10;
> + ASSERT(temp <= INT_MAX * modulo_hz * 100);
Doesn't that need something to force the RHS to 64bit?
(or has modulo_hz been changed in a patch I'm not seeing?)
David
> + *pixel_clk_100hz = div_u64(temp, modulo_hz * 100);
> } else
> *pixel_clk_100hz = 0;
> } else {
> @@ -1286,12 +1286,12 @@ static bool dcn401_get_dp_dto_frequency_100hz(const struct clock_source *clock_s
> */
> temp = (unsigned long long)dp_dto_integer * modulo_hz + phase_hz;
>
> - if (temp / 100 > 0xFFFFFFFFUL) {
> + if (temp > (UINT_MAX * 100ULL)) {
> /* pixel rate 100hz should never be this high, if it is, throw an assert and return 0 */
> BREAK_TO_DEBUGGER();
> *pixel_clk_100hz = 0;
> } else {
> - *pixel_clk_100hz = (unsigned int)(temp / 100);
> + *pixel_clk_100hz = div_u64(temp, 100);
> }
>
> return true;
next prev parent reply other threads:[~2026-06-19 15:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 8:23 [PATCH] drm/amd/display: avoid 64-bit division Arnd Bergmann
2026-06-19 8:30 ` sashiko-bot
2026-06-19 15:21 ` David Laight [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-07-08 13:52 Arnd Bergmann
2019-07-08 13:52 ` Arnd Bergmann
[not found] ` <20190708135238.651483-1-arnd-r2nGTMty4D4@public.gmane.org>
2019-07-08 14:16 ` Kazlauskas, Nicholas
2019-07-08 18:20 ` Abramov, Slava
2019-07-09 16:31 ` Abramov, Slava
[not found] ` <DM6PR12MB320967C48957C4F2F0E92438FEF10-lmeGfMZKVrEA9tGwT7oCEgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-07-09 16:40 ` Deucher, Alexander
2019-07-09 19:37 ` Arnd Bergmann
2019-07-09 19:37 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260619162139.362299f9@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=christian.koenig@amd.com \
--cc=chuanyu.tseng@amd.com \
--cc=dillon.varone@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gaghik.khachatrian@amd.com \
--cc=harry.wentland@amd.com \
--cc=kees@kernel.org \
--cc=leo.chen@amd.com \
--cc=linus.probert@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ovidiu.bunea@amd.com \
--cc=ray.wu@amd.com \
--cc=simona@ffwll.ch \
--cc=siqueira@igalia.com \
--cc=sunpeng.li@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.