<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 15.02.19 um 17:49 schrieb Jason
      Ekstrand:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAOFGe96HUkzHPJKYT-07X3vMvCRD-=Hba1=Ke24qt_PY2vn0YQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Fri, Feb 15, 2019 at 9:52
            AM Lionel Landwerlin via dri-devel <<a
              href="mailto:dri-devel@lists.freedesktop.org"
              moz-do-not-send="true">dri-devel@lists.freedesktop.org</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">On 15/02/2019 14:32,
            Koenig, Christian wrote:<br>
            > Am 15.02.19 um 15:23 schrieb Lionel Landwerlin:<br>
            >> Hi Christian, David,<br>
            >><br>
            >> For timeline semaphore we need points to signaled
            in order.<br>
            >> I'm struggling to understand how this fence-chain
            implementation<br>
            >> preserves ordering of the seqnos.<br>
            >><br>
            >> One of the scenario I can see an issue happening is
            when you have a<br>
            >> timeline with points 1 & 2 and userspace
            submits for 2 different<br>
            >> engines :<br>
            >>      - first with let's say a blitter style engine
            on point 2<br>
            >>      - then a 3d style engine on point 1<br>
            > Yeah, and where exactly is the problem?<br>
            ><br>
            > Seqno 1 will signal when the 3d style engine finishes
            work.<br>
            ><br>
            > And seqno 2 will signal when both seqno 1 is signaled
            and the blitter<br>
            > style engine has finished its work.<br>
          </blockquote>
          <div><br>
          </div>
          <div>That's an interesting interpretation of the spec.  I
            think it's legal and I could see that behavior may be
            desirable in some ways.<br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Well we actually had this discussion multiple times now, both
    internally as well as on the mailing list. Please also see the
    previous mails with Daniel on this topic.<br>
    <br>
    My initial suggestion was actually to exactly what Leonid suggested
    as well.<br>
    <br>
    And following this I used a rather simple container for the
    implementation, e.g. just a ring buffer indexed by the sequence
    number. In this scenario userspace can specify on syncobj creation
    time how big the window for sequence numbers should be, e.g. in this
    implementation how big the ring buffer would be.<br>
    <br>
    This was rejected by our guys who actually wrote a good part of the
    Vulkan specification. Daniel then has gone into the same direction
    during the public discussion.<br>
    <br>
    [SNIP]<br>
    <blockquote type="cite"
cite="mid:CAOFGe96HUkzHPJKYT-07X3vMvCRD-=Hba1=Ke24qt_PY2vn0YQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div>I think what Christian is suggesting is a valid
            interpretation of the spec though it is rather
            unconventional.  The Vulkan spec, as it stands today,
            requires that the application ensure that at the time of
            signaling, the timeline semaphore value increases.  This
            means that all of the above possible cases are technically
            illegal in Vulkan and so it doesn't really matter what we do
            as long as we don't do anyting especially stupid.</div>
        </div>
      </div>
    </blockquote>
    <br>
    And exactly that's the point. When an application does something
    stupid with its own submissions then this is not much of a problem.<br>
    <br>
    But this interface is meant to be made for communication between
    processes, and here we want to be sure that nobody can do anything
    stupid.<br>
    <br>
    <blockquote type="cite"
cite="mid:CAOFGe96HUkzHPJKYT-07X3vMvCRD-=Hba1=Ke24qt_PY2vn0YQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div>My understanding of how this works on Windows is that a
            wait operation on 3 is a wait until x >= 3 where x is a
            64-bit value and a signal operation is simply a write to x. 
            This means that, in the above cases, waits on 1 will be
            triggered immediately when 2 is written but waits on 2 may
            or may not happen at all depending on whether the GPU write
            which overwrites x to 1 or the CPU (or potentially GPU in a
            different context) read gets there first such that the
            reader observes 2.  If you mess this up and something isn't
            signaled, that's your fault.</div>
        </div>
      </div>
    </blockquote>
    <br>
    Yeah and I think that this is actually not a good idea at all.
    Implementing it like this ultimately means that you can only use
    polling on the number.<br>
    <br>
    <blockquote type="cite"
