[PATCH 6/6] dma-buf: add poll support, v2 (original) (raw)
Rob Clark robdclark at gmail.com
Mon Feb 17 08:38:17 PST 2014
- Previous message: [PATCH 6/6] dma-buf: add poll support, v2
- Next message: [Bug 75102] New: Radeon 4890 getting a blank screen and fans go up to 100% (kernel 3.13.3)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Feb 17, 2014 at 10:58 AM, Maarten Lankhorst <maarten.lankhorst at canonical.com> wrote:
Thanks to Fengguang Wu for spotting a missing static cast.
v2: - Kill unused variable needshared. Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com> --- drivers/base/dma-buf.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 12 ++++++ 2 files changed, 113 insertions(+) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 85e792c2c909..77ea621ab59d 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -30,6 +30,7 @@ #include <linux/export.h> #include <linux/debugfs.h> #include <linux/seqfile.h> +#include <linux/poll.h> #include <linux/reservation.h> static inline int isdmabuffile(struct file *); @@ -52,6 +53,13 @@ static int dmabufrelease(struct inode *inode, struct file *file) BUGON(dmabuf->vmappingcounter); + /* + * Any fences that a dma-buf poll can wait on should be signaled + * before releasing dma-buf. This is the responsibility of each + * driver that uses the reservation objects.
minor nit.. but wouldn't hurt to mention in the comment that if you hit this BUG_ON it is because someone isn't holding a ref to the dmabuf while there is a pending fence
+ */ + BUGON(dmabuf->cbshared.active || dmabuf->cbexcl.active); + dmabuf->ops->release(dmabuf);
mutexlock(&dblist.lock); @@ -108,10 +116,99 @@ static lofft dmabufllseek(struct file *file, lofft offset, int whence) return base + offset; } +static void dmabufpollcb(struct fence *fence, struct fencecb *cb) +{ + struct dmabufpollcbt dcb = (struct dmabufpollcbt) cb; + unsigned long flags; + + spinlockirqsave(&dcb->poll->lock, flags); + wakeuplockedpoll(dcb->poll, dcb->active); + dcb->active = 0; + spinunlockirqrestore(&dcb->poll->lock, flags); +} + +static unsigned int dmabufpoll(struct file *file, polltable *poll) +{ + struct dmabuf *dmabuf; + struct reservationobject *resv; + unsigned long events; + + dmabuf = file->privatedata; + if (!dmabuf || !dmabuf->resv) + return POLLERR; + + resv = dmabuf->resv; + + pollwait(file, &dmabuf->poll, poll); + + events = pollrequestedevents(poll) & (POLLIN | POLLOUT); + if (!events) + return 0; + + wwmutexlock(&resv->lock, NULL); + + if (resv->fenceexcl && (!(events & POLLOUT) || resv->fencesharedcount == 0)) { + struct dmabufpollcbt *dcb = &dmabuf->cbexcl; + unsigned long pevents = POLLIN; + + if (resv->fencesharedcount == 0) + pevents |= POLLOUT; + + spinlockirq(&dmabuf->poll.lock); + if (dcb->active) { + dcb->active |= pevents; + events &= ~pevents; + } else + dcb->active = pevents; + spinunlockirq(&dmabuf->poll.lock); + + if (events & pevents) { + if (!fenceaddcallback(resv->fenceexcl, + &dcb->cb, dmabufpollcb)) + events &= ~pevents; + else + // No callback queued, wake up any additional waiters.
couple spots w/ c++ comments, which I assume you didn't mean to leave?
Anyways, other than those minor things,
Reviewed-by: Rob Clark <robdclark at gmail.com>
+ dmabufpollcb(NULL, &dcb->cb); + } + } + + if ((events & POLLOUT) && resv->fencesharedcount > 0) { + struct dmabufpollcbt *dcb = &dmabuf->cbshared; + int i; + + /* Only queue a new callback if no event has fired yet */ + spinlockirq(&dmabuf->poll.lock); + if (dcb->active) + events &= ~POLLOUT; + else + dcb->active = POLLOUT; + spinunlockirq(&dmabuf->poll.lock); + + if (!(events & POLLOUT)) + goto out; + + for (i = 0; i < resv->fencesharedcount; ++i) + if (!fenceaddcallback(resv->fenceshared[i], + &dcb->cb, dmabufpollcb)) { + events &= ~POLLOUT; + break; + } + + // No callback queued, wake up any additional waiters. + if (i == resv->fencesharedcount) + dmabufpollcb(NULL, &dcb->cb); + } + +out: + wwmutexunlock(&resv->lock); + return events; +} + static const struct fileoperations dmabuffops = { .release = dmabufrelease, .mmap = dmabufmmapinternal, .llseek = dmabufllseek, + .poll = dmabufpoll, };
/* @@ -171,6 +268,10 @@ struct dmabuf *dmabufexportnamed(void *priv, const struct dmabufops *ops, dmabuf->ops = ops; dmabuf->size = size; dmabuf->expname = expname; + initwaitqueuehead(&dmabuf->poll); + dmabuf->cbexcl.poll = dmabuf->cbshared.poll = &dmabuf->poll; + dmabuf->cbexcl.active = dmabuf->cbshared.active = 0; + if (!resv) { resv = (struct reservationobject*)&dmabuf[1]; reservationobjectinit(resv); diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 34cfbac52c03..e1df18f584ef 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -30,6 +30,8 @@ #include <linux/list.h> #include <linux/dma-mapping.h> #include <linux/fs.h> +#include <linux/fence.h> +#include <linux/wait.h> struct device; struct dmabuf; @@ -130,6 +132,16 @@ struct dmabuf { struct listhead listnode; void *priv; struct reservationobject *resv; + + /* poll support */ + waitqueueheadt poll; + + struct dmabufpollcbt { + struct fencecb cb; + waitqueueheadt *poll; + + unsigned long active; + } cbexcl, cbshared; }; /**
- Previous message: [PATCH 6/6] dma-buf: add poll support, v2
- Next message: [Bug 75102] New: Radeon 4890 getting a blank screen and fans go up to 100% (kernel 3.13.3)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]