<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>Hi Jonathan,</p>
    <div class="moz-cite-prefix">On 25-07-2025 02:51, Cavitt, Jonathan
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:BL1PR11MB544584E2D9C75D9DC47B627DE55EA@BL1PR11MB5445.namprd11.prod.outlook.com">
      <pre wrap="" class="moz-quote-pre">-----Original Message-----
From: igt-dev <a class="moz-txt-link-rfc2396E" href="mailto:igt-dev-bounces@lists.freedesktop.org"><igt-dev-bounces@lists.freedesktop.org></a> On Behalf Of Soham Purkait
Sent: Thursday, July 24, 2025 11:51 AM
To: <a class="moz-txt-link-abbreviated" href="mailto:igt-dev@lists.freedesktop.org">igt-dev@lists.freedesktop.org</a>; Gupta, Anshuman <a class="moz-txt-link-rfc2396E" href="mailto:anshuman.gupta@intel.com"><anshuman.gupta@intel.com></a>
Cc: Purkait, Soham <a class="moz-txt-link-rfc2396E" href="mailto:soham.purkait@intel.com"><soham.purkait@intel.com></a>; Tauro, Riana <a class="moz-txt-link-rfc2396E" href="mailto:riana.tauro@intel.com"><riana.tauro@intel.com></a>; De Marchi, Lucas <a class="moz-txt-link-rfc2396E" href="mailto:lucas.demarchi@intel.com"><lucas.demarchi@intel.com></a>
Subject: [PATCH i-g-t] tools/gputop/xe_gputop: Keep engine activity percentage between 0 and 100
</pre>
      <blockquote type="cite">
        <pre wrap="" class="moz-quote-pre">
Engine activity percentage within the valid range of 0 to 100 prevents
</pre>
      </blockquote>
      <pre wrap="" class="moz-quote-pre">

s/Engine activity percentage/Clamping engine activity percentage to

There's also a nit below, but it's non-blocking, so:
Reviewed-by: Jonathan Cavitt <a class="moz-txt-link-rfc2396E" href="mailto:jonathan.cavitt@intel.com"><jonathan.cavitt@intel.com></a>


</pre>
      <blockquote type="cite">
        <pre wrap="" class="moz-quote-pre">out-of-bound values that could lead to undefined behavior during runtime.

Signed-off-by: Soham Purkait <a class="moz-txt-link-rfc2396E" href="mailto:soham.purkait@intel.com"><soham.purkait@intel.com></a>
---
 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;
+
</pre>
      </blockquote>
      <pre wrap="" class="moz-quote-pre">
NIT:
This clamping operation can be compressed using the fmin and fmax functions:

"""
        return fmax(0, fmin(percentage, 100));
"""

However, it's not particularly important that this be compressed, and doing so might
obfuscate what the code does (on top of possibly being slower due to the function
calls), so I'm fine with either way of performing the clamp.

I should also note that we normally shouldn't clamp the percentage like this generally,
but since this is just a helper function used to pass a value into a pretty-print operation
for data visualization purposes, I suppose it's okay.  On the other hand, maybe we should
be printing the true, raw value separately?  Maybe as an extension of
print_percentage_bar?</pre>
    </blockquote>
    What could be the possible usages of the <span style="white-space: pre-wrap">raw values ? 

Thanks,
Soham</span>
    <blockquote type="cite" cite="mid:BL1PR11MB544584E2D9C75D9DC47B627DE55EA@BL1PR11MB5445.namprd11.prod.outlook.com">
      <pre wrap="" class="moz-quote-pre">

(Though, I guess at that point, we'd want to do the clamping there, rather than in
pmu_active_percentage...).

Sorry.  I'm just thinking aloud.  You can take this advice or leave it.

-Jonathan Cavitt

</pre>
      <blockquote type="cite">
        <pre wrap="" class="moz-quote-pre">   return percentage;
 }
 
-- 
2.43.0


</pre>
      </blockquote>
    </blockquote>
  </body>
</html>