<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=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
p.msipheadera4477989, li.msipheadera4477989, div.msipheadera4477989
{mso-style-name:msipheadera4477989;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="msipheadera4477989" style="margin:0in"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">[AMD Official Use Only]</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So the final decision is rollback to scnprintf().<o:p></o:p></p>
<p class="MsoNormal">If we can define our own helper functions like sysfs_emit/sysfs_emit_at
<o:p></o:p></p>
<p class="MsoNormal">but without page boundary aligned limitation to make life easier?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">Lang<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Powell, Darren <Darren.Powell@amd.com> <br>
<b>Sent:</b> Thursday, September 9, 2021 6:18 AM<br>
<b>To:</b> Christian König <ckoenig.leichtzumerken@gmail.com>; Lazar, Lijo <Lijo.Lazar@amd.com>; Yu, Lang <Lang.Yu@amd.com>; amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Tian Tao <tiantao6@hisilicon.com><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: fix sysfs_emit/sysfs_emit_at warnings<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="margin:5.0pt"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">[AMD Official Use Only]<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Christian König <<a href="mailto:ckoenig.leichtzumerken@gmail.com">ckoenig.leichtzumerken@gmail.com</a>><br>
<b>Sent:</b> Wednesday, September 8, 2021 8:43 AM<br>
<b>To:</b> Lazar, Lijo <<a href="mailto:Lijo.Lazar@amd.com">Lijo.Lazar@amd.com</a>>; Yu, Lang <<a href="mailto:Lang.Yu@amd.com">Lang.Yu@amd.com</a>>;
<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a> <<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>><br>
<b>Cc:</b> Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com">Alexander.Deucher@amd.com</a>>; Huang, Ray <<a href="mailto:Ray.Huang@amd.com">Ray.Huang@amd.com</a>>; Tian Tao <<a href="mailto:tiantao6@hisilicon.com">tiantao6@hisilicon.com</a>>; Powell,
Darren <<a href="mailto:Darren.Powell@amd.com">Darren.Powell@amd.com</a>><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: fix sysfs_emit/sysfs_emit_at warnings</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Am 08.09.21 um 12:22 schrieb Lazar, Lijo:<br>
> On 9/8/2021 3:08 PM, Christian König wrote:<br>
>> Am 08.09.21 um 11:29 schrieb Lazar, Lijo:<br>
>>> On 9/8/2021 2:32 PM, Yu, Lang wrote:<br>
>>>> [AMD Official Use Only]<br>
>>>>> -----Original Message-----<br>
>>>>> From: Lazar, Lijo <<a href="mailto:Lijo.Lazar@amd.com">Lijo.Lazar@amd.com</a>><br>
>>>>> Sent: Wednesday, September 8, 2021 4:55 PM<br>
>>>>> To: Yu, Lang <<a href="mailto:Lang.Yu@amd.com">Lang.Yu@amd.com</a>>; Christian König<br>
>>>>> <<a href="mailto:ckoenig.leichtzumerken@gmail.com">ckoenig.leichtzumerken@gmail.com</a>>;
<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
>>>>> Cc: Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com">Alexander.Deucher@amd.com</a>>; Huang, Ray<br>
>>>>> <<a href="mailto:Ray.Huang@amd.com">Ray.Huang@amd.com</a>>; Tian Tao <<a href="mailto:tiantao6@hisilicon.com">tiantao6@hisilicon.com</a>><br>
>>>>> Subject: Re: [PATCH] drm/amdgpu: fix sysfs_emit/sysfs_emit_at <br>
>>>>> warnings<br>
>>>>><br>
>>>>><br>
>>>>><br>
>>>>> On 9/8/2021 1:14 PM, Yu, Lang wrote:<br>
>>>>>> [AMD Official Use Only]<br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>>> -----Original Message-----<br>
>>>>>>> From: Lazar, Lijo <<a href="mailto:Lijo.Lazar@amd.com">Lijo.Lazar@amd.com</a>><br>
>>>>>>> Sent: Wednesday, September 8, 2021 3:36 PM<br>
>>>>>>> To: Christian König <<a href="mailto:ckoenig.leichtzumerken@gmail.com">ckoenig.leichtzumerken@gmail.com</a>>; Yu, Lang<br>
>>>>>>> <<a href="mailto:Lang.Yu@amd.com">Lang.Yu@amd.com</a>>; <a href="mailto:amd-gfx@lists.freedesktop.org">
amd-gfx@lists.freedesktop.org</a><br>
>>>>>>> Cc: Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com">Alexander.Deucher@amd.com</a>>; Huang, Ray<br>
>>>>>>> <<a href="mailto:Ray.Huang@amd.com">Ray.Huang@amd.com</a>>; Tian Tao <<a href="mailto:tiantao6@hisilicon.com">tiantao6@hisilicon.com</a>><br>
>>>>>>> Subject: Re: [PATCH] drm/amdgpu: fix sysfs_emit/sysfs_emit_at<br>
>>>>>>> warnings<br>
>>>>>>><br>
>>>>>>><br>
>>>>>>><br>
>>>>>>> On 9/8/2021 12:07 PM, Christian König wrote:<br>
>>>>>>>> Am 08.09.21 um 07:56 schrieb Lang Yu:<br>
>>>>>>>>> sysfs_emit and sysfs_emit_at requrie a page boundary aligned buf<br>
>>>>>>>>> address. Make them happy!<br>
>>>>>>>>><br>
>>>>>>>>> Warning Log:<br>
>>>>>>>>> [ 492.545174] invalid sysfs_emit_at: buf:00000000f19bdfde at:0 [<br>
>>>>>>>>> 492.546416] WARNING: CPU: 7 PID: 1304 at fs/sysfs/file.c:765<br>
>>>>>>>>> sysfs_emit_at+0x4a/0xa0<br>
>>>>>>>>> [ 492.654805] Call Trace:<br>
>>>>>>>>> [ 492.655353] ? smu_cmn_get_metrics_table+0x40/0x50 [amdgpu] [<br>
>>>>>>>>> 492.656780] vangogh_print_clk_levels+0x369/0x410 [amdgpu] [<br>
>>>>>>>>> 492.658245] vangogh_common_print_clk_levels+0x77/0x80 [amdgpu] [<br>
>>>>>>>>> 492.659733] ? preempt_schedule_common+0x18/0x30 [ 492.660713]<br>
>>>>>>>>> smu_print_ppclk_levels+0x65/0x90 [amdgpu] [ 492.662107]<br>
>>>>>>>>> amdgpu_get_pp_od_clk_voltage+0x13d/0x190 [amdgpu] [ 492.663620]<br>
>>>>>>>>> dev_attr_show+0x1d/0x40<br>
>>>>>>>><br>
>>>>>>>> Mhm, that at least partially doesn't looks like the right <br>
>>>>>>>> approach to me.<br>
>>>>>>>><br>
>>>>>>>> Why do we have string printing and sysfs code in the hardware<br>
>>>>>>>> version specific backend in the first place?<br>
>>>>>>>><br>
>>>>>>><br>
>>>>>>> This is a callback meant for printing ASIC specific information to<br>
>>>>>>> sysfs node. The buffer passed in sysfs read is passed as it is <br>
>>>>>>> to the callback API.<br>
>>>>>>><br>
>>>>>>>> That stuff needs to be implemented for each hardware generation <br>
>>>>>>>> and<br>
>>>>>>>> is now cluttered with sysfs buffer offset calculations.<br>
>>>>>>>><br>
>>>>>>><br>
>>>>>>> Looks like the warning happened because of this usage.<br>
>>>>>>><br>
>>>>>>> size = amdgpu_dpm_print_clock_levels(adev, <br>
>>>>>>> OD_SCLK, buf);<br>
>>>>>>> size += amdgpu_dpm_print_clock_levels(adev, <br>
>>>>>>> OD_MCLK,<br>
>>>>>>> buf+size);<br>
>>>>>>> size += amdgpu_dpm_print_clock_levels(adev,<br>
>>>>>>> OD_VDDC_CURVE, buf+size);<br>
>>>>>>> size += amdgpu_dpm_print_clock_levels(adev,<br>
>>>>>>> OD_VDDGFX_OFFSET, buf+size);<br>
>>>>>>> size += amdgpu_dpm_print_clock_levels(adev,<br>
>>>>>>> OD_RANGE,<br>
>>>>>>> buf+size);<br>
>>>>>>> size += amdgpu_dpm_print_clock_levels(adev, <br>
>>>>>>> OD_CCLK,<br>
>>>>>>> buf+size);<br>
>>>>>>><br>
>>>>>>><br>
>>>>>> [Yu, Lang]<br>
>>>>>> Yes. So it is fine we just fix the caller <br>
>>>>>> amdgpu_get_pp_od_clk_voltage like<br>
>>>>> following:<br>
>>>>>><br>
>>>>>> static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,<br>
>>>>>> struct device_attribute *attr,<br>
>>>>>> char *buf)<br>
>>>>>> {<br>
>>>>>> struct drm_device *ddev = dev_get_drvdata(dev);<br>
>>>>>> struct amdgpu_device *adev = drm_to_adev(ddev);<br>
>>>>>> ssize_t size, offset;<br>
>>>>>> int ret, i;<br>
>>>>>> char temp_buf[512];<br>
>>>>>> char clock_type[] = {OD_SCLK, OD_MCLK, OD_VDDC_CURVE,<br>
>>>>>> OD_VDDGFX_OFFSET, OD_RANGE, OD_CCLK};<br>
>>>>>><br>
>>>>>> if (amdgpu_in_reset(adev))<br>
>>>>>> return -EPERM;<br>
>>>>>> if (adev->in_suspend && !adev->in_runpm)<br>
>>>>>> return -EPERM;<br>
>>>>>><br>
>>>>>> ret = pm_runtime_get_sync(ddev->dev);<br>
>>>>>> if (ret < 0) {<br>
>>>>>> pm_runtime_put_autosuspend(ddev->dev);<br>
>>>>>> return ret;<br>
>>>>>> }<br>
>>>>>><br>
>>>>>> offset = 0;<br>
>>>>>><br>
>>>>>> if (adev->powerplay.pp_funcs->print_clock_levels) {<br>
>>>>>> for (i = 0; i < ARRAY_SIZE(clock_type); i++) {<br>
>>>>>> size = amdgpu_dpm_print_clock_levels(adev,<br>
>>>>> clock_type[i], buf);<br>
>>>>>> if (offset + size > PAGE_SIZE)<br>
>>>>>> break;<br>
>>>>>> memcpy(temp_buf + offset, buf, size);<br>
>>>>>> offset += size;<br>
>>>>>> }<br>
>>>>>> memcpy(buf, temp_buf, offset);<br>
>>>>>> size = offset;<br>
>>>>>> } else {<br>
>>>>>> size = sysfs_emit(buf, "\n");<br>
>>>>>> }<br>
>>>>>> pm_runtime_mark_last_busy(ddev->dev);<br>
>>>>>> pm_runtime_put_autosuspend(ddev->dev);<br>
>>>>>><br>
>>>>>> return size;<br>
>>>>>> }<br>
>>>>>><br>
>>>>> Prefer to avoid any extra stack or heap usage for buffer. Maybe <br>
>>>>> another arg to<br>
>>>>> pass offset along with buf?<br>
>>>>><br>
>>>> [Yu, Lang]<br>
>>>> Actually, the buf address contains the offset(offset_in_page(buf)) .<br>
>>><br>
>>> Though it's not a problem based on codeflow, static analysis tools <br>
>>> might complain.<br>
>>><br>
>>>> Or we just rollback to sprintf/snprintf.<br>
>>>><br>
>>><br>
>>> snprintf with (PAGE_SIZE-size) may be simpler. I think Darren took <br>
>>> the effort to convert these, he may have some other ideas.<br>
The changes I made were intended to simply replace snprintf with sysfs_emit as per <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">linux/Documentation/filesystems/sysfs.rst:246,247 <o:p></o:p></p>
<div>
<p class="MsoNormal"> - show() should only use sysfs_emit() or sysfs_emit_at() when formatting<o:p></o:p></p>
</div>
<p class="MsoNormal"> the value to be returned to user space.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I specifically tried not to change the design, but only as I didn't have <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">background in Power Management.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">>><br>
>> This is not what I meant. See from the design point of view the <br>
>> print_clock_levels() callback is the bad idea to begin with.<br>
>><br>
>> What we should have instead is a callback which returns the clock as <br>
>> a value which is then printed in the amdgpu_get_pp_od_clk_voltage() <br>
>> function.<br>
>><br>
>> This avoids passing around the buffer and remaining size everywhere <br>
>> and also guarantees that the sysfs have unified printing over all <br>
>> hardware generations.<br>
>><br>
><br>
> The scenario is one node used for multiple parameters - OD_SCLK, <br>
> OD_CCLK, OD_VDDGFX_OFFSET etc.(mostly to avoid cluttering sysfs with <br>
> lots of nodes). On top of it, the parameters supported (for ex: CCLK <br>
> is not valid on dGPUs), the number of levels supported etc. vary <br>
> across ASICs. There has to be multiple calls or the call needs to <br>
> return multiple values for a single parameter (for ex: up to 4, 8 or <br>
> 16 levels of GFXCLK depending on ASIC).<br>
<br>
Well exactly that is questionable design for sysfs.<br>
<br>
See the sysfs_emit() and sysfs_emit_at() functions are designed the way <br>
they are because you should have only one value per file, which is then <br>
printed at exactly one location.<br>
<br>
Take a look at the documentation for sysfs for more details.<br>
<br>
> I don't know the history of the callback, mostly it was considered <br>
> more efficient to print it directly rather than fetch and print. <br>
> Alex/Evan may know the details.<br>
<br>
Yeah, somebody with a bit more background in power management needs to <br>
take a closer look at this here. Just keep me looped in.<br>
<br>
Regards,<br>
Christian.<br>
<br>
><br>
> Thanks,<br>
> Lijo<br>
><br>
>> Regards,<br>
>> Christian.<br>
>><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>