[PATCH] drm/i915/hwmon: Round up power1_max_interval value for read/show

Ashutosh Dixit ashutosh.dixit at intel.com
Mon Feb 27 20:51:59 UTC 2023


Bug: https://gitlab.freedesktop.org/drm/intel/-/issues/7754
Signed-off-by: Ashutosh Dixit <ashutosh.dixit at intel.com>
---
 drivers/gpu/drm/i915/i915_hwmon.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
index 7c20a6f47b92e..327731edea70c 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.c
+++ b/drivers/gpu/drm/i915/i915_hwmon.c
@@ -150,6 +150,13 @@ hwm_energy(struct hwm_drvdata *ddat, long *energy)
 	mutex_unlock(&hwmon->hwmon_lock);
 }
 
+static u64 mul_u64_u32_shr_roundup(u64 a, u32 mul, unsigned int shift)
+{
+	u64 x = mul_u64_u32_shr(a, mul, 0) + BIT_ULL(shift) - 1;
+
+	return mul_u64_u32_shr(x, 1, shift);
+}
+
 static ssize_t
 hwm_power1_max_interval_show(struct device *dev, struct device_attribute *attr,
 			     char *buf)
@@ -175,7 +182,7 @@ hwm_power1_max_interval_show(struct device *dev, struct device_attribute *attr,
 	 */
 	tau4 = ((1 << x_w) | x) << y;
 	/* val in hwmon interface units (millisec) */
-	out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
+	out = mul_u64_u32_shr_roundup(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
 
 	return sysfs_emit(buf, "%llu\n", out);
 }
-- 
2.38.0



More information about the Intel-gfx-trybot mailing list