drm/i915: Make engine's batch pool safe for use with virtual engines
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 27 Aug 2019 13:59:35 +0000 (14:59 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Tue, 27 Aug 2019 15:42:12 +0000 (16:42 +0100)
A virtual engine itself does not have a batch pool, but we can gleefully
use any of its siblings instead.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190827135935.3831-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c
drivers/gpu/drm/i915/gt/intel_engine_pool.c
drivers/gpu/drm/i915/gt/intel_engine_pool.h
drivers/gpu/drm/i915/gt/intel_lrc.c
drivers/gpu/drm/i915/gt/intel_lrc.h

index f813fcb8ceb6e9eac389a7a46168f68a60180039..5a2238d444237704a1419208fde2921410891f7e 100644 (file)
@@ -1145,7 +1145,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,
        u32 *cmd;
        int err;
 
-       pool = intel_engine_pool_get(&eb->engine->pool, PAGE_SIZE);
+       pool = intel_engine_get_pool(eb->engine, PAGE_SIZE);
        if (IS_ERR(pool))
                return PTR_ERR(pool);
 
@@ -1963,7 +1963,7 @@ static struct i915_vma *eb_parse(struct i915_execbuffer *eb, bool is_master)
        struct i915_vma *vma;
        int err;
 
-       pool = intel_engine_pool_get(&eb->engine->pool, eb->batch_len);
+       pool = intel_engine_get_pool(eb->engine, eb->batch_len);
        if (IS_ERR(pool))
                return ERR_CAST(pool);
 
index 6415f9a17e2d569922ab4036d6ce6f6f34fa702a..5bd8de124d74db6d8167c139e57440c0d61e6bc6 100644 (file)
@@ -32,7 +32,7 @@ struct i915_vma *intel_emit_vma_fill_blt(struct intel_context *ce,
        count = div_u64(vma->size, block_size);
        size = (1 + 8 * count) * sizeof(u32);
        size = round_up(size, PAGE_SIZE);
-       pool = intel_engine_pool_get(&ce->engine->pool, size);
+       pool = intel_engine_get_pool(ce->engine, size);
        if (IS_ERR(pool)) {
                err = PTR_ERR(pool);
                goto out_pm;
@@ -216,7 +216,7 @@ struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce,
        count = div_u64(dst->size, block_size);
        size = (1 + 11 * count) * sizeof(u32);
        size = round_up(size, PAGE_SIZE);
-       pool = intel_engine_pool_get(&ce->engine->pool, size);
+       pool = intel_engine_get_pool(ce->engine, size);
        if (IS_ERR(pool)) {
                err = PTR_ERR(pool);
                goto out_pm;
index 4cd54c5699111673793a076cb820a9e49336c689..97d36cca8ded1fd8f3ee9675f9899bda213c8e4a 100644 (file)
@@ -107,9 +107,19 @@ node_create(struct intel_engine_pool *pool, size_t sz)
        return node;
 }
 
+static struct intel_engine_pool *lookup_pool(struct intel_engine_cs *engine)
+{
+       if (intel_engine_is_virtual(engine))
+               engine = intel_virtual_engine_get_sibling(engine, 0);
+
+       GEM_BUG_ON(!engine);
+       return &engine->pool;
+}
+
 struct intel_engine_pool_node *
-intel_engine_pool_get(struct intel_engine_pool *pool, size_t size)
+intel_engine_get_pool(struct intel_engine_cs *engine, size_t size)
 {
+       struct intel_engine_pool *pool = lookup_pool(engine);
        struct intel_engine_pool_node *node;
        struct list_head *list;
        unsigned long flags;
index 8d069efd9457600c8d232994de84a08c6d932284..7e2123b335949bc4fc95d95b1eebe98175571f51 100644 (file)
@@ -12,7 +12,7 @@
 #include "i915_request.h"
 
 struct intel_engine_pool_node *
-intel_engine_pool_get(struct intel_engine_pool *pool, size_t size);
+intel_engine_get_pool(struct intel_engine_cs *engine, size_t size);
 
 static inline int
 intel_engine_pool_mark_active(struct intel_engine_pool_node *node,
index d42584439f515336641f08105f481912d0131239..cfbdcca76ff06788b84ad2bd25bc0b81c45f2982 100644 (file)
@@ -3851,6 +3851,18 @@ int intel_virtual_engine_attach_bond(struct intel_engine_cs *engine,
        return 0;
 }
 
+struct intel_engine_cs *
+intel_virtual_engine_get_sibling(struct intel_engine_cs *engine,
+                                unsigned int sibling)
+{
+       struct virtual_engine *ve = to_virtual_engine(engine);
+
+       if (sibling >= ve->num_siblings)
+               return NULL;
+
+       return ve->siblings[sibling];
+}
+
 void intel_execlists_show_requests(struct intel_engine_cs *engine,
                                   struct drm_printer *m,
                                   void (*show_request)(struct drm_printer *m,
index c2bba82bcc16a42259aca92900be69fda4327adb..dc0252e0589e4d2ef964f6e0752d7c4b3af93a2f 100644 (file)
@@ -131,4 +131,8 @@ int intel_virtual_engine_attach_bond(struct intel_engine_cs *engine,
                                     const struct intel_engine_cs *master,
                                     const struct intel_engine_cs *sibling);
 
+struct intel_engine_cs *
+intel_virtual_engine_get_sibling(struct intel_engine_cs *engine,
+                                unsigned int sibling);
+
 #endif /* _INTEL_LRC_H_ */