Skip to content

Commit 2ada9cb

Browse files
committed
drm/i915: Fix conversion between clock ticks and nanoseconds
When tick values are large, the multiplication by NSEC_PER_SEC is larger than 64 bits and results in bad conversions. The issue is seen in PMU busyness counters that look like they have wrapped around due to bad conversion. i915 PMU implementation returns monotonically increasing counters. If a count is lesser than previous one, it will only return the larger value until the smaller value catches up. The user will see this as zero delta between two measurements even though the engines are busy. Fix it by using mul_u64_u32_div() Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14955 Signed-off-by: Umesh Nerlige Ramappa <[email protected]> Reviewed-by: Ashutosh Dixit <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b03be3e commit 2ada9cb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpu/drm/i915/gt/intel_gt_clock_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static u64 div_u64_roundup(u64 nom, u32 den)
205205

206206
u64 intel_gt_clock_interval_to_ns(const struct intel_gt *gt, u64 count)
207207
{
208-
return div_u64_roundup(count * NSEC_PER_SEC, gt->clock_frequency);
208+
return mul_u64_u32_div(count, NSEC_PER_SEC, gt->clock_frequency);
209209
}
210210

211211
u64 intel_gt_pm_interval_to_ns(const struct intel_gt *gt, u64 count)
@@ -215,7 +215,7 @@ u64 intel_gt_pm_interval_to_ns(const struct intel_gt *gt, u64 count)
215215

216216
u64 intel_gt_ns_to_clock_interval(const struct intel_gt *gt, u64 ns)
217217
{
218-
return div_u64_roundup(gt->clock_frequency * ns, NSEC_PER_SEC);
218+
return mul_u64_u32_div(ns, gt->clock_frequency, NSEC_PER_SEC);
219219
}
220220

221221
u64 intel_gt_ns_to_pm_interval(const struct intel_gt *gt, u64 ns)

0 commit comments

Comments
 (0)