<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>I will answer everything here - <br>
</p>
<div class="moz-cite-prefix">On 2021-08-31 9:58 p.m., Liu, Monk
wrote:<br>
</div>
<blockquote type="cite" cite="mid:BL1PR12MB5269EB4E07A80EEB48A391DF84CD9@BL1PR12MB5269.namprd12.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@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;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}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;}span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}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]-->
<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">In the previous discussion, you guys stated
that we should drop the “kthread_should_park” in cleanup_job.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">@@ -676,15 +676,6 @@
drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched)<o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal"> struct drm_sched_job *job, *next;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">- /*<o:p></o:p></p>
<p class="MsoNormal">- * Don't destroy jobs while the
timeout worker is running OR thread<o:p></o:p></p>
<p class="MsoNormal">- * is being parked and hence
assumed to not touch pending_list<o:p></o:p></p>
<p class="MsoNormal">- */<o:p></o:p></p>
<p class="MsoNormal">- if ((sched->timeout !=
MAX_SCHEDULE_TIMEOUT &&<o:p></o:p></p>
<p class="MsoNormal">-
!cancel_delayed_work(&sched->work_tdr)) ||<o:p></o:p></p>
<p class="MsoNormal">- kthread_should_park())<o:p></o:p></p>
<p class="MsoNormal">- return NULL;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But I suddenly have a question here: if
return the timedout job no matter kthread_should_park() or
not, then we are backing to the original problem again: that
the timedout_job is suddenly signaling and cleanup_job still
returns it to sched_main and job is freed while it is still
handling by vendor’s timeout callback<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If we return NULL when
kthread_should_park() in cleanup_job, we can prevent above
scenario from happening: once a job is processed by
job_timedout we can stop its scheduler, and after that even
this job suddenly signaled the cleanup_job won’t return it so
sched_main won’t free it in parallel … <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">What do you
think ?</p>
</div>
</blockquote>
<p><br>
</p>
<p>Is your analysis above takes into account that you also submit<br>
'[PATCH 2/2] drm/sched: serialize job_timeout and scheduler' then
I don't see a problem -<br>
I think that as long as you put kthread_park(sched->thread)
BEFORE <br>
fetching next bad job from pending list (under spinlock) there is
no <br>
such issue as in the case you describe because this potential bad
job<br>
that became signaled will be removed from pending list before you<br>
even fetch the next job and by the time you fetch it the scheduler<br>
thread is already stopped anyway</p>
<p>If you don't submit and we keep the removal hack for now then
also no problem because<br>
we temporary remove the job we fetch for TDR from pending list
under spinlock<br>
exactly to avoid this race<br>
<br>
</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:BL1PR12MB5269EB4E07A80EEB48A391DF84CD9@BL1PR12MB5269.namprd12.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p></o:p></p>
<div>
<p class="MsoNormal">Thanks <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">Monk Liu | Cloud-GPU Core team<o:p></o:p></p>
<p class="MsoNormal">------------------------------------------<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Liu, Monk <br>
<b>Sent:</b> Wednesday, September 1, 2021 9:23 AM<br>
<b>To:</b> Koenig, Christian
<a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a>; Grodzovsky, Andrey
<a class="moz-txt-link-rfc2396E" href="mailto:Andrey.Grodzovsky@amd.com"><Andrey.Grodzovsky@amd.com></a>; Daniel Vetter
<a class="moz-txt-link-rfc2396E" href="mailto:daniel@ffwll.ch"><daniel@ffwll.ch></a>; Chen, JingWen
<a class="moz-txt-link-rfc2396E" href="mailto:JingWen.Chen2@amd.com"><JingWen.Chen2@amd.com></a><br>
<b>Cc:</b> DRI Development
<a class="moz-txt-link-rfc2396E" href="mailto:dri-devel@lists.freedesktop.org"><dri-devel@lists.freedesktop.org></a>;
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
<b>Subject:</b> [diagnostic TDR mode patches] unify our
solution opinions/suggestions in one thread<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<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">Hi Daniel/Christian/Andrey<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It looks the voice from you three are
spread over those email floods to me, the feature we are
working on (diagnostic TDR scheme) is pending there for more
than 6 month (we started it from feb 2021).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Honestly speaking the email ways that we
are using now is not friendly and quite painful to me ….<o:p></o:p></p>
<p class="MsoNormal">Can we try to put all our opinions,
suggestions, or even objects here together, let’s go through
them one by one, it’s too hard for us to reply each email on
different questions .<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">For [PATCH 1/2] drm/sched: fix the bug of
time out calculation(v4)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is a fixing patch on the timeout timer
in scheduler, can we complete this one first ? it should
already resolved all the questions and suggestions.</p>
</div>
</blockquote>
<p><br>
</p>
<p>I have no objections for this one besides getting rid of the
kthread_should_park()) return null part,<br>
if my answer above is not wrong then it seems superfluous to me</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:BL1PR12MB5269EB4E07A80EEB48A391DF84CD9@BL1PR12MB5269.namprd12.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">For [PATCH 2/2] drm/sched: serialize
job_timeout and scheduler<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I think I already explained the questions
raised by Daniel in other thread , regarding why I use
__kthread_should_park()<br>
</p>
</div>
</blockquote>
<p><br>
</p>
<p>Is this race free ? Can't the other thread execute kthread_park
after the check ?</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:BL1PR12MB5269EB4E07A80EEB48A391DF84CD9@BL1PR12MB5269.namprd12.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal">For other aspects, can we put all our
opinion synthesized here ?
</p>
</div>
</blockquote>
<p><br>
</p>
<p>So to summarize from previous threads I think that the best
solution<br>
to the problem being solved in this patch is if we do HW fence
embedding
<br>
at the drm_sched_job level instead of doing it only for amdgpu,
and modifying all
<br>
the drivers to support this we can both remove this hack and solve
the race
<br>
against concurrent drm_sched_cleanup_jobs job freeing just by
taking reference
<br>
to the hw fence of the job at the beginning of
drm_sched_job_timedout <br>
</p>
<p>If doing this refactoring for all the drivers is not an option
now and you need a quick<br>
solution such as the serialization you do here then take into
account other concurrent<br>
TDR handlers that might run, as mentioned before, without
serializing against other TDR handlers from other
<br>
schedulers you just race here against them, e.g. you parked it now
but another
<br>
one in progress will unpark it as part of calling drm_sched_start
for other rings.<br>
So you either need a global lock or dedicated single threaded
queue as Daniel suggested.<br>
At minimum we should change cancel_delayed_work in drm_sched_stop
to cancel_delayed_work_sync<br>
to cancel and flush all concurrent TDRs and probably move it to
the begining of the function, after kthread_park<br>
and before we start playing with the pending list.<br>
</p>
<p>P.S One comment I had regarding single threaded queue is that in
case we have multiple TDR<br>
arising from same event we will proceed to resetting multiple
times - something that with trylock<br>
we mostly avoid today within amdgpu (see amdgpu_device_lock_adev
and amdgpu_device_lock_hive_adev)<br>
Daniel mentioned it's not a problem but I still haven't understood
why not.<br>
</p>
<p>Andrey<br>
</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:BL1PR12MB5269EB4E07A80EEB48A391DF84CD9@BL1PR12MB5269.namprd12.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks !<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">Monk Liu | Cloud-GPU Core team<o:p></o:p></p>
<p class="MsoNormal">------------------------------------------<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</blockquote>
</body>
</html>