]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915: Immediately execute the fenced work
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 25 Mar 2020 12:02:27 +0000 (12:02 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Wed, 25 Mar 2020 13:05:04 +0000 (13:05 +0000)
If the caller allows and we do not have to wait for any signals,
immediately execute the work within the caller's process. By doing so we
avoid the overhead of scheduling a new task, and the latency in
executing it, at the cost of pulling that work back into the immediate
context. (Sometimes we still prefer to offload the task to another cpu,
especially if we plan on executing many such tasks in parallel for this
client.)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200325120227.8044-2-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
drivers/gpu/drm/i915/i915_sw_fence_work.c
drivers/gpu/drm/i915/i915_sw_fence_work.h
drivers/gpu/drm/i915/i915_vma.c

index 6b3013d20851bdeac2548142e843d7f3bda8843f..c643eec4dca0f81e05d0c99ab99f140a90032bec 100644 (file)
@@ -1822,7 +1822,7 @@ static int eb_parse_pipeline(struct i915_execbuffer *eb,
        dma_resv_add_excl_fence(shadow->resv, &pw->base.dma);
        dma_resv_unlock(shadow->resv);
 
-       dma_fence_work_commit(&pw->base);
+       dma_fence_work_commit_imm(&pw->base);
        return 0;
 
 err_batch_unlock:
index 997b2998f1f2158ea53e4b202f55154ecce5cbb4..a3a81bb8f2c36ffb97bb2b99ad4510ffbdc7258a 100644 (file)
@@ -38,7 +38,10 @@ fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
 
                if (!f->dma.error) {
                        dma_fence_get(&f->dma);
-                       queue_work(system_unbound_wq, &f->work);
+                       if (test_bit(DMA_FENCE_WORK_IMM, &f->dma.flags))
+                               fence_work(&f->work);
+                       else
+                               queue_work(system_unbound_wq, &f->work);
                } else {
                        fence_complete(f);
                }
index 3a22b287e2019129a7379929a912f5cc3c87455e..2c409f11c5c5979931ba119e8044e8db0c460888 100644 (file)
@@ -32,6 +32,10 @@ struct dma_fence_work {
        const struct dma_fence_work_ops *ops;
 };
 
+enum {
+       DMA_FENCE_WORK_IMM = DMA_FENCE_FLAG_USER_BITS,
+};
+
 void dma_fence_work_init(struct dma_fence_work *f,
                         const struct dma_fence_work_ops *ops);
 int dma_fence_work_chain(struct dma_fence_work *f, struct dma_fence *signal);
@@ -41,4 +45,23 @@ static inline void dma_fence_work_commit(struct dma_fence_work *f)
        i915_sw_fence_commit(&f->chain);
 }
 
+/**
+ * dma_fence_work_commit_imm: Commit the fence, and if possible execute locally.
+ * @f: the fenced worker
+ *
+ * Instead of always scheduling a worker to execute the callback (see
+ * dma_fence_work_commit()), we try to execute the callback immediately in
+ * the local context. It is required that the fence be committed before it
+ * is published, and that no other threads try to tamper with the number
+ * of asynchronous waits on the fence (or else the callback will be
+ * executed in the wrong context, i.e. not the callers).
+ */
+static inline void dma_fence_work_commit_imm(struct dma_fence_work *f)
+{
+       if (atomic_read(&f->chain.pending) <= 1)
+               __set_bit(DMA_FENCE_WORK_IMM, &f->dma.flags);
+
+       dma_fence_work_commit(f);
+}
+
 #endif /* I915_SW_FENCE_WORK_H */
index 08699fa069aa6f5e8b1f4b34b98b87f12fe1cfe8..191577a983900f1f75608c978272e0fcf7d115bb 100644 (file)
@@ -980,7 +980,7 @@ err_unlock:
        mutex_unlock(&vma->vm->mutex);
 err_fence:
        if (work)
-               dma_fence_work_commit(&work->base);
+               dma_fence_work_commit_imm(&work->base);
        if (wakeref)
                intel_runtime_pm_put(&vma->vm->i915->runtime_pm, wakeref);
 err_pages: