<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hi Monk,<br>
      <br>
      that is to remove the problem that allocating memory could fail.<br>
      <br>
      E.g. we only add the fence after sending the command to the
      hardware, so there is now way back and we need to add the fence or
      break memory management.<br>
      <br>
      So reservation_object_reserve_shared() makes sure there is a free
      fence slot *before* we start to prepare things for the hardware.<br>
      <br>
      Regards,<br>
      Christian.<br>
      <br>
      Am 06.03.2018 um 11:19 schrieb Liu, Monk:<br>
    </div>
    <blockquote type="cite"
cite="mid:BLUPR12MB0449F8D5C0FA6DEC7BE6C24B84D90@BLUPR12MB0449.namprd12.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
        dir="ltr">
        <p style="margin-top:0;margin-bottom:0">Hi Chris<span
            style="font-size: 12pt;"> </span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="font-size:
            12pt;"><br>
          </span></p>
        <p style="margin-top:0;margin-bottom:0">another question is why
          we not just call "<span style="color: rgb(220, 220, 170); background-color: rgb(30, 30, 30); font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; font-size: 14px; white-space: pre;">reservation_object_reserve_shared"</span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; font-size: 14px; white-space: pre;">during below add_shared_fence function,
 so the BUG_ON() could be avoided and caller won't need</span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; font-size: 14px; white-space: pre;">to worry when and how much time
 it should call reserve_shared() ?</span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; font-size: 14px; white-space: pre;">

</span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; font-size: 14px; white-space: pre;">thanks !</span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="font-size:
            12pt;"><br>
          </span></p>
        <p style="margin-top:0;margin-bottom:0"><span style="font-size:
            12pt;"></span></p>
        <div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; font-size: 14px; line-height: 19px; white-space: pre;">
<div><span style="color: #569cd6;">void</span> <span style="color: #dcdcaa;">reservation_object_add_shared_fence</span>(<span style="color: #569cd6;">struct</span> reservation_object *obj,</div>
<div>                     <span style="color: #569cd6;">struct</span> dma_fence *fence)</div>
<div>{</div>
<div>    <span style="color: #569cd6;">struct</span> reservation_object_list *old, *fobj = obj-><span style="color: #9cdcfe;">staged</span>;</div>


<div>    old = <span style="color: #dcdcaa;">reservation_object_get_list</span>(obj);</div>
<div>    obj-><span style="color: #9cdcfe;">staged</span> = <span style="color: #569cd6;">
NULL</span>;</div>


<div>    <span style="color: #c586c0;">if</span> (!fobj) {</div>
<div>        <span style="color: #dcdcaa;">BUG_ON</span>(old-><span style="color: #9cdcfe;">shared_count</span> >= old-><span style="color: #9cdcfe;">shared_max</span>);</div>
<div>        <span style="color: #dcdcaa;">reservation_object_add_shared_inplace</span>(obj, old, fence);</div>
<div>    } <span style="color: #c586c0;">else</span></div>
<div>        <span style="color: #dcdcaa;">reservation_object_add_shared_replace</span>(obj, old, fobj, fence);</div>
<div>}</div>
<div><span style="color: #dcdcaa;">EXPORT_SYMBOL</span>(reservation_object_add_shared_fence);</div>
<div>

</div>
<div>

</div>
</div>
      </div>
      <hr style="display:inline-block;width:98%" tabindex="-1">
      <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
          face="Calibri, sans-serif" color="#000000"><b>From:</b> Chris
          Wilson <a class="moz-txt-link-rfc2396E" href="mailto:chris@chris-wilson.co.uk"><chris@chris-wilson.co.uk></a><br>
          <b>Sent:</b> Tuesday, March 6, 2018 6:10:21 PM<br>
          <b>To:</b> Liu, Monk; <a class="moz-txt-link-abbreviated" href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a>; Koenig,
          Christian<br>
          <b>Subject:</b> Re: reservation questions</font>
        <div> </div>
      </div>
      <div class="BodyFragment"><font size="2"><span
            style="font-size:11pt;">
            <div class="PlainText">Quoting Liu, Monk (2018-03-06
              09:45:19)<br>
              > call reservation_object_add_excl_fence,<br>
              > it set obj->fence->shared_count to 0, and put
              all shared fence from obj->fence<br>
              > without waiting signaling.<br>
              > (this action looks inappropriate, I think at least
              before put all those shared<br>
              > fences<br>
              > we should dma_wait_fence() on them to make sure they
              are signaled)<br>
              <br>
              No. Serialisation of resv updates are handled by the
              caller, the fences<br>
              are ordered asynchronously so the wait is implicit in the
              construction.<br>
              (I.e. before the excl fence can be signaled, all of the
              earlier shared<br>
              fences must be signaled. You can even say before the
              operation that the<br>
              excl fence signals completion of can begin, all the shared
              fences must<br>
              have been signaled. But that is all implicit so that we
              can do it<br>
              asynchronously.)<br>
              <br>
              > call reservation_object_reserve_shared,<br>
              > this time obj->staged isn't NULL, and it is freed
              (nothing bad now<br>
              > since obj->fence points to other place),<br>
              > and obj->staged set to NULL,<br>
              > <br>
              > call reservation_object_add_shared_fence,<br>
              > this time should going through
              reservation_object_add_shared_inplace,<br>
              > But BUG_ON(old->shared_count >=
              old->shared_max) will hit !<br>
              <br>
              How? You only free staged iff shared_count <
              shared_max.<br>
              <br>
              You've reminded me that we should cover all this with a
              bunch of<br>
              selftests.<br>
              -Chris<br>
            </div>
          </span></font></div>
    </blockquote>
    <br>
  </body>
</html>