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

Riana Tauro riana.tauro at intel.com
Tue Jul 29 06:36:40 UTC 2025



On 7/25/2025 5:05 PM, 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.
> 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>


Looks good to me
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



More information about the igt-dev mailing list