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

Lucas De Marchi lucas.demarchi at intel.com
Thu Jul 24 21:18:25 UTC 2025


On Fri, Jul 25, 2025 at 12:20:40AM +0530, Soham Purkait wrote:
>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;

maybe this would be clear enough and shorter?

	return clamp(percentage, 0., 100.);

Lucas De Marchi

> }
>
>-- 
>2.43.0
>


More information about the igt-dev mailing list