All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	DRI mailing list <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 3/3] dma-fence: Introduce drm_fence_set_error() helper
Date: Mon, 9 Jan 2017 14:56:50 +0000	[thread overview]
Message-ID: <20170109145650.GY19067@nuc-i3427.alporthouse.com> (raw)
In-Reply-To: <CAO_48GEAO=k4zdEkxjK1iVnRsT3c_enAmKV4CVk15=qhe9o4EA@mail.gmail.com>

On Mon, Jan 09, 2017 at 08:13:11PM +0530, Sumit Semwal wrote:
> Hi Chris,
> 
> On 4 January 2017 at 19:42, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > The dma_fence.error field (formerly known as dma_fence.status) is an
> > optional field that may be set by drivers before calling
> > dma_fence_signal(). The field can be used to indicate that the fence was
> > completed in err rather than with success, and is visible to other
> > consumers of the fence and to userspace via sync_file.
> >
> > This patch renames the field from status to error so that its meaning is
> > hopefully more clear (and distinct from dma_fence_get_status() which is
> > a composite between the error state and signal state) and adds a helper
> > that validates the preconditions of when it is suitable to adjust the
> > error field.
> >
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> >  drivers/dma-buf/dma-fence.c |  2 +-
> >  include/linux/dma-fence.h   | 30 +++++++++++++++++++++++++-----
> >  2 files changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> > index 7d936d19e659..ee82f36cb25e 100644
> > --- a/drivers/dma-buf/dma-fence.c
> > +++ b/drivers/dma-buf/dma-fence.c
> > @@ -559,7 +559,7 @@ dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
> >         fence->context = context;
> >         fence->seqno = seqno;
> >         fence->flags = 0UL;
> > -       fence->status = 0;
> > +       fence->error = 0;
> >
> >         trace_dma_fence_init(fence);
> >  }
> > diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
> > index 19f7af905182..6048fa404e57 100644
> > --- a/include/linux/dma-fence.h
> > +++ b/include/linux/dma-fence.h
> > @@ -47,7 +47,7 @@ struct dma_fence_cb;
> >   * can be compared to decide which fence would be signaled later.
> >   * @flags: A mask of DMA_FENCE_FLAG_* defined below
> >   * @timestamp: Timestamp when the fence was signaled.
> > - * @status: Optional, only valid if < 0, must be set before calling
> > + * @error: Optional, only valid if < 0, must be set before calling
> >   * dma_fence_signal, indicates that the fence has completed with an error.
> >   *
> >   * the flags member must be manipulated and read using the appropriate
> > @@ -79,7 +79,7 @@ struct dma_fence {
> >         unsigned seqno;
> >         unsigned long flags;
> >         ktime_t timestamp;
> > -       int status;
> > +       int error;
> >  };
> >
> >  enum dma_fence_flag_bits {
> > @@ -133,7 +133,7 @@ struct dma_fence_cb {
> >   * or some failure occurred that made it impossible to enable
> >   * signaling. True indicates successful enabling.
> >   *
> > - * fence->status may be set in enable_signaling, but only when false is
> > + * fence->error may be set in enable_signaling, but only when false is
> >   * returned.
> >   *
> >   * Calling dma_fence_signal before enable_signaling is called allows
> > @@ -145,7 +145,7 @@ struct dma_fence_cb {
> >   * the second time will be a noop since it was already signaled.
> >   *
> >   * Notes on signaled:
> > - * May set fence->status if returning true.
> > + * May set fence->error if returning true.
> >   *
> >   * Notes on wait:
> >   * Must not be NULL, set to dma_fence_default_wait for default implementation.
> > @@ -395,13 +395,33 @@ static inline struct dma_fence *dma_fence_later(struct dma_fence *f1,
> >  static inline int dma_fence_get_status_locked(struct dma_fence *fence)
> >  {
> >         if (dma_fence_is_signaled_locked(fence))
> > -               return fence->status < 0 ? fence->status : 1;
> > +               return fence->error ?: 1;
> >         else
> >                 return 0;
> >  }
> >
> >  int dma_fence_get_status(struct dma_fence *fence);
> >
> > +/**
> > + * dma_fence_set_error - flag an error condition on the fence
> > + * @fence: [in]        the dma_fence
> > + * @error: [in]        the error to store
> > + *
> > + * Drivers can supply an optional error status condition before they signal
> > + * the fence, to indicate that the fence was completed due to an error
> > + * rather than success. This must be set before signaling (so that the value
> > + * is visible before any waiters on the signal callback are woken). This
> > + * helper exists to help catching erroneous setting of #dma_fence.error.
> > + */
> > +static inline void dma_fence_set_error(struct dma_fence *fence,
> > +                                      int error)
> > +{
> > +       BUG_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags));
> > +       BUG_ON(error >= 0 || error < -MAX_ERRNO);
> > +
> > +       fence->error = error;
> > +}
> Sorry I missed this earlier, but are you sure you want to use a BUG_ON
> here, and not a WARN_ON?

Given that it is a void return, there's nowhere for the warning to go.
The second is a definite programming error and should hopefully be
eliminated at compiletime, but writing it as a BUILD_BUG or
__builtin_constant_p may not work - BUILD_BUG_ON(error...) happens to
work for my code. If you want to use

-       BUG_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags));
-       BUG_ON(error >= 0 || error < -MAX_ERRNO);
+       BUILD_BUG_ON(error >= 0 || error < -MAX_ERRNO);
+       WARN_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags));
 
and have a softlockup instead, be my guest.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-01-09 14:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-04 14:12 [PATCH 1/3] dma-fence: Clear fence->status during dma_fence_init() Chris Wilson
2017-01-04 14:12 ` [PATCH 2/3] dma-fence: Wrap querying the fence->status Chris Wilson
2017-01-04 14:12 ` [PATCH 3/3] dma-fence: Introduce drm_fence_set_error() helper Chris Wilson
2017-01-09 14:43   ` Sumit Semwal
2017-01-09 14:56     ` Chris Wilson [this message]
2017-01-04 15:10 ` [PATCH 1/3] dma-fence: Clear fence->status during dma_fence_init() Daniel Vetter
2017-01-04 15:53   ` Sumit Semwal
2017-01-06 14:32     ` Chris Wilson
2017-01-04 15:16 ` ✗ Fi.CI.BAT: warning for series starting with [1/3] " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170109145650.GY19067@nuc-i3427.alporthouse.com \
    --to=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=sumit.semwal@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.