cite="mid:CAOFGe96HUkzHPJKYT-07X3vMvCRD-=Hba1=Ke24qt_PY2vn0YQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div> 4. If you do get into a sticky situation, you can
            unblock an entire timeline by using the CPU signal ioctl to
            set it to a high value. <br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Well I think that this could be problematic as well. Keep in mind
    that main use case for this is sharing timelines between processes.<br>
    <br>
    In other words you don't want applications to be able to mess with
    it to much.<br>
    <br>
    <blockquote type="cite"
cite="mid:CAOFGe96HUkzHPJKYT-07X3vMvCRD-=Hba1=Ke24qt_PY2vn0YQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div><br>
          </div>
          <div>Of all these reasons, I think 1 and 2 carry the most
            weight.  2, in particular, is interesting if we one day want
            to implement the same behavior with a simple 64-bit value
            like Windows does.  Immagine, for instance, a scenario where
            the GPU is doing it's own scheduling or command buffers are
            submitted ahead of the signal operation being available and
            told to just sit on the GPU until they see x >= 3.  (Yes,
            there are issues here with residency, contention, etc.  I'm
            asking you to use your immagination.)  Assuming you can do
            64-bit atomics (there are aparently issues here with PCIe
            that make things sticky), the behavior I'm suggesting is
            completely implementable in that way whereas the behavior
            Christian is suggesting is only implementable if you're
            maintaining a CPU-side list of fences.  I don't think we
            want to paint ourselves into that corner.</div>
        </div>
      </div>
    </blockquote>
    <br>
    Actually we already had such an implementation with radeon. And I
    can only say that it was a totally PAIN IN THE A* to maintain.<br>
    <br>
    This is one of the reason why we are not using hardware semaphores
    any more with amdgpu.<br>
    <br>
    Regards,<br>
    Christian.<br>
    <br>
    <blockquote type="cite"
