<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Of course, considering all the suggestions, I will implement a write callback for usermode app to notify KMD that a dump is finished by sending "Done".</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In this way, usermode app can do multiple dumps without closing the node,<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Jiange<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Pelloux-prayer, Pierre-eric <Pierre-eric.Pelloux-prayer@amd.com><br>
<b>Sent:</b> Friday, April 24, 2020 3:46 PM<br>
<b>To:</b> Zhao, Jiange <Jiange.Zhao@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Pelloux-prayer, Pierre-eric <Pierre-eric.Pelloux-prayer@amd.com>; Kuehling, Felix <Felix.Kuehling@amd.com>; Liu, Monk <Monk.Liu@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: Add autodump debugfs node for gpu reset</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi Jiange,<br>
<br>
FYI I'm working on adding a new "--autodump" command to umr that uses this feature.<br>
This is not yet merged but you can find the code here: <a href="https://gitlab.freedesktop.org/pepp/umr/-/tree/autodump">
https://gitlab.freedesktop.org/pepp/umr/-/tree/autodump</a><br>
<br>
> (3) At the same time, considering the use case of this node, I believe that only the first GPU reset is worthy of a dump.<br>
<br>
If it's possible I'd like to be able to do multiple dumps instead of limiting ourselves to only the first one.<br>
<br>
Thanks!<br>
Pierre-Eric<br>
<br>
<br>
<br>
> (4) I didn't implement race condition guard because I believe that this node caters for a cautious super-user and a single client is enough to do all the work. I can add the logic if you think it is necessary.<br>
> <br>
> Jiange<br>
> <br>
> -----Original Message-----<br>
> From: Koenig, Christian <Christian.Koenig@amd.com> <br>
> Sent: Thursday, April 23, 2020 4:53 PM<br>
> To: Zhao, Jiange <Jiange.Zhao@amd.com>; amd-gfx@lists.freedesktop.org<br>
> Cc: Kuehling, Felix <Felix.Kuehling@amd.com>; Pelloux-prayer, Pierre-eric <Pierre-eric.Pelloux-prayer@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com>; Liu, Monk <Monk.Liu@amd.com>; Zhao, Jiange <Jiange.Zhao@amd.com><br>
> Subject: Re: [PATCH] drm/amdgpu: Add autodump debugfs node for gpu reset<br>
> <br>
> Am 23.04.20 um 09:19 schrieb jianzh@amd.com:<br>
>> From: Jiange Zhao <Jiange.Zhao@amd.com><br>
>><br>
>> When GPU got timeout, it would notify an interested part of an <br>
>> opportunity to dump info before actual GPU reset.<br>
>><br>
>> A usermode app would open 'autodump' node under debugfs system and <br>
>> poll() for readable/writable. When a GPU reset is due, amdgpu would <br>
>> notify usermode app through wait_queue_head and give it 10 minutes to <br>
>> dump info.<br>
>><br>
>> After usermode app has done its work, this 'autodump' node is closed.<br>
>> On node closure, amdgpu gets to know the dump is done through the <br>
>> completion that is triggered in release().<br>
>><br>
>> There is no write or read callback because necessary info can be <br>
>> obtained through dmesg and umr. Messages back and forth between <br>
>> usermode app and amdgpu are unnecessary.<br>
>><br>
>> Signed-off-by: Jiange Zhao <Jiange.Zhao@amd.com><br>
>> ---<br>
>> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 9 +++<br>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 85 +++++++++++++++++++++<br>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h | 1 +<br>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +<br>
>> 4 files changed, 97 insertions(+)<br>
>><br>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h <br>
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
>> index bc1e0fd71a09..a505b547f242 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
>> @@ -724,6 +724,13 @@ struct amd_powerplay {<br>
>> const struct amd_pm_funcs *pp_funcs;<br>
>> };<br>
>> <br>
>> +struct amdgpu_autodump {<br>
>> + bool registered;<br>
>> + struct completion completed;<br>
> <br>
> Registered and completed seems to have the same meaning.<br>
> <br>
>> + struct dentry *dentry;<br>
>> + struct wait_queue_head gpu_hang_wait;<br>
>> +};<br>
>> +<br>
>> #define AMDGPU_RESET_MAGIC_NUM 64<br>
>> #define AMDGPU_MAX_DF_PERFMONS 4<br>
>> struct amdgpu_device {<br>
>> @@ -990,6 +997,8 @@ struct amdgpu_device {<br>
>> char product_number[16];<br>
>> char product_name[32];<br>
>> char serial[16];<br>
>> +<br>
>> + struct amdgpu_autodump autodump;<br>
>> };<br>
>> <br>
>> static inline struct amdgpu_device *amdgpu_ttm_adev(struct <br>
>> ttm_bo_device *bdev) diff --git <br>
>> a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c <br>
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
>> index 1a4894fa3693..cdd4bf00adee 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
>> @@ -74,8 +74,91 @@ int amdgpu_debugfs_add_files(struct amdgpu_device *adev,<br>
>> return 0;<br>
>> }<br>
>> <br>
>> +int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev) { #if <br>
>> +defined(CONFIG_DEBUG_FS)<br>
>> + int ret;<br>
>> + unsigned long tmo = 600*HZ;<br>
> <br>
> In general please declare constant lines first and variable like "i" or "r" last.<br>
> <br>
>> +<br>
>> + if (!adev->autodump.registered)<br>
>> + return 0;<br>
>> +<br>
>> + wake_up_interruptible(&adev->autodump.gpu_hang_wait);<br>
>> +<br>
>> + ret = <br>
>> +wait_for_completion_interruptible_timeout(&adev->autodump.completed, <br>
>> +tmo);<br>
> <br>
> This is racy, in other words it can happen that a new client opens up the debugfs file without being signaled but blocks the reset here.<br>
> <br>
> You could use two completion structures to avoid that.<br>
> <br>
>> + if (ret == 0) { /* time out and dump tool still not finish its dump*/<br>
>> + pr_err("autodump: timeout before dump finished, move on to gpu recovery\n");<br>
>> + return -ETIMEDOUT;<br>
>> + }<br>
>> +#endif<br>
>> + return 0;<br>
>> +}<br>
>> +<br>
>> #if defined(CONFIG_DEBUG_FS)<br>
>> <br>
>> +static int amdgpu_debugfs_autodump_open(struct inode *inode, struct <br>
>> +file *file) {<br>
>> + int ret;<br>
>> + struct amdgpu_device *adev;<br>
>> +<br>
>> + ret = simple_open(inode, file);<br>
>> + if (ret)<br>
>> + return ret;<br>
>> +<br>
>> + adev = file->private_data;<br>
>> + if (adev->autodump.registered == true)<br>
>> + return -EINVAL;<br>
> <br>
> Probably better to return -EBUSY here. And this is racy, and might need a lock e.g. multiple clients could open the file at the same time.<br>
> <br>
> If we use a struct completion for registered we could use the spinlock of that one for protection here.<br>
> <br>
>> +<br>
>> + adev->autodump.registered = true;<br>
> <br>
> You also need to reset the completion structure here otherwise only the first GPU reset would work with this.<br>
> <br>
>> +<br>
>> + return 0;<br>
>> +}<br>
>> +<br>
>> +static int amdgpu_debugfs_autodump_release(struct inode *inode, <br>
>> +struct file *file) {<br>
>> + struct amdgpu_device *adev = file->private_data;<br>
>> +<br>
>> + complete(&adev->autodump.completed);<br>
>> + adev->autodump.registered = false;<br>
>> +<br>
>> + return 0;<br>
>> +}<br>
>> +<br>
>> +unsigned int amdgpu_debugfs_autodump_poll(struct file *file, struct <br>
>> +poll_table_struct *poll_table) {<br>
>> + struct amdgpu_device *adev = file->private_data;<br>
>> +<br>
>> + poll_wait(file, &adev->autodump.gpu_hang_wait, poll_table);<br>
>> +<br>
>> + if (adev->in_gpu_reset)<br>
>> + return POLLIN | POLLRDNORM | POLLWRNORM;<br>
>> +<br>
>> + return 0;<br>
>> +}<br>
>> +<br>
>> +static const struct file_operations autodump_debug_fops = {<br>
>> + .owner = THIS_MODULE,<br>
>> + .open = amdgpu_debugfs_autodump_open,<br>
>> + .poll = amdgpu_debugfs_autodump_poll,<br>
>> + .release = amdgpu_debugfs_autodump_release, };<br>
>> +<br>
>> +static int amdgpu_debugfs_autodump_init(struct amdgpu_device *adev) {<br>
>> + struct dentry *entry;<br>
>> +<br>
>> + init_completion(&adev->autodump.completed);<br>
>> + init_waitqueue_head(&adev->autodump.gpu_hang_wait);<br>
>> + adev->autodump.registered = false;<br>
>> +<br>
>> + entry = debugfs_create_file("autodump", 0600,<br>
>> + adev->ddev->primary->debugfs_root,<br>
>> + adev, &autodump_debug_fops);<br>
>> + adev->autodump.dentry = entry;<br>
>> +<br>
>> + return 0;<br>
>> +}<br>
>> +<br>
>> /**<br>
>> * amdgpu_debugfs_process_reg_op - Handle MMIO register reads/writes<br>
>> *<br>
>> @@ -1434,6 +1517,8 @@ int amdgpu_debugfs_init(struct amdgpu_device <br>
>> *adev)<br>
>> <br>
>> amdgpu_ras_debugfs_create_all(adev);<br>
>> <br>
>> + amdgpu_debugfs_autodump_init(adev);<br>
>> +<br>
>> return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,<br>
>> ARRAY_SIZE(amdgpu_debugfs_list));<br>
>> }<br>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h <br>
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
>> index de12d1101526..9428940a696d 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
>> @@ -40,3 +40,4 @@ int amdgpu_debugfs_add_files(struct amdgpu_device *adev,<br>
>> int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);<br>
>> int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);<br>
>> int amdgpu_debugfs_gem_init(struct amdgpu_device *adev);<br>
>> +int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev);<br>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c <br>
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> index 3d601d5dd5af..44e54ea7af0f 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> @@ -3915,6 +3915,8 @@ static int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,<br>
>> int i, r = 0;<br>
>> bool need_full_reset = *need_full_reset_arg;<br>
>> <br>
>> + amdgpu_debugfs_wait_dump(adev);<br>
>> +<br>
>> /* block all schedulers and reset given job's ring */<br>
>> for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {<br>
>> struct amdgpu_ring *ring = adev->rings[i];<br>
> _______________________________________________<br>
> amd-gfx mailing list<br>
> amd-gfx@lists.freedesktop.org<br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
> <br>
</div>
</span></font></div>
</div>
</body>
</html>