Skip to contentSkip to conversation

media: iris: avoid plain 64-bit division

PATCH In review Arnd Bergmann 2 participants 2 messages Oct 2 – Oct 3

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

PATCH 1/1 media: iris: avoid plain 64-bit division

From: Arnd Bergmann <[email protected]>

inst->fw_caps[BITRATE].value is a 64-bit integer, which on 32-bit architectures cannot be divided:

ERROR: modpost: drivers/media/platform/qcom/iris/qcom-iris.ko: symbol '__divdi3' undefined!

In particular, doing three divisions in a row is particularly slow, even on 64-bit CPUs.

Rework the calculation to replace it with a single division, thus avoiding the build failure.

Fixes 5f21cd9a4ae4 ("media: iris: add support for multi_slice in iris encoder")

---
Please check the math, as I'm not sure if this is the intended amount of rounding. Previously it was rounding down twice and up once, now it just rounds up during the combined division.

Ideally this would be replaced with a cast of the incoming value to u32, but doing this requires to prove that this does not overflow.

---
 drivers/media/platform/qcom/iris/iris_ctrls.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/iris/iris_ctrls.c +3 -2
index 8c4c47944f22..5294999fdf7b 100644
@@ -1588,8 +1588,9 @@ int iris_set_slice_count(struct iris_inst *inst, enum platform_inst_fw_cap_type
 	} else if (slice_mode == V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES) {
 		hfi_value = inst->fw_caps[SLICE_MAX_BYTES].value;
 		if (rc_type != HFI_RC_OFF) {
-			max_avg_slicesize = DIV_ROUND_UP((inst->fw_caps[BITRATE].value / fps) / 8,
-							 slice_caps->max_slices_per_frame);
+			max_avg_slicesize = DIV_U64_ROUND_UP(inst->fw_caps[BITRATE].value,
+							     fps * 8 *
+							     slice_caps->max_slices_per_frame);
 		} else {
 			/*
 			 * No bitrate target exists under RC_OFF, so approximate a
Signature · 1 line
2.53.0
#1 lore raw
Quoted 13 lines · On Fri, 2 Oct 2026 14:44:22 +0200 Arnd Bergmann <[email protected]> wrote:

From: Arnd Bergmann <[email protected]>

inst->fw_caps[BITRATE].value is a 64-bit integer, which on 32-bit architectures cannot be divided:

ERROR: modpost: drivers/media/platform/qcom/iris/qcom-iris.ko: symbol '__divdi3' undefined!

In particular, doing three divisions in a row is particularly slow, even on 64-bit CPUs.

Rework the calculation to replace it with a single division, thus avoiding the build failure.

Quoted 6 lines
Fixes 5f21cd9a4ae4 ("media: iris: add support for multi_slice in iris encoder")

---
Please check the math, as I'm not sure if this is the intended amount of rounding. Previously it was rounding down twice and up once, now it just rounds up during the combined division.

Can definitely change the result:

	DIV_ROUND_UP(7 / 3, 2) is 1
but
	DIV_ROUND_UP(7, 2 * 3) is 2

who knows what the value is supposed to be.

Quoted 3 lines

Ideally this would be replaced with a cast of the incoming value to u32, but doing this requires to prove that this does not overflow.

You only need to prove that in incoming value is less than 32G (Hz). The '/ 8' is cheap(ish) and can be done first.

David

Quoted 22 lines
---
 drivers/media/platform/qcom/iris/iris_ctrls.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/iris/iris_ctrls.c +3 -2
index 8c4c47944f22..5294999fdf7b 100644
@@ -1588,8 +1588,9 @@ int iris_set_slice_count(struct iris_inst *inst, enum platform_inst_fw_cap_type
 	} else if (slice_mode == V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES) {
 		hfi_value = inst->fw_caps[SLICE_MAX_BYTES].value;
 		if (rc_type != HFI_RC_OFF) {
-			max_avg_slicesize = DIV_ROUND_UP((inst->fw_caps[BITRATE].value / fps) / 8,
-							 slice_caps->max_slices_per_frame);
+			max_avg_slicesize = DIV_U64_ROUND_UP(inst->fw_caps[BITRATE].value,
+							     fps * 8 *
+							     slice_caps->max_slices_per_frame);
 		} else {
 			/*
 			 * No bitrate target exists under RC_OFF, so approximate a