All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/xe/hwmon: Simplify and fix 32b wrap
@ 2025-05-30 22:31 Lucas De Marchi
  2025-05-30 22:37 ` ✓ CI.Patch_applied: success for drm/xe/hwmon: Simplify and fix 32b wrap (rev2) Patchwork
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Lucas De Marchi @ 2025-05-30 22:31 UTC (permalink / raw)
  To: intel-xe; +Cc: Lucas De Marchi, Badal Nilawar, Raag Jadav

Like done in commit eaa287069a70 ("drm/xe/guc_submit: Simplify and fix
diff calculation"), just use u32 for wrapping the value, which is
simpler and more correct: when wrapping on 32b, the accumulated value
was off by one.

Also, do not mix the u64 value from pmt with the u32 value used for the
calculation.

Cc: Badal Nilawar <badal.nilawar@intel.com>
Cc: Raag Jadav <raag.jadav@intel.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
Changes in v2:
- Rebase - now there's a u64 coming from pmt that was mixed as
  "reg_val", so use separate variables.
- Removed previous r-b due to the code changes. Raag, please let me know
  if you are still ok with this
- Link to v1: https://lore.kernel.org/r/20250529-xe-hwmon-wrap-v1-1-60d3f1eed17d@intel.com
---
 drivers/gpu/drm/xe/xe_hwmon.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
index 778354c91f598..0d32e977537ca 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@ -436,7 +436,7 @@ xe_hwmon_energy_get(struct xe_hwmon *hwmon, int channel, long *energy)
 {
 	struct xe_mmio *mmio = xe_root_tile_mmio(hwmon->xe);
 	struct xe_hwmon_energy_info *ei = &hwmon->ei[channel];
-	u64 reg_val;
+	u32 reg_val;
 	int ret = 0;
 
 	/* Energy is supported only for card and pkg */
@@ -446,29 +446,27 @@ xe_hwmon_energy_get(struct xe_hwmon *hwmon, int channel, long *energy)
 	}
 
 	if (hwmon->xe->info.platform == XE_BATTLEMAGE) {
+		u64 pmt_val;
+
 		ret = xe_pmt_telem_read(to_pci_dev(hwmon->xe->drm.dev),
 					xe_mmio_read32(mmio, PUNIT_TELEMETRY_GUID),
-					&reg_val, BMG_ENERGY_STATUS_PMT_OFFSET,	sizeof(reg_val));
-		if (ret != sizeof(reg_val)) {
+					&pmt_val, BMG_ENERGY_STATUS_PMT_OFFSET,	sizeof(pmt_val));
+		if (ret != sizeof(pmt_val)) {
 			drm_warn(&hwmon->xe->drm, "energy read from pmt failed, ret %d\n", ret);
 			*energy = 0;
 			return;
 		}
 
 		if (channel == CHANNEL_PKG)
-			reg_val = REG_FIELD_GET64(ENERGY_PKG, reg_val);
+			reg_val = REG_FIELD_GET64(ENERGY_PKG, pmt_val);
 		else
-			reg_val = REG_FIELD_GET64(ENERGY_CARD, reg_val);
+			reg_val = REG_FIELD_GET64(ENERGY_CARD, pmt_val);
 	} else {
 		reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS,
 								channel));
 	}
 
-	if (reg_val >= ei->reg_val_prev)
-		ei->accum_energy += reg_val - ei->reg_val_prev;
-	else
-		ei->accum_energy += UINT_MAX - ei->reg_val_prev + reg_val;
-
+	ei->accum_energy += reg_val - ei->reg_val_prev;
 	ei->reg_val_prev = reg_val;
 
 	*energy = mul_u64_u32_shr(ei->accum_energy, SF_ENERGY,




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

end of thread, other threads:[~2025-06-02 16:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-30 22:31 [PATCH v2] drm/xe/hwmon: Simplify and fix 32b wrap Lucas De Marchi
2025-05-30 22:37 ` ✓ CI.Patch_applied: success for drm/xe/hwmon: Simplify and fix 32b wrap (rev2) Patchwork
2025-05-30 22:38 ` ✗ CI.checkpatch: warning " Patchwork
2025-05-30 22:39 ` ✓ CI.KUnit: success " Patchwork
2025-05-30 22:49 ` ✓ CI.Build: " Patchwork
2025-05-30 22:52 ` ✓ CI.Hooks: " Patchwork
2025-05-30 22:53 ` ✓ CI.checksparse: " Patchwork
2025-05-30 23:17 ` ✓ Xe.CI.BAT: " Patchwork
2025-06-01 19:02 ` ✗ Xe.CI.Full: failure " Patchwork
2025-06-02 16:16 ` [PATCH v2] drm/xe/hwmon: Simplify and fix 32b wrap Raag Jadav

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.