[PATCH i-g-t v2] tools/gputop/xe_gputop: Keep engine activity percentage between 0 and 100
Soham Purkait
soham.purkait at intel.com
Tue Jul 29 11:18:43 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.
One typical scenario could be during a GT reset, where the engine activity
percentage might spike to a very high value, potentially leading to a
segmentation fault while setting the progress bar.
v1:
- Use clamp for clearer and shorter percentage bounding (Lucas)
Signed-off-by: Soham Purkait <soham.purkait at intel.com>
Reviewed-by: Riana Tauro <riana.tauro at intel.com>
---
tools/gputop/xe_gputop.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/gputop/xe_gputop.c b/tools/gputop/xe_gputop.c
index 9757369a8..bb2caa6ea 100644
--- a/tools/gputop/xe_gputop.c
+++ b/tools/gputop/xe_gputop.c
@@ -281,7 +281,8 @@ static double pmu_active_percentage(struct xe_engine *engine)
double percentage;
percentage = (pmu_active_ticks * 100) / pmu_total_ticks;
- return percentage;
+
+ return clamp(percentage, 0., 100.);
}
static int
--
2.34.1
More information about the igt-dev
mailing list