cite="mid:CAOFGe96HUkzHPJKYT-07X3vMvCRD-=Hba1=Ke24qt_PY2vn0YQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div><br>
          </div>
          <div>--Jason<br>
          </div>
          <div> </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">
            ><br>
            > Regards,<br>
            > Christian.<br>
            ><br>
            >> -Lionel<br>
            >><br>
            >> On 07/12/2018 09:55, Chunming Zhou wrote:<br>
            >>> From: Christian König <<a
              href="mailto:ckoenig.leichtzumerken@gmail.com"
              target="_blank" moz-do-not-send="true">ckoenig.leichtzumerken@gmail.com</a>><br>
            >>><br>
            >>> Lockless container implementation similar to a
            dma_fence_array, but with<br>
            >>> only two elements per node and automatic
            garbage collection.<br>
            >>><br>
            >>> v2: properly document dma_fence_chain_for_each,
            add<br>
            >>> dma_fence_chain_find_seqno,<br>
            >>>       drop prev reference during garbage
            collection if it's not a<br>
            >>> chain fence.<br>
            >>> v3: use head and iterator for
            dma_fence_chain_for_each<br>
            >>> v4: fix reference count in
            dma_fence_chain_enable_signaling<br>
            >>><br>
            >>> Signed-off-by: Christian König <<a
              href="mailto:christian.koenig@amd.com" target="_blank"
              moz-do-not-send="true">christian.koenig@amd.com</a>><br>
            >>> ---<br>
            >>>    drivers/dma-buf/Makefile          |   3 +-<br>
            >>>    drivers/dma-buf/dma-fence-chain.c | 241
            ++++++++++++++++++++++++++++++<br>
            >>>    include/linux/dma-fence-chain.h   |  81
            ++++++++++<br>
            >>>    3 files changed, 324 insertions(+), 1
            deletion(-)<br>
            >>>    create mode 100644
            drivers/dma-buf/dma-fence-chain.c<br>
            >>>    create mode 100644
            include/linux/dma-fence-chain.h<br>
            >>><br>
            >>> diff --git a/drivers/dma-buf/Makefile
            b/drivers/dma-buf/Makefile<br>
            >>> index 0913a6ccab5a..1f006e083eb9 100644<br>
            >>> --- a/drivers/dma-buf/Makefile<br>
            >>> +++ b/drivers/dma-buf/Makefile<br>
            >>> @@ -1,4 +1,5 @@<br>
            >>> -obj-y := dma-buf.o dma-fence.o
            dma-fence-array.o reservation.o<br>
            >>> seqno-fence.o<br>
            >>> +obj-y := dma-buf.o dma-fence.o
            dma-fence-array.o dma-fence-chain.o \<br>
            >>> +     reservation.o seqno-fence.o<br>
            >>>    obj-$(CONFIG_SYNC_FILE)        +=
            sync_file.o<br>
            >>>    obj-$(CONFIG_SW_SYNC)        += sw_sync.o
            sync_debug.o<br>
            >>>    obj-$(CONFIG_UDMABUF)        += udmabuf.o<br>
            >>> diff --git a/drivers/dma-buf/dma-fence-chain.c<br>
            >>> b/drivers/dma-buf/dma-fence-chain.c<br>
            >>> new file mode 100644<br>
            >>> index 000000000000..0c5e3c902fa0<br>
            >>> --- /dev/null<br>
            >>> +++ b/drivers/dma-buf/dma-fence-chain.c<br>
            >>> @@ -0,0 +1,241 @@<br>
            >>> +/*<br>
            >>> + * fence-chain: chain fences together in a
            timeline<br>
            >>> + *<br>
            >>> + * Copyright (C) 2018 Advanced Micro Devices,
            Inc.<br>
            >>> + * Authors:<br>
            >>> + *    Christian König <<a
              href="mailto:christian.koenig@amd.com" target="_blank"
              moz-do-not-send="true">christian.koenig@amd.com</a>><br>
            >>> + *<br>
            >>> + * This program is free software; you can
            redistribute it and/or<br>
            >>> modify it<br>
            >>> + * under the terms of the GNU General Public
            License version 2 as<br>
            >>> published by<br>
            >>> + * the Free Software Foundation.<br>
            >>> + *<br>
            >>> + * This program is distributed in the hope
            that it will be useful,<br>
            >>> but WITHOUT<br>
            >>> + * ANY WARRANTY; without even the implied
            warranty of<br>
            >>> MERCHANTABILITY or<br>
            >>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public<br>
            >>> License for<br>
            >>> + * more details.<br>
            >>> + */<br>
            >>> +<br>
            >>> +#include <linux/dma-fence-chain.h><br>
            >>> +<br>
            >>> +static bool
            dma_fence_chain_enable_signaling(struct dma_fence *fence);<br>
            >>> +<br>
            >>> +/**<br>
            >>> + * dma_fence_chain_get_prev - use RCU to get a
            reference to the<br>
            >>> previous fence<br>
            >>> + * @chain: chain node to get the previous node
            from<br>
            >>> + *<br>
            >>> + * Use dma_fence_get_rcu_safe to get a
            reference to the previous<br>
            >>> fence of the<br>
            >>> + * chain node.<br>
            >>> + */<br>
            >>> +static struct dma_fence
            *dma_fence_chain_get_prev(struct<br>
            >>> dma_fence_chain *chain)<br>
            >>> +{<br>
            >>> +    struct dma_fence *prev;<br>
            >>> +<br>
            >>> +    rcu_read_lock();<br>
            >>> +    prev =
            dma_fence_get_rcu_safe(&chain->prev);<br>
            >>> +    rcu_read_unlock();<br>
            >>> +    return prev;<br>
            >>> +}<br>
            >>> +<br>
            >>> +/**<br>
            >>> + * dma_fence_chain_walk - chain walking
            function<br>
            >>> + * @fence: current chain node<br>
            >>> + *<br>
            >>> + * Walk the chain to the next node. Returns
            the next fence or NULL<br>
            >>> if we are at<br>
            >>> + * the end of the chain. Garbage collects
            chain nodes which are already<br>
            >>> + * signaled.<br>
            >>> + */<br>
            >>> +struct dma_fence *dma_fence_chain_walk(struct
            dma_fence *fence)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *chain,
            *prev_chain;<br>
            >>> +    struct dma_fence *prev, *replacement,
            *tmp;<br>
            >>> +<br>
            >>> +    chain = to_dma_fence_chain(fence);<br>
            >>> +    if (!chain) {<br>
            >>> +        dma_fence_put(fence);<br>
            >>> +        return NULL;<br>
            >>> +    }<br>
            >>> +<br>
            >>> +    while ((prev =
            dma_fence_chain_get_prev(chain))) {<br>
            >>> +<br>
            >>> +        prev_chain = to_dma_fence_chain(prev);<br>
            >>> +        if (prev_chain) {<br>
            >>> +            if
            (!dma_fence_is_signaled(prev_chain->fence))<br>
            >>> +                break;<br>
            >>> +<br>
            >>> +            replacement =
            dma_fence_chain_get_prev(prev_chain);<br>
            >>> +        } else {<br>
            >>> +            if (!dma_fence_is_signaled(prev))<br>
            >>> +                break;<br>
            >>> +<br>
            >>> +            replacement = NULL;<br>
            >>> +        }<br>
            >>> +<br>
            >>> +        tmp = cmpxchg(&chain->prev,
            prev, replacement);<br>
            >>> +        if (tmp == prev)<br>
            >>> +            dma_fence_put(tmp);<br>
            >>> +        else<br>
            >>> +            dma_fence_put(replacement);<br>
            >>> +        dma_fence_put(prev);<br>
            >>> +    }<br>
            >>> +<br>
            >>> +    dma_fence_put(fence);<br>
            >>> +    return prev;<br>
            >>> +}<br>
            >>> +EXPORT_SYMBOL(dma_fence_chain_walk);<br>
            >>> +<br>
            >>> +/**<br>
            >>> + * dma_fence_chain_find_seqno - find fence
            chain node by seqno<br>
            >>> + * @pfence: pointer to the chain node where to
            start<br>
            >>> + * @seqno: the sequence number to search for<br>
            >>> + *<br>
            >>> + * Advance the fence pointer to the chain node
            which will signal<br>
            >>> this sequence<br>
            >>> + * number. If no sequence number is provided
            then this is a no-op.<br>
            >>> + *<br>
            >>> + * Returns EINVAL if the fence is not a chain
            node or the sequence<br>
            >>> number has<br>
            >>> + * not yet advanced far enough.<br>
            >>> + */<br>
            >>> +int dma_fence_chain_find_seqno(struct
            dma_fence **pfence, uint64_t<br>
            >>> seqno)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *chain;<br>
            >>> +<br>
            >>> +    if (!seqno)<br>
            >>> +        return 0;<br>
            >>> +<br>
            >>> +    chain = to_dma_fence_chain(*pfence);<br>
            >>> +    if (!chain || chain->base.seqno <
            seqno)<br>
            >>> +        return -EINVAL;<br>
            >>> +<br>
            >>> +    dma_fence_chain_for_each(*pfence,
            &chain->base) {<br>
            >>> +        if ((*pfence)->context !=
            chain->base.context ||<br>
            >>> +           
            to_dma_fence_chain(*pfence)->prev_seqno < seqno)<br>
            >>> +            break;<br>
            >>> +    }<br>
            >>> +    dma_fence_put(&chain->base);<br>
            >>> +<br>
            >>> +    return 0;<br>
            >>> +}<br>
            >>> +EXPORT_SYMBOL(dma_fence_chain_find_seqno);<br>
            >>> +<br>
            >>> +static const char
            *dma_fence_chain_get_driver_name(struct dma_fence<br>
            >>> *fence)<br>
            >>> +{<br>
            >>> +        return "dma_fence_chain";<br>
            >>> +}<br>
            >>> +<br>
            >>> +static const char
            *dma_fence_chain_get_timeline_name(struct<br>
            >>> dma_fence *fence)<br>
            >>> +{<br>
            >>> +        return "unbound";<br>
            >>> +}<br>
            >>> +<br>
            >>> +static void dma_fence_chain_irq_work(struct
            irq_work *work)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *chain;<br>
            >>> +<br>
            >>> +    chain = container_of(work, typeof(*chain),
            work);<br>
            >>> +<br>
            >>> +    /* Try to rearm the callback */<br>
            >>> +    if
            (!dma_fence_chain_enable_signaling(&chain->base))<br>
            >>> +        /* Ok, we are done. No more unsignaled
            fences left */<br>
            >>> +        dma_fence_signal(&chain->base);<br>
            >>> +    dma_fence_put(&chain->base);<br>
            >>> +}<br>
            >>> +<br>
            >>> +static void dma_fence_chain_cb(struct
            dma_fence *f, struct<br>
            >>> dma_fence_cb *cb)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *chain;<br>
            >>> +<br>
            >>> +    chain = container_of(cb, typeof(*chain),
            cb);<br>
            >>> +    irq_work_queue(&chain->work);<br>
            >>> +    dma_fence_put(f);<br>
            >>> +}<br>
            >>> +<br>
            >>> +static bool
            dma_fence_chain_enable_signaling(struct dma_fence *fence)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *head =
            to_dma_fence_chain(fence);<br>
            >>> +<br>
            >>> +    dma_fence_get(&head->base);<br>
            >>> +    dma_fence_chain_for_each(fence,
            &head->base) {<br>
            >>> +        struct dma_fence_chain *chain =
            to_dma_fence_chain(fence);<br>
            >>> +        struct dma_fence *f = chain ?
            chain->fence : fence;<br>
            >>> +<br>
            >>> +        dma_fence_get(f);<br>
            >>> +        if (!dma_fence_add_callback(f,
            &head->cb,<br>
            >>> dma_fence_chain_cb)) {<br>
            >>> +            dma_fence_put(fence);<br>
            >>> +            return true;<br>
            >>> +        }<br>
            >>> +        dma_fence_put(f);<br>
            >>> +    }<br>
            >>> +    dma_fence_put(&head->base);<br>
            >>> +    return false;<br>
            >>> +}<br>
            >>> +<br>
            >>> +static bool dma_fence_chain_signaled(struct
            dma_fence *fence)<br>
            >>> +{<br>
            >>> +    dma_fence_chain_for_each(fence, fence) {<br>
            >>> +        struct dma_fence_chain *chain =
            to_dma_fence_chain(fence);<br>
            >>> +        struct dma_fence *f = chain ?
            chain->fence : fence;<br>
            >>> +<br>
            >>> +        if (!dma_fence_is_signaled(f)) {<br>
            >>> +            dma_fence_put(fence);<br>
            >>> +            return false;<br>
            >>> +        }<br>
            >>> +    }<br>
            >>> +<br>
            >>> +    return true;<br>
            >>> +}<br>
            >>> +<br>
            >>> +static void dma_fence_chain_release(struct
            dma_fence *fence)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *chain =
            to_dma_fence_chain(fence);<br>
            >>> +<br>
            >>> +    dma_fence_put(chain->prev);<br>
            >>> +    dma_fence_put(chain->fence);<br>
            >>> +    dma_fence_free(fence);<br>
            >>> +}<br>
            >>> +<br>
            >>> +const struct dma_fence_ops dma_fence_chain_ops
            = {<br>
            >>> +    .get_driver_name =
            dma_fence_chain_get_driver_name,<br>
            >>> +    .get_timeline_name =
            dma_fence_chain_get_timeline_name,<br>
            >>> +    .enable_signaling =
            dma_fence_chain_enable_signaling,<br>
            >>> +    .signaled = dma_fence_chain_signaled,<br>
            >>> +    .release = dma_fence_chain_release,<br>
            >>> +};<br>
            >>> +EXPORT_SYMBOL(dma_fence_chain_ops);<br>
            >>> +<br>
            >>> +/**<br>
            >>> + * dma_fence_chain_init - initialize a fence
            chain<br>
            >>> + * @chain: the chain node to initialize<br>
            >>> + * @prev: the previous fence<br>
            >>> + * @fence: the current fence<br>
            >>> + *<br>
            >>> + * Initialize a new chain node and either
            start a new chain or add<br>
            >>> the node to<br>
            >>> + * the existing chain of the previous fence.<br>
            >>> + */<br>
            >>> +void dma_fence_chain_init(struct
            dma_fence_chain *chain,<br>
            >>> +              struct dma_fence *prev,<br>
            >>> +              struct dma_fence *fence,<br>
            >>> +              uint64_t seqno)<br>
            >>> +{<br>
            >>> +    struct dma_fence_chain *prev_chain =
            to_dma_fence_chain(prev);<br>
            >>> +    uint64_t context;<br>
            >>> +<br>
            >>> +    spin_lock_init(&chain->lock);<br>
            >>> +    chain->prev = prev;<br>
            >>> +    chain->fence = fence;<br>
            >>> +    chain->prev_seqno = 0;<br>
            >>> +    init_irq_work(&chain->work,
            dma_fence_chain_irq_work);<br>
            >>> +<br>
            >>> +    /* Try to reuse the context of the
            previous chain node. */<br>
            >>> +    if (prev_chain &&
            __dma_fence_is_later(seqno, prev->seqno)) {<br>
            >>> +        context = prev->context;<br>
            >>> +        chain->prev_seqno = prev->seqno;<br>
            >>> +    } else {<br>
            >>> +        context = dma_fence_context_alloc(1);<br>
            >>> +        /* Make sure that we always have a
            valid sequence number. */<br>
            >>> +        if (prev_chain)<br>
            >>> +            seqno = max(prev->seqno,
            seqno);<br>
            >>> +    }<br>
            >>> +<br>
            >>> +    dma_fence_init(&chain->base,
            &dma_fence_chain_ops,<br>
            >>> +               &chain->lock, context,
            seqno);<br>
            >>> +}<br>
            >>> +EXPORT_SYMBOL(dma_fence_chain_init);<br>
            >>> diff --git a/include/linux/dma-fence-chain.h<br>
            >>> b/include/linux/dma-fence-chain.h<br>
            >>> new file mode 100644<br>
            >>> index 000000000000..a5c2e8c6915c<br>
            >>> --- /dev/null<br>
            >>> +++ b/include/linux/dma-fence-chain.h<br>
            >>> @@ -0,0 +1,81 @@<br>
            >>> +/*<br>
            >>> + * fence-chain: chain fences together in a
            timeline<br>
            >>> + *<br>
            >>> + * Copyright (C) 2018 Advanced Micro Devices,
            Inc.<br>
            >>> + * Authors:<br>
            >>> + *    Christian König <<a
              href="mailto:christian.koenig@amd.com" target="_blank"
              moz-do-not-send="true">christian.koenig@amd.com</a>><br>
            >>> + *<br>
            >>> + * This program is free software; you can
            redistribute it and/or<br>
            >>> modify it<br>
            >>> + * under the terms of the GNU General Public
            License version 2 as<br>
            >>> published by<br>
            >>> + * the Free Software Foundation.<br>
            >>> + *<br>
            >>> + * This program is distributed in the hope
            that it will be useful,<br>
            >>> but WITHOUT<br>
            >>> + * ANY WARRANTY; without even the implied
            warranty of<br>
            >>> MERCHANTABILITY or<br>
            >>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public<br>
            >>> License for<br>
            >>> + * more details.<br>
            >>> + */<br>
            >>> +<br>
            >>> +#ifndef __LINUX_DMA_FENCE_CHAIN_H<br>
            >>> +#define __LINUX_DMA_FENCE_CHAIN_H<br>
            >>> +<br>
            >>> +#include <linux/dma-fence.h><br>
            >>> +#include <linux/irq_work.h><br>
            >>> +<br>
            >>> +/**<br>
            >>> + * struct dma_fence_chain - fence to represent
            an node of a fence chain<br>
            >>> + * @base: fence base class<br>
            >>> + * @lock: spinlock for fence handling<br>
            >>> + * @prev: previous fence of the chain<br>
            >>> + * @prev_seqno: original previous seqno before
            garbage collection<br>
            >>> + * @fence: encapsulated fence<br>
            >>> + * @cb: callback structure for signaling<br>
            >>> + * @work: irq work item for signaling<br>
            >>> + */<br>
            >>> +struct dma_fence_chain {<br>
            >>> +    struct dma_fence base;<br>
            >>> +    spinlock_t lock;<br>
            >>> +    struct dma_fence *prev;<br>
            >>> +    u64 prev_seqno;<br>
            >>> +    struct dma_fence *fence;<br>
            >>> +    struct dma_fence_cb cb;<br>
            >>> +    struct irq_work work;<br>
            >>> +};<br>
            >>> +<br>
            >>> +extern const struct dma_fence_ops
            dma_fence_chain_ops;<br>
            >>> +<br>
            >>> +/**<br>
            >>> + * to_dma_fence_chain - cast a fence to a
            dma_fence_chain<br>
            >>> + * @fence: fence to cast to a dma_fence_array<br>
            >>> + *<br>
            >>> + * Returns NULL if the fence is not a
            dma_fence_chain,<br>
            >>> + * or the dma_fence_chain otherwise.<br>
            >>> + */<br>
            >>> +static inline struct dma_fence_chain *<br>
            >>> +to_dma_fence_chain(struct dma_fence *fence)<br>
            >>> +{<br>
            >>> +    if (!fence || fence->ops !=
            &dma_fence_chain_ops)<br>
            >>> +        return NULL;<br>
            >>> +<br>
            >>> +    return container_of(fence, struct
            dma_fence_chain, base);<br>
            >>> +}<br>
            >>> +<br>
            >>> +/**<br>
            >>> + * dma_fence_chain_for_each - iterate over all
            fences in chain<br>
            >>> + * @iter: current fence<br>
            >>> + * @head: starting point<br>
            >>> + *<br>
            >>> + * Iterate over all fences in the chain. We
            keep a reference to the<br>
            >>> current<br>
            >>> + * fence while inside the loop which must be
            dropped when breaking out.<br>
            >>> + */<br>
            >>> +#define dma_fence_chain_for_each(iter,
            head)    \<br>
            >>> +    for (iter = dma_fence_get(head); iter; \<br>
            >>> +         iter = dma_fence_chain_walk(head))<br>
            >>> +<br>
            >>> +struct dma_fence *dma_fence_chain_walk(struct
            dma_fence *fence);<br>
            >>> +int dma_fence_chain_find_seqno(struct
            dma_fence **pfence, uint64_t<br>
            >>> seqno);<br>
            >>> +void dma_fence_chain_init(struct
            dma_fence_chain *chain,<br>
            >>> +              struct dma_fence *prev,<br>
            >>> +              struct dma_fence *fence,<br>
            >>> +              uint64_t seqno);<br>
            >>> +<br>
            >>> +#endif /* __LINUX_DMA_FENCE_CHAIN_H */<br>
            >><br>
            <br>
            _______________________________________________<br>
            dri-devel mailing list<br>
            <a href="mailto:dri-devel@lists.freedesktop.org"
              target="_blank" moz-do-not-send="true">dri-devel@lists.freedesktop.org</a><br>
            <a
              href="https://lists.freedesktop.org/mailman/listinfo/dri-devel"
              rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a></blockquote>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>