[PATCH i-g-t] tools/gputop/xe_gputop: Keep engine activity percentage between 0 and 100

Soham Purkait soham.purkait at intel.com
Thu Jul 24 18:50:40 UTC 2025


Engine activity percentage within the valid range of 0 to 100 prevents
out-of-bound values that could lead to undefined behavior during runtime.

Signed-off-by: Soham Purkait <soham.purkait at intel.com>
---
 tools/gputop/xe_gputop.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/gputop/xe_gputop.c b/tools/gputop/xe_gputop.c
index 9757369a8..ced427c0c 100644
--- a/tools/gputop/xe_gputop.c
+++ b/tools/gputop/xe_gputop.c
@@ -281,6 +281,12 @@ static double pmu_active_percentage(struct xe_engine *engine)
 	double percentage;
 
 	percentage = (pmu_active_ticks * 100) / pmu_total_ticks;
+
+	if (percentage > 100)
+		percentage = 100;
+	else if (percentage < 0)
+		percentage = 0;
+
 	return percentage;
 }
 
-- 
2.43.0



More information about the igt-dev mailing list