<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Aptos;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Consolas",serif;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Purkait, Soham <soham.purkait@intel.com>
<br>
<b>Sent:</b> Friday, July 25, 2025 3:29 AM<br>
<b>To:</b> Cavitt, Jonathan <jonathan.cavitt@intel.com>; igt-dev@lists.freedesktop.org; Gupta, Anshuman <anshuman.gupta@intel.com><br>
<b>Cc:</b> Tauro, Riana <riana.tauro@intel.com>; De Marchi, Lucas <lucas.demarchi@intel.com><br>
<b>Subject:</b> Re: [PATCH i-g-t] tools/gputop/xe_gputop: Keep engine activity percentage between 0 and 100<o:p></o:p></span></p>
</div>
</div>
<p>> Hi Jonathan,<o:p></o:p></p>
<div>
<p class="MsoNormal">> > On 25-07-2025 02:51, Cavitt, Jonathan wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre style="mso-margin-top-alt:5.0pt;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > -----Original Message-----<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > From: igt-dev <a href="mailto:igt-dev-bounces@lists.freedesktop.org"><igt-dev-bounces@lists.freedesktop.org></a> On Behalf Of Soham Purkait<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > Sent: Thursday, July 24, 2025 11:51 AM<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > To: <a href="mailto:igt-dev@lists.freedesktop.org">igt-dev@lists.freedesktop.org</a>; Gupta, Anshuman <a href="mailto:anshuman.gupta@intel.com"><anshuman.gupta@intel.com></a><o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > Cc: Purkait, Soham <a href="mailto:soham.purkait@intel.com"><soham.purkait@intel.com></a>; Tauro, Riana <a href="mailto:riana.tauro@intel.com"><riana.tauro@intel.com></a>; De Marchi, Lucas <a href="mailto:lucas.demarchi@intel.com"><lucas.demarchi@intel.com></a><o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > Subject: [PATCH i-g-t] tools/gputop/xe_gputop: Keep engine activity percentage between 0 and 100<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre style="mso-margin-top-alt:5.0pt;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:5.0pt;margin-left:2.0in">> > Engine activity percentage within the valid range of 0 to 100 prevents<o:p></o:p></pre>
</blockquote>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > s/Engine activity percentage/Clamping engine activity percentage to<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > There's also a nit below, but it's non-blocking, so:<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > Reviewed-by: Jonathan Cavitt <a href="mailto:jonathan.cavitt@intel.com"><jonathan.cavitt@intel.com></a><o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre style="mso-margin-top-alt:5.0pt;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > out-of-bound values that could lead to undefined behavior during runtime.<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > Signed-off-by: Soham Purkait <a href="mailto:soham.purkait@intel.com"><soham.purkait@intel.com></a><o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > ---<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > tools/gputop/xe_gputop.c | 6 ++++++<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > 1 file changed, 6 insertions(+)<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > diff --git a/tools/gputop/xe_gputop.c b/tools/gputop/xe_gputop.c<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > index 9757369a8..ced427c0c 100644<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > --- a/tools/gputop/xe_gputop.c<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > +++ b/tools/gputop/xe_gputop.c<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > @@ -281,6 +281,12 @@ static double pmu_active_percentage(struct xe_engine *engine)<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > double percentage;<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > percentage = (pmu_active_ticks * 100) / pmu_total_ticks;<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > +<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > + if (percentage > 100)<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > + percentage = 100;<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > + else if (percentage < 0)<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > + percentage = 0;<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:5.0pt;margin-left:2.0in">> > +<o:p></o:p></pre>
</blockquote>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > NIT:<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > This clamping operation can be compressed using the fmin and fmax functions:<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > """<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > return fmax(0, fmin(percentage, 100));<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > """<o:p></o:p></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif"><o:p> </o:p></span></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">I see Lucas pointed out a proper ‘clamp’ function for this purpose, as defined in igt_aux.h.<o:p></o:p></span></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">I had tried searching for one prior but failed to do a grep for one in the repo, and eventually<o:p></o:p></span></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">discovered that C didn’t support that operation natively, so I gave up searching for it.<o:p></o:p></span></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif"><o:p> </o:p></span></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">I agree with Lucas that we should be using the clamp() function here.<o:p></o:p></span></pre>
<pre style="margin-right:1.0in"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif"><o:p> </o:p></span></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > However, it's not particularly important that this be compressed, and doing so might<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > obfuscate what the code does (on top of possibly being slower due to the function<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > calls), so I'm fine with either way of performing the clamp.<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > I should also note that we normally shouldn't clamp the percentage like this generally,<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > but since this is just a helper function used to pass a value into a pretty-print operation<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > for data visualization purposes, I suppose it's okay. On the other hand, maybe we should<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > be printing the true, raw value separately? Maybe as an extension of<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:5.0pt;margin-left:1.0in">> > print_percentage_bar?<o:p></o:p></pre>
</blockquote>
<p class="MsoNormal">> What could be the possible usages of the raw values ? Thanks, Soham
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">We return the raw percentage value for tests such as xe_drm_fdinfo, even if the raw percentage<o:p></o:p></p>
<p class="MsoNormal">value is some greater-than-100 amount, so I figured it would be reasonable to print the raw<o:p></o:p></p>
<p class="MsoNormal">percentage value in this case as well.<o:p></o:p></p>
<p class="MsoNormal">-Jonathan Cavitt<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre style="mso-margin-top-alt:5.0pt;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > (Though, I guess at that point, we'd want to do the clamping there, rather than in<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > pmu_active_percentage...).<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > Sorry. I'm just thinking aloud. You can take this advice or leave it.<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > -Jonathan Cavitt<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:1.0in;margin-bottom:0in;margin-left:1.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre style="mso-margin-top-alt:5.0pt;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > return percentage;<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > }<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > -- <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > 2.43.0<o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:5.0pt;margin-left:2.0in">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:5.0pt;margin-left:2.0in">> > <o:p></o:p></pre>
<pre style="mso-margin-top-alt:0in;margin-right:2.0in;margin-bottom:0in;margin-left:2.0in;margin-bottom:.0001pt">> > <o:p></o:p></pre>
</blockquote>
</blockquote>
</div>
</body>
</html>