<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;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
p.msipheader4d0fcdd7, li.msipheader4d0fcdd7, div.msipheader4d0fcdd7
        {mso-style-name:msipheader4d0fcdd7;
        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 bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="msipheader4d0fcdd7" style="margin:0in;margin-bottom:.0001pt"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#0078D7">[AMD Official Use Only - Internal Distribution Only]</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">Hi, Jiange,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">      How to handle the case that multi-apps do the auto dump? This patch seems not multi-process safety.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">Best Regards<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">Dennis Li<o:p></o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:windowtext">From:</span></b><span style="color:windowtext"> amd-gfx <amd-gfx-bounces@lists.freedesktop.org>
<b>On Behalf Of </b>Christian König<br>
<b>Sent:</b> Thursday, May 14, 2020 4:29 PM<br>
<b>To:</b> Zhao, Jiange <Jiange.Zhao@amd.com>; 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 v4<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi Jiange,<br>
<br>
it probably won't hurt, but I would just drop that. You need roughly 4 billion GPU resets until the UINT_MAX-1 becomes zero again.<br>
<br>
Christian.<br>
<br>
Am 14.05.20 um 09:14 schrieb Zhao, Jiange:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p style="margin:15.0pt"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#0078D7">[AMD Official Use Only - Internal Distribution 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">Hi Christian,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal">wait_for_completion_interruptible_timeout() would decrease autodump.dumping.done to UINT_MAX-1.<span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal">complete_all() here would restore autodump.dumping to the state as in amdgpu_debugfs_autodump_init().<span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal">I want to make sure every open() deals with the same situation.<span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal">Jiange<span style="font-size:12.0pt"><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>From:</b> Christian König <a href="mailto:ckoenig.leichtzumerken@gmail.com">
<ckoenig.leichtzumerken@gmail.com></a><br>
<b>Sent:</b> Thursday, May 14, 2020 3:01 PM<br>
<b>To:</b> Zhao, Jiange <a href="mailto:Jiange.Zhao@amd.com"><Jiange.Zhao@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> Pelloux-prayer, Pierre-eric <a href="mailto:Pierre-eric.Pelloux-prayer@amd.com">
<Pierre-eric.Pelloux-prayer@amd.com></a>; Zhao, Jiange <a href="mailto:Jiange.Zhao@amd.com">
<Jiange.Zhao@amd.com></a>; Kuehling, Felix <a href="mailto:Felix.Kuehling@amd.com">
<Felix.Kuehling@amd.com></a>; Deucher, Alexander <a href="mailto:Alexander.Deucher@amd.com">
<Alexander.Deucher@amd.com></a>; Koenig, Christian <a href="mailto:Christian.Koenig@amd.com">
<Christian.Koenig@amd.com></a>; Liu, Monk <a href="mailto:Monk.Liu@amd.com"><Monk.Liu@amd.com></a>; Zhang, Hawking
<a href="mailto:Hawking.Zhang@amd.com"><Hawking.Zhang@amd.com></a><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: Add autodump debugfs node for gpu reset v4
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Am 14.05.20 um 07:29 schrieb <a href="mailto:jianzh@amd.com">
jianzh@amd.com</a>:<br>
> From: Jiange Zhao <a href="mailto:Jiange.Zhao@amd.com"><Jiange.Zhao@amd.com></a><br>
><br>
> When GPU got timeout, it would notify an interested part<br>
> of an opportunity to dump info before actual GPU reset.<br>
><br>
> A usermode app would open 'autodump' node under debugfs system<br>
> and poll() for readable/writable. When a GPU reset is due,<br>
> amdgpu would notify usermode app through wait_queue_head and give<br>
> it 10 minutes to 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<br>
> the 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>
> v2: (1) changed 'registered' to 'app_listening'<br>
>      (2) add a mutex in open() to prevent race condition<br>
><br>
> v3 (chk): grab the reset lock to avoid race in autodump_open,<br>
>            rename debugfs file to amdgpu_autodump,<br>
>            provide autodump_read as well,<br>
>            style and code cleanups<br>
><br>
> v4: add 'bool app_listening' to differentiate situations, so that<br>
>      the node can be reopened; also, there is no need to wait for<br>
>      completion when no app is waiting for a dump.<br>
><br>
> v5: change 'bool app_listening' to 'enum amdgpu_autodump_state'<br>
>      add 'app_state_mutex' for race conditions:<br>
>        (1)Only 1 user can open this file node<br>
>        (2)wait_dump() can only take effect after poll() executed.<br>
>        (3)eliminated the race condition between release() and<br>
>           wait_dump()<br>
><br>
> v6: removed 'enum amdgpu_autodump_state' and 'app_state_mutex'<br>
>      removed state checking in amdgpu_debugfs_wait_dump<br>
>      Improve on top of version 3 so that the node can be reopened.<br>
><br>
> v7: move reinit_completion into open() so that only one user<br>
>      can open it.<br>
><br>
> Signed-off-by: Jiange Zhao <a href="mailto:Jiange.Zhao@amd.com"><Jiange.Zhao@amd.com></a><br>
> ---<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h         |  2 +<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 79 ++++++++++++++++++++-<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h |  6 ++<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c  |  2 +<br>
>   4 files changed, 88 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> index 2a806cb55b78..9e8eeddfe7ce 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> @@ -992,6 +992,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 ttm_bo_device *bdev)<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
> index 1a4894fa3693..efee3f1adecf 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
> @@ -27,7 +27,7 @@<br>
>   #include <linux/pci.h><br>
>   #include <linux/uaccess.h><br>
>   #include <linux/pm_runtime.h><br>
> -<br>
> +#include <linux/poll.h><br>
>   #include <drm/drm_debugfs.h><br>
>   <br>
>   #include "amdgpu.h"<br>
> @@ -74,8 +74,83 @@ int amdgpu_debugfs_add_files(struct amdgpu_device *adev,<br>
>        return 0;<br>
>   }<br>
>   <br>
> +int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev)<br>
> +{<br>
> +#if defined(CONFIG_DEBUG_FS)<br>
> +     unsigned long timeout = 600 * HZ;<br>
> +     int ret;<br>
> +<br>
> +     wake_up_interruptible(&adev->autodump.gpu_hang);<br>
> +<br>
> +     ret = wait_for_completion_interruptible_timeout(&adev->autodump.dumping, timeout);<br>
> +     complete_all(&adev->autodump.dumping);<br>
<br>
Sorry that I'm mentioning this only now. But what is this complete_all() <br>
here good for?<br>
<br>
I mean we already waited for completion, didn't we?<br>
<br>
Christian.<br>
<br>
> +     if (ret == 0) {<br>
> +             pr_err("autodump: timeout, 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 file *file)<br>
> +{<br>
> +     struct amdgpu_device *adev = inode->i_private;<br>
> +     int ret;<br>
> +<br>
> +     file->private_data = adev;<br>
> +<br>
> +     mutex_lock(&adev->lock_reset);<br>
> +     if (adev->autodump.dumping.done) {<br>
> +             reinit_completion(&adev->autodump.dumping);<br>
> +             ret = 0;<br>
> +     } else {<br>
> +             ret = -EBUSY;<br>
> +     }<br>
> +     mutex_unlock(&adev->lock_reset);<br>
> +<br>
> +     return ret;<br>
> +}<br>
> +<br>
> +static int amdgpu_debugfs_autodump_release(struct inode *inode, struct file *file)<br>
> +{<br>
> +     struct amdgpu_device *adev = file->private_data;<br>
> +<br>
> +     complete_all(&adev->autodump.dumping);<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +static unsigned int amdgpu_debugfs_autodump_poll(struct file *file, struct poll_table_struct *poll_table)<br>
> +{<br>
> +     struct amdgpu_device *adev = file->private_data;<br>
> +<br>
> +     poll_wait(file, &adev->autodump.gpu_hang, 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>
> +<br>
> +static void amdgpu_debugfs_autodump_init(struct amdgpu_device *adev)<br>
> +{<br>
> +     init_completion(&adev->autodump.dumping);<br>
> +     complete_all(&adev->autodump.dumping);<br>
> +     init_waitqueue_head(&adev->autodump.gpu_hang);<br>
> +<br>
> +     debugfs_create_file("amdgpu_autodump", 0600,<br>
> +             adev->ddev->primary->debugfs_root,<br>
> +             adev, &autodump_debug_fops);<br>
> +}<br>
> +<br>
>   /**<br>
>    * amdgpu_debugfs_process_reg_op - Handle MMIO register reads/writes<br>
>    *<br>
> @@ -1434,6 +1509,8 @@ int amdgpu_debugfs_init(struct amdgpu_device *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 b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
> index de12d1101526..2803884d338d 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
> @@ -31,6 +31,11 @@ struct amdgpu_debugfs {<br>
>        unsigned                num_files;<br>
>   };<br>
>   <br>
> +struct amdgpu_autodump {<br>
> +     struct completion               dumping;<br>
> +     struct wait_queue_head          gpu_hang;<br>
> +};<br>
> +<br>
>   int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);<br>
>   int amdgpu_debugfs_init(struct amdgpu_device *adev);<br>
>   void amdgpu_debugfs_fini(struct amdgpu_device *adev);<br>
> @@ -40,3 +45,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 b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> index cc41e8f5ad14..545beebcf43e 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> @@ -3927,6 +3927,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];<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>