Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/linux i915: Defer destroying request l...



details:   https://anonhg.NetBSD.org/src/rev/e2e756afacab
branches:  trunk
changeset: 1028781:e2e756afacab
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 12:00:48 2021 +0000

description:
i915: Defer destroying request lock and fence until page destruction.

diffstat:

 sys/external/bsd/common/include/linux/slab.h       |  35 +++++++++++++++++++++-
 sys/external/bsd/drm2/dist/drm/i915/i915_request.c |  23 ++++++++-----
 sys/external/bsd/drm2/include/linux/dma-fence.h    |   5 ++-
 sys/external/bsd/drm2/linux/linux_dma_fence.c      |  32 ++++++++++++++++++-
 4 files changed, 82 insertions(+), 13 deletions(-)

diffs (225 lines):

diff -r 839e3a539671 -r e2e756afacab sys/external/bsd/common/include/linux/slab.h
--- a/sys/external/bsd/common/include/linux/slab.h      Sun Dec 19 12:00:40 2021 +0000
+++ b/sys/external/bsd/common/include/linux/slab.h      Sun Dec 19 12:00:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: slab.h,v 1.6 2021/12/19 11:58:09 riastradh Exp $       */
+/*     $NetBSD: slab.h,v 1.7 2021/12/19 12:00:48 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -137,6 +137,7 @@
        pool_cache_t    kc_pool_cache;
        size_t          kc_size;
        void            (*kc_ctor)(void *);
+       void            (*kc_dtor)(void *);
 };
 
 /* XXX These should be in <sys/pool.h>.  */
@@ -168,6 +169,15 @@
        return 0;
 }
 
+static void
+kmem_cache_dtor(void *cookie, void *ptr)
+{
+       struct kmem_cache *const kc = cookie;
+
+       if (kc->kc_dtor)
+               (*kc->kc_dtor)(ptr);
+}
+
 static inline struct kmem_cache *
 kmem_cache_create(const char *name, size_t size, size_t align,
     unsigned long flags, void (*ctor)(void *))
@@ -189,6 +199,29 @@
        return kc;
 }
 
+/* XXX extension */
+static inline struct kmem_cache *
+kmem_cache_create_dtor(const char *name, size_t size, size_t align,
+    unsigned long flags, void (*ctor)(void *), void (*dtor)(void *))
+{
+       struct pool_allocator *palloc = NULL;
+       struct kmem_cache *kc;
+
+       if (ISSET(flags, SLAB_HWCACHE_ALIGN))
+               align = roundup(MAX(1, align), CACHE_LINE_SIZE);
+       if (ISSET(flags, SLAB_TYPESAFE_BY_RCU))
+               palloc = &pool_allocator_kmem_rcu;
+
+       kc = kmem_alloc(sizeof(*kc), KM_SLEEP);
+       kc->kc_pool_cache = pool_cache_init(size, align, 0, 0, name, palloc,
+           IPL_VM, &kmem_cache_ctor, &kmem_cache_dtor, kc);
+       kc->kc_size = size;
+       kc->kc_ctor = ctor;
+       kc->kc_dtor = dtor;
+
+       return kc;
+}
+
 #define        KMEM_CACHE(T, F)                                                      \
        kmem_cache_create(#T, sizeof(struct T), __alignof__(struct T),        \
            (F), NULL)
diff -r 839e3a539671 -r e2e756afacab sys/external/bsd/drm2/dist/drm/i915/i915_request.c
--- a/sys/external/bsd/drm2/dist/drm/i915/i915_request.c        Sun Dec 19 12:00:40 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/i915_request.c        Sun Dec 19 12:00:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_request.c,v 1.8 2021/12/19 12:00:40 riastradh Exp $       */
+/*     $NetBSD: i915_request.c,v 1.9 2021/12/19 12:00:48 riastradh Exp $       */
 
 /*
  * Copyright © 2008-2015 Intel Corporation
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_request.c,v 1.8 2021/12/19 12:00:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_request.c,v 1.9 2021/12/19 12:00:48 riastradh Exp $");
 
 #include <linux/dma-fence-array.h>
 #include <linux/irq_work.h>
@@ -121,8 +121,6 @@
        i915_sw_fence_fini(&rq->submit);
        i915_sw_fence_fini(&rq->semaphore);
 
-       dma_fence_destroy(&rq->fence);
-       spin_lock_destroy(&rq->lock);
        kmem_cache_free(global.slab_requests, rq);
 }
 
@@ -602,9 +600,7 @@
        i915_sw_fence_init(&rq->submit, submit_notify);
        i915_sw_fence_init(&rq->semaphore, semaphore_notify);
 
-#ifndef __NetBSD__
        dma_fence_init(&rq->fence, &i915_fence_ops, &rq->lock, 0, 0);
-#endif
 
        rq->file_priv = NULL;
        rq->capture_list = NULL;
@@ -612,6 +608,14 @@
        INIT_LIST_HEAD(&rq->execute_cb);
 }
 
+static void __i915_request_dtor(void *arg)
+{
+       struct i915_request *rq = arg;
+
+       dma_fence_destroy(&rq->fence);
+       spin_lock_destroy(&rq->lock);
+}
+
 struct i915_request *
 __i915_request_create(struct intel_context *ce, gfp_t gfp)
 {
@@ -671,7 +675,7 @@
        rq->execution_mask = ce->engine->mask;
 
 #ifdef __NetBSD__
-       dma_fence_init(&rq->fence, &i915_fence_ops, &rq->lock, 0, 0);
+       dma_fence_reset(&rq->fence, &i915_fence_ops, &rq->lock, 0, 0);
 #else
        kref_init(&rq->fence.refcount);
        rq->fence.flags = 0;
@@ -1677,13 +1681,14 @@
 int __init i915_global_request_init(void)
 {
        global.slab_requests =
-               kmem_cache_create("i915_request",
+               kmem_cache_create_dtor("i915_request",
                                  sizeof(struct i915_request),
                                  __alignof__(struct i915_request),
                                  SLAB_HWCACHE_ALIGN |
                                  SLAB_RECLAIM_ACCOUNT |
                                  SLAB_TYPESAFE_BY_RCU,
-                                 __i915_request_ctor);
+                                 __i915_request_ctor,
+                                 __i915_request_dtor);
        if (!global.slab_requests)
                return -ENOMEM;
 
diff -r 839e3a539671 -r e2e756afacab sys/external/bsd/drm2/include/linux/dma-fence.h
--- a/sys/external/bsd/drm2/include/linux/dma-fence.h   Sun Dec 19 12:00:40 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/dma-fence.h   Sun Dec 19 12:00:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dma-fence.h,v 1.12 2021/12/19 11:03:57 riastradh Exp $ */
+/*     $NetBSD: dma-fence.h,v 1.13 2021/12/19 12:00:48 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -102,6 +102,7 @@
 #define        dma_fence_is_signaled_locked    linux_dma_fence_is_signaled_locked
 #define        dma_fence_put                   linux_dma_fence_put
 #define        dma_fence_remove_callback       linux_dma_fence_remove_callback
+#define        dma_fence_reset                 linux_dma_fence_reset
 #define        dma_fence_set_error             linux_dma_fence_set_error
 #define        dma_fence_signal                linux_dma_fence_signal
 #define        dma_fence_signal_locked         linux_dma_fence_signal_locked
@@ -113,6 +114,8 @@
 
 void   dma_fence_init(struct dma_fence *, const struct dma_fence_ops *,
            spinlock_t *, unsigned, unsigned);
+void   dma_fence_reset(struct dma_fence *, const struct dma_fence_ops *,
+           spinlock_t *, unsigned, unsigned); /* XXX extension */
 void   dma_fence_destroy(struct dma_fence *);
 void   dma_fence_free(struct dma_fence *);
 
diff -r 839e3a539671 -r e2e756afacab sys/external/bsd/drm2/linux/linux_dma_fence.c
--- a/sys/external/bsd/drm2/linux/linux_dma_fence.c     Sun Dec 19 12:00:40 2021 +0000
+++ b/sys/external/bsd/drm2/linux/linux_dma_fence.c     Sun Dec 19 12:00:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_dma_fence.c,v 1.17 2021/12/19 11:20:56 riastradh Exp $   */
+/*     $NetBSD: linux_dma_fence.c,v 1.18 2021/12/19 12:00:48 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.17 2021/12/19 11:20:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.18 2021/12/19 12:00:48 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/condvar.h>
@@ -83,11 +83,39 @@
        fence->context = context;
        fence->seqno = seqno;
        fence->ops = ops;
+       fence->error = 0;
        TAILQ_INIT(&fence->f_callbacks);
        cv_init(&fence->f_cv, "dmafence");
 }
 
 /*
+ * dma_fence_reset(fence)
+ *
+ *     Ensure fence is in a quiescent state.  Allowed either for newly
+ *     initialized or freed fences, but not fences with more than one
+ *     reference.
+ *
+ *     XXX extension to Linux API
+ */
+void
+dma_fence_reset(struct dma_fence *fence, const struct dma_fence_ops *ops,
+    spinlock_t *lock, unsigned context, unsigned seqno)
+{
+
+       KASSERT(kref_read(&fence->refcount) == 0 ||
+           kref_read(&fence->refcount) == 1);
+       KASSERT(TAILQ_EMPTY(&fence->f_callbacks));
+       KASSERT(fence->lock == lock);
+       KASSERT(fence->ops == ops);
+
+       kref_init(&fence->refcount);
+       fence->flags = 0;
+       fence->context = context;
+       fence->seqno = seqno;
+       fence->error = 0;
+}
+
+/*
  * dma_fence_destroy(fence)
  *
  *     Clean up memory initialized with dma_fence_init.  This is meant



Home | Main Index | Thread Index | Old Index