public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 07/27] drm/i915: Coordinate i915_active with its own mutex
Date: Fri, 27 Sep 2019 13:08:51 +0100	[thread overview]
Message-ID: <85a5f7de-3837-3017-cb20-23258a61075f@linux.intel.com> (raw)
In-Reply-To: <156958352829.32596.13199670465422748570@skylake-alporthouse-com>


On 27/09/2019 12:25, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2019-09-27 12:10:29)
>>
>> On 25/09/2019 11:01, Chris Wilson wrote:
>>>    void i915_active_set_exclusive(struct i915_active *ref, struct dma_fence *f)
>>>    {
>>>        /* We expect the caller to manage the exclusive timeline ordering */
>>>        GEM_BUG_ON(i915_active_is_idle(ref));
>>>    
>>> -     dma_fence_get(f);
>>> -
>>> -     rcu_read_lock();
>>> -     if (rcu_access_pointer(ref->excl)) {
>>> -             struct dma_fence *old;
>>> -
>>> -             old = dma_fence_get_rcu_safe(&ref->excl);
>>> -             if (old) {
>>> -                     if (dma_fence_remove_callback(old, &ref->excl_cb))
>>> -                             atomic_dec(&ref->count);
>>> -                     dma_fence_put(old);
>>> -             }
>>> -     }
>>> -     rcu_read_unlock();
>>> -
>>> -     atomic_inc(&ref->count);
>>> -     rcu_assign_pointer(ref->excl, f);
>>> +     mutex_acquire(&ref->mutex.dep_map, 0, 0, _THIS_IP_);
>>> +     if (!__i915_active_fence_set(&ref->excl, f))
>>> +             atomic_inc(&ref->count);
>>> +     mutex_release(&ref->mutex.dep_map, 0, _THIS_IP_);
>>
>> Comment for this block please to explain what's going on.
> 
> This was meant to be clued in by the opening comment that the caller is
> expected to manage the exclusive timeline. But since the
> i915_active_fence debug API requires us to declare what mutex guards
> each timeline, we had to fake one.

I think the commentary about duality of which mutex guards things is 
only present in the commit message at the moment and it would be really 
good to have that somewhere in the code as well. Because after a few 
months of refactoring, going from git blame to commits can stop working 
so well, and then in code commentary becomes very valuable.

>>> +struct dma_fence *
>>> +__i915_active_fence_set(struct i915_active_fence *active,
>>> +                     struct dma_fence *fence)
>>
>> Can you add a short comment for this function explaining the racyness
>> and so why it returns prev and what should the callers do with it?
> 
> Before using this function, we had the callers declare what mutex guards
> this timeline and we check here that is held.

No, I mean because it has to reload prev and return it to the caller, 
which implies that is to handle some designed-in racy-ness which I think 
should be mentioned.

> 
>>> +{
>>> +     struct dma_fence *prev;
>>> +     unsigned long flags;
>>> +
>>> +     /* NB: updates must be serialised by an outer timeline mutex */
>>
>> Can't check here?
> 
> We do, see active_is_held()

Ack!

>>> +     spin_lock_irqsave(fence->lock, flags);
>>> +     GEM_BUG_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags));
>>> +
>>> +     prev = rcu_dereference_protected(active->fence, active_is_held(active));
>>> +     if (prev) {
>>> +             spin_lock_nested(prev->lock, SINGLE_DEPTH_NESTING);
>>> +             __list_del_entry(&active->cb.node);
>>> +             spin_unlock(prev->lock); /* serialise with prev->cb_list */
>>> +             prev = rcu_access_pointer(active->fence);
>>>        }
>>> +
>>> +     rcu_assign_pointer(active->fence, fence);
>>> +     list_add_tail(&active->cb.node, &fence->cb_list);
>>> +
>>> +     spin_unlock_irqrestore(fence->lock, flags);
>>> +
>>> +     return prev;
>>>    }
>>>    
>>> -int i915_active_request_set(struct i915_active_request *active,
>>> -                         struct i915_request *rq)
>>> +int i915_active_fence_set(struct i915_active_fence *active,
>>> +                       struct i915_request *rq)
>>>    {
>>> +     struct dma_fence *fence;
>>>        int err;
>>>    
>>>    #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
>>
>> Here not in diff we actually have:
>>
>> #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
>>          lockdep_assert_held(active->lock);
>>
>> So why only under GEM debug and how does it related to the NB comment in
>> __i915_active_fence_set?
> 
> We only expand the struct when we want to for debugging.

Missed that detail, ok.

Regards,

Tvrtko


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-09-27 12:08 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 10:01 struct_mutex is over the hill and far away Chris Wilson
2019-09-25 10:01 ` [PATCH 01/27] dma-fence: Serialise signal enabling (dma_fence_enable_sw_signaling) Chris Wilson
2019-09-25 10:01 ` [PATCH 02/27] drm/mm: Pack allocated/scanned boolean into a bitfield Chris Wilson
2019-09-25 10:01 ` [PATCH 03/27] drm/i915: Only track bound elements of the GTT Chris Wilson
2019-09-25 10:01 ` [PATCH 04/27] drm/i915: Mark up address spaces that may need to allocate Chris Wilson
2019-09-25 10:01 ` [PATCH 05/27] drm/i915: Pull i915_vma_pin under the vm->mutex Chris Wilson
2019-09-27  8:47   ` Tvrtko Ursulin
2019-09-27 11:06     ` Chris Wilson
2019-09-25 10:01 ` [PATCH 06/27] drm/i915: Push the i915_active.retire into a worker Chris Wilson
2019-09-25 10:01 ` [PATCH 07/27] drm/i915: Coordinate i915_active with its own mutex Chris Wilson
2019-09-27 11:10   ` Tvrtko Ursulin
2019-09-27 11:25     ` Chris Wilson
2019-09-27 12:08       ` Tvrtko Ursulin [this message]
2019-09-27 12:16         ` Chris Wilson
2019-09-27 12:25           ` Tvrtko Ursulin
2019-09-27 12:32             ` Chris Wilson
2019-09-27 13:58               ` Tvrtko Ursulin
2019-09-27 14:10                 ` Chris Wilson
2019-09-25 10:01 ` [PATCH 08/27] drm/i915: Move idle barrier cleanup into engine-pm Chris Wilson
2019-09-25 10:01 ` [PATCH 09/27] drm/i915: Drop struct_mutex from around i915_retire_requests() Chris Wilson
2019-09-25 10:01 ` [PATCH 10/27] drm/i915: Remove the GEM idle worker Chris Wilson
2019-09-25 10:01 ` [PATCH 11/27] drm/i915: Merge wait_for_timelines with retire_request Chris Wilson
2019-09-25 10:47   ` Tvrtko Ursulin
2019-09-25 10:54     ` Chris Wilson
2019-09-25 10:01 ` [PATCH 12/27] drm/i915: Move request runtime management onto gt Chris Wilson
2019-09-25 10:57   ` Tvrtko Ursulin
2019-09-25 11:17     ` Chris Wilson
2019-09-25 11:24       ` Chris Wilson
2019-09-25 11:29         ` Chris Wilson
2019-09-25 11:33           ` Chris Wilson
2019-09-25 15:17             ` Tvrtko Ursulin
2019-09-25 10:01 ` [PATCH 13/27] drm/i915: Move global activity tracking from GEM to GT Chris Wilson
2019-09-25 10:01 ` [PATCH 14/27] drm/i915: Expose engine properties via sysfs Chris Wilson
2019-09-27 20:48   ` Rodrigo Vivi
2019-09-25 10:01 ` [PATCH 15/27] drm/i915/execlists: Force preemption Chris Wilson
2019-09-25 10:01 ` [PATCH 16/27] drm/i915: Mark up "sentinel" requests Chris Wilson
2019-09-25 10:01 ` [PATCH 17/27] drm/i915/execlists: Cancel banned contexts on schedule-out Chris Wilson
2019-09-25 10:01 ` [PATCH 18/27] drm/i915: Cancel non-persistent contexts on close Chris Wilson
2019-09-25 10:01 ` [PATCH 19/27] drm/i915: Replace hangcheck by heartbeats Chris Wilson
2019-09-27  8:26   ` Joonas Lahtinen
2019-09-27  9:18     ` Chris Wilson
2019-09-25 10:01 ` [PATCH 20/27] drm/i915: Remove logical HW ID Chris Wilson
2019-09-25 12:41   ` Tvrtko Ursulin
2019-09-25 12:51     ` Chris Wilson
2019-09-25 14:38       ` Tvrtko Ursulin
2019-09-25 17:59     ` Daniele Ceraolo Spurio
2019-09-25 18:23       ` Matthew Brost
2019-09-25 10:01 ` [PATCH 21/27] drm/i915: Move context management under GEM Chris Wilson
2019-09-26 13:57   ` Tvrtko Ursulin
2019-10-02 16:09     ` Tvrtko Ursulin
2019-10-03  7:35     ` Chris Wilson
2019-09-25 10:01 ` [PATCH 22/27] drm/i915/overlay: Drop struct_mutex guard Chris Wilson
2019-09-25 12:43   ` Tvrtko Ursulin
2019-09-25 12:53     ` Chris Wilson
2019-09-25 13:01       ` Tvrtko Ursulin
2019-09-25 13:11         ` Chris Wilson
2019-09-25 10:01 ` [PATCH 23/27] drm/i915: Drop struct_mutex guard from debugfs/framebuffer_info Chris Wilson
2019-09-25 12:45   ` Tvrtko Ursulin
2019-09-25 10:01 ` [PATCH 24/27] drm/i915: Remove struct_mutex guard for debugfs/opregion Chris Wilson
2019-09-25 12:51   ` Tvrtko Ursulin
2019-09-25 10:01 ` [PATCH 25/27] drm/i915: Drop struct_mutex from suspend state save/restore Chris Wilson
2019-09-25 12:52   ` Tvrtko Ursulin
2019-09-25 10:01 ` [PATCH 26/27] drm/i915/selftests: Drop vestigal struct_mutex guards Chris Wilson
2019-09-25 12:55   ` Tvrtko Ursulin
2019-09-25 10:01 ` [PATCH 27/27] drm/i915: Drop struct_mutex from around GEM initialisation Chris Wilson
2019-09-25 12:56   ` Tvrtko Ursulin
2019-09-25 10:21 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/27] dma-fence: Serialise signal enabling (dma_fence_enable_sw_signaling) Patchwork
2019-09-25 10:34 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-09-25 10:51 ` ✓ Fi.CI.BAT: success " Patchwork
2019-09-26  0:56 ` ✗ Fi.CI.IGT: failure " 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=85a5f7de-3837-3017-cb20-23258a61075f@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox