drm/fence: add fence to drm_pending_event
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Wed, 1 Jun 2016 22:06:35 +0000 (00:06 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 2 Jun 2016 22:01:59 +0000 (00:01 +0200)
Now a drm_pending_event can either send a real drm_event or signal a
fence, or both. It allow us to signal via fences when the buffer is
displayed on the screen. Which in turn means that the previous buffer
is not in use anymore and can be freed or sent back to another driver
for processing.

v2: Comments from Daniel Vetter
- call fence_signal in drm_send_event_locked()
- remove unneeded !e->event check

v3: Remove drm_pending_event->destroy to fix a leak when e->file_priv
is not set.

Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk> (v2)
[danvet: fix one e->destroy in arcpgu due to rebasing.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1464818821-5736-13-git-send-email-daniel.vetter@ffwll.ch
drivers/gpu/drm/arc/arcpgu_drv.c
drivers/gpu/drm/drm_atomic.c
drivers/gpu/drm/drm_fops.c
drivers/gpu/drm/nouveau/nouveau_usif.c
drivers/gpu/drm/rockchip/rockchip_drm_vop.c
include/drm/drmP.h

index 76e187a..69b5be0 100644 (file)
@@ -92,7 +92,7 @@ static void arcpgu_preclose(struct drm_device *drm, struct drm_file *file)
                if (e->base.file_priv != file)
                        continue;
                list_del(&e->base.link);
-               e->base.destroy(&e->base);
+               kfree(&e->base);
        }
        spin_unlock_irqrestore(&drm->event_lock, flags);
 }
index 674b2e4..1db198d 100644 (file)
@@ -1412,7 +1412,8 @@ EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
  */
 
 static struct drm_pending_vblank_event *create_vblank_event(
-               struct drm_device *dev, struct drm_file *file_priv, uint64_t user_data)
+               struct drm_device *dev, struct drm_file *file_priv,
+               struct fence *fence, uint64_t user_data)
 {
        struct drm_pending_vblank_event *e = NULL;
        int ret;
@@ -1425,12 +1426,17 @@ static struct drm_pending_vblank_event *create_vblank_event(
        e->event.base.length = sizeof(e->event);
        e->event.user_data = user_data;
 
-       ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base);
-       if (ret) {
-               kfree(e);
-               return NULL;
+       if (file_priv) {
+               ret = drm_event_reserve_init(dev, file_priv, &e->base,
+                                            &e->event.base);
+               if (ret) {
+                       kfree(e);
+                       return NULL;
+               }
        }
 
+       e->base.fence = fence;
+
        return e;
 }
 
@@ -1670,7 +1676,8 @@ retry:
                for_each_crtc_in_state(state, crtc, crtc_state, i) {
                        struct drm_pending_vblank_event *e;
 
-                       e = create_vblank_event(dev, file_priv, arg->user_data);
+                       e = create_vblank_event(dev, file_priv, NULL,
+                                               arg->user_data);
                        if (!e) {
                                ret = -ENOMEM;
                                goto out;
index 7af7f8b..efa980a 100644 (file)
@@ -368,7 +368,7 @@ static void drm_events_release(struct drm_file *file_priv)
        /* Remove unconsumed events */
        list_for_each_entry_safe(e, et, &file_priv->event_list, link) {
                list_del(&e->link);
-               e->destroy(e);
+               kfree(e);
        }
 
        spin_unlock_irqrestore(&dev->event_lock, flags);
@@ -636,7 +636,7 @@ put_back_event:
                        }
 
                        ret += length;
-                       e->destroy(e);
+                       kfree(e);
                }
        }
        mutex_unlock(&file_priv->event_read_lock);
@@ -713,9 +713,6 @@ int drm_event_reserve_init_locked(struct drm_device *dev,
        list_add(&p->pending_link, &file_priv->pending_event_list);
        p->file_priv = file_priv;
 
-       /* we *could* pass this in as arg, but everyone uses kfree: */
-       p->destroy = (void (*) (struct drm_pending_event *)) kfree;
-
        return 0;
 }
 EXPORT_SYMBOL(drm_event_reserve_init_locked);
@@ -778,7 +775,7 @@ void drm_event_cancel_free(struct drm_device *dev,
                list_del(&p->pending_link);
        }
        spin_unlock_irqrestore(&dev->event_lock, flags);
-       p->destroy(p);
+       kfree(p);
 }
 EXPORT_SYMBOL(drm_event_cancel_free);
 
@@ -800,8 +797,13 @@ void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e)
 {
        assert_spin_locked(&dev->event_lock);
 
+       if (e->fence) {
+               fence_signal(e->fence);
+               fence_put(e->fence);
+       }
+
        if (!e->file_priv) {
-               e->destroy(e);
+               kfree(e);
                return;
        }
 
index 675e9e0..08f9c6f 100644 (file)
@@ -212,7 +212,6 @@ usif_notify_get(struct drm_file *f, void *data, u32 size, void *argv, u32 argc)
        ntfy->p->base.event = &ntfy->p->e.base;
        ntfy->p->base.file_priv = f;
        ntfy->p->base.pid = current->pid;
-       ntfy->p->base.destroy =(void(*)(struct drm_pending_event *))kfree;
        ntfy->p->e.base.type = DRM_NOUVEAU_EVENT_NVIF;
        ntfy->p->e.base.length = sizeof(ntfy->p->e.base) + ntfy->reply;
 
index 1c4d5b5..5567fb4 100644 (file)
@@ -889,7 +889,7 @@ static void vop_crtc_cancel_pending_vblank(struct drm_crtc *crtc,
        if (e && e->base.file_priv == file_priv) {
                vop->event = NULL;
 
-               e->base.destroy(&e->base);
+               kfree(&e->base);
                file_priv->event_space += sizeof(e->event);
        }
        spin_unlock_irqrestore(&drm->event_lock, flags);
index 0051828..9e5eefd 100644 (file)
@@ -57,6 +57,7 @@
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <linux/workqueue.h>
+#include <linux/fence.h>
 
 #include <asm/mman.h>
 #include <asm/pgalloc.h>
@@ -283,12 +284,12 @@ struct drm_ioctl_desc {
 /* Event queued up for userspace to read */
 struct drm_pending_event {
        struct drm_event *event;
+       struct fence *fence;
        struct list_head link;
        struct list_head pending_link;
        struct drm_file *file_priv;
        pid_t pid; /* pid of requester, no guarantee it's valid by the time
                      we deliver the event, for tracing only */
-       void (*destroy)(struct drm_pending_event *event);
 };
 
 /* initial implementaton using a linked list - todo hashtab */