diff mbox

[3/3] drm: Factor-out drm_emit_vblank_event code.

Message ID 1303884659-739-3-git-send-email-christopher.halse.rogers@canonical.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christopher James Halse Rogers April 27, 2011, 6:10 a.m. UTC
From: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
---
 drivers/gpu/drm/drm_irq.c |   39 ++++++++++++++++-----------------------
 1 files changed, 16 insertions(+), 23 deletions(-)

Comments

Michel Dänzer April 27, 2011, 8:36 a.m. UTC | #1
On Mit, 2011-04-27 at 16:10 +1000, christopher.halse.rogers@canonical.com wrote:
> From: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> 
> Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> ---
>  drivers/gpu/drm/drm_irq.c |   39 ++++++++++++++++-----------------------
>  1 files changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 72407fa..485714b 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -930,6 +930,18 @@ void drm_vblank_put(struct drm_device *dev, int crtc)
>  }
>  EXPORT_SYMBOL(drm_vblank_put);
>  
> +static void drm_emit_vblank_event (struct drm_pending_vblank_event *e,
> +				   unsigned int seq, struct timeval *now)
> +{
> +	e->event.sequence = seq;
> +	e->event.tv_sec = now->tv_sec;
> +	e->event.tv_usec = now->tv_usec;
> +	list_move_tail(&e->base.link, &e->base.file_priv->event_list);
> +	wake_up_interruptible(&e->base.file_priv->event_wait);
> +	trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
> +					 e->event.sequence);
> +}
> +
>  void drm_vblank_off(struct drm_device *dev, int crtc)
>  {
>  	struct drm_pending_vblank_event *e, *t;
> @@ -950,14 +962,8 @@ void drm_vblank_off(struct drm_device *dev, int crtc)
>  			  wanted %d, current %d\n",
>  			  e->event.sequence, seq);
>  
> -		e->event.sequence = seq;
> -		e->event.tv_sec = now.tv_sec;
> -		e->event.tv_usec = now.tv_usec;
>  		drm_vblank_put(dev, e->pipe);
> -		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
> -		wake_up_interruptible(&e->base.file_priv->event_wait);
> -		trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
> -						 e->event.sequence);
> +		drm_emit_vblank_event(e, seq, &now);
>  	}

Makes sense, but shouldn't the drm_vblank_put() calls move into
drm_emit_vblank_event() as well?
Christopher James Halse Rogers April 27, 2011, 8:48 a.m. UTC | #2
On Wed, 2011-04-27 at 10:36 +0200, Michel Dänzer wrote:
> On Mit, 2011-04-27 at 16:10 +1000, christopher.halse.rogers@canonical.com wrote:
> > From: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> > 
> > Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> > ---
> >  drivers/gpu/drm/drm_irq.c |   39 ++++++++++++++++-----------------------
> >  1 files changed, 16 insertions(+), 23 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> > index 72407fa..485714b 100644
> > --- a/drivers/gpu/drm/drm_irq.c
> > +++ b/drivers/gpu/drm/drm_irq.c
> > @@ -930,6 +930,18 @@ void drm_vblank_put(struct drm_device *dev, int crtc)
> >  }
> >  EXPORT_SYMBOL(drm_vblank_put);
> >  
> > +static void drm_emit_vblank_event (struct drm_pending_vblank_event *e,
> > +				   unsigned int seq, struct timeval *now)
> > +{
> > +	e->event.sequence = seq;
> > +	e->event.tv_sec = now->tv_sec;
> > +	e->event.tv_usec = now->tv_usec;
> > +	list_move_tail(&e->base.link, &e->base.file_priv->event_list);
> > +	wake_up_interruptible(&e->base.file_priv->event_wait);
> > +	trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
> > +					 e->event.sequence);
> > +}
> > +
> >  void drm_vblank_off(struct drm_device *dev, int crtc)
> >  {
> >  	struct drm_pending_vblank_event *e, *t;
> > @@ -950,14 +962,8 @@ void drm_vblank_off(struct drm_device *dev, int crtc)
> >  			  wanted %d, current %d\n",
> >  			  e->event.sequence, seq);
> >  
> > -		e->event.sequence = seq;
> > -		e->event.tv_sec = now.tv_sec;
> > -		e->event.tv_usec = now.tv_usec;
> >  		drm_vblank_put(dev, e->pipe);
> > -		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
> > -		wake_up_interruptible(&e->base.file_priv->event_wait);
> > -		trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
> > -						 e->event.sequence);
> > +		drm_emit_vblank_event(e, seq, &now);
> >  	}
> 
> Makes sense, but shouldn't the drm_vblank_put() calls move into
> drm_emit_vblank_event() as well?

Possibly.  I felt that dropping the vblank reference was a conceptually
distinct action from emitting the vblank event, which is why I left it
out.  I'd be happy enough to have it as a part of drm_emit_vblank_event,
though.
Michel Dänzer April 27, 2011, 9:06 a.m. UTC | #3
On Mit, 2011-04-27 at 18:48 +1000, Christopher James Halse Rogers
wrote: 
> On Wed, 2011-04-27 at 10:36 +0200, Michel Dänzer wrote:
> > On Mit, 2011-04-27 at 16:10 +1000, christopher.halse.rogers@canonical.com wrote:
> > > From: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> > > 
> > > Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> > > ---
> > >  drivers/gpu/drm/drm_irq.c |   39 ++++++++++++++++-----------------------
> > >  1 files changed, 16 insertions(+), 23 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> > > index 72407fa..485714b 100644
> > > --- a/drivers/gpu/drm/drm_irq.c
> > > +++ b/drivers/gpu/drm/drm_irq.c
> > > @@ -930,6 +930,18 @@ void drm_vblank_put(struct drm_device *dev, int crtc)
> > >  }
> > >  EXPORT_SYMBOL(drm_vblank_put);
> > >  
> > > +static void drm_emit_vblank_event (struct drm_pending_vblank_event *e,
> > > +				   unsigned int seq, struct timeval *now)
> > > +{
> > > +	e->event.sequence = seq;
> > > +	e->event.tv_sec = now->tv_sec;
> > > +	e->event.tv_usec = now->tv_usec;
> > > +	list_move_tail(&e->base.link, &e->base.file_priv->event_list);
> > > +	wake_up_interruptible(&e->base.file_priv->event_wait);
> > > +	trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
> > > +					 e->event.sequence);
> > > +}
> > > +
> > >  void drm_vblank_off(struct drm_device *dev, int crtc)
> > >  {
> > >  	struct drm_pending_vblank_event *e, *t;
> > > @@ -950,14 +962,8 @@ void drm_vblank_off(struct drm_device *dev, int crtc)
> > >  			  wanted %d, current %d\n",
> > >  			  e->event.sequence, seq);
> > >  
> > > -		e->event.sequence = seq;
> > > -		e->event.tv_sec = now.tv_sec;
> > > -		e->event.tv_usec = now.tv_usec;
> > >  		drm_vblank_put(dev, e->pipe);
> > > -		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
> > > -		wake_up_interruptible(&e->base.file_priv->event_wait);
> > > -		trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
> > > -						 e->event.sequence);
> > > +		drm_emit_vblank_event(e, seq, &now);
> > >  	}
> > 
> > Makes sense, but shouldn't the drm_vblank_put() calls move into
> > drm_emit_vblank_event() as well?
> 
> Possibly.  I felt that dropping the vblank reference was a conceptually
> distinct action from emitting the vblank event, which is why I left it
> out.  I'd be happy enough to have it as a part of drm_emit_vblank_event,
> though.

I think they belong together, as the reference was taken for the pending
event.
Jesse Barnes April 28, 2011, 8:36 p.m. UTC | #4
On Wed, 27 Apr 2011 16:10:59 +1000
christopher.halse.rogers@canonical.com wrote:

> From: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> 
> Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
> ---
>  drivers/gpu/drm/drm_irq.c |   39 ++++++++++++++++-----------------------
>  1 files changed, 16 insertions(+), 23 deletions(-)
> 

Oh I see you already addressed my last comment. :)

I think Michel is right about the put; the event queue holds the ref
and the emit should drop it, so keeping them together seems good to me.

Other than that,
Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>

same for the first patch now that you've addressed my cleanup issue.
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 72407fa..485714b 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -930,6 +930,18 @@  void drm_vblank_put(struct drm_device *dev, int crtc)
 }
 EXPORT_SYMBOL(drm_vblank_put);
 
+static void drm_emit_vblank_event (struct drm_pending_vblank_event *e,
+				   unsigned int seq, struct timeval *now)
+{
+	e->event.sequence = seq;
+	e->event.tv_sec = now->tv_sec;
+	e->event.tv_usec = now->tv_usec;
+	list_move_tail(&e->base.link, &e->base.file_priv->event_list);
+	wake_up_interruptible(&e->base.file_priv->event_wait);
+	trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
+					 e->event.sequence);
+}
+
 void drm_vblank_off(struct drm_device *dev, int crtc)
 {
 	struct drm_pending_vblank_event *e, *t;
@@ -950,14 +962,8 @@  void drm_vblank_off(struct drm_device *dev, int crtc)
 			  wanted %d, current %d\n",
 			  e->event.sequence, seq);
 
-		e->event.sequence = seq;
-		e->event.tv_sec = now.tv_sec;
-		e->event.tv_usec = now.tv_usec;
 		drm_vblank_put(dev, e->pipe);
-		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
-		wake_up_interruptible(&e->base.file_priv->event_wait);
-		trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
-						 e->event.sequence);
+		drm_emit_vblank_event(e, seq, &now);
 	}
 
 	WARN_ON(atomic_read(&dev->vblank_refcount[crtc]) != 0);
@@ -1103,18 +1109,11 @@  static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
 				      vblwait->request.sequence);
 
 	e->event.sequence = vblwait->request.sequence;
+	list_add_tail(&e->base.link, &dev->vblank_event_list);
 	if ((seq - vblwait->request.sequence) <= (1 << 23)) {
-		e->event.sequence = seq;
-		e->event.tv_sec = now.tv_sec;
-		e->event.tv_usec = now.tv_usec;
 		drm_vblank_put(dev, pipe);
-		list_add_tail(&e->base.link, &e->base.file_priv->event_list);
-		wake_up_interruptible(&e->base.file_priv->event_wait);
-		vblwait->reply.sequence = seq;
-		trace_drm_vblank_event_delivered(current->pid, pipe,
-						 vblwait->request.sequence);
+		drm_emit_vblank_event(e, seq, &now);
 	} else {
-		list_add_tail(&e->base.link, &dev->vblank_event_list);
 		vblwait->reply.sequence = vblwait->request.sequence;
 	}
 
@@ -1248,14 +1247,8 @@  void drm_handle_vblank_events(struct drm_device *dev, int crtc)
 		DRM_DEBUG("vblank event on %d, current %d\n",
 			  e->event.sequence, seq);
 
-		e->event.sequence = seq;
-		e->event.tv_sec = now.tv_sec;
-		e->event.tv_usec = now.tv_usec;
 		drm_vblank_put(dev, e->pipe);
-		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
-		wake_up_interruptible(&e->base.file_priv->event_wait);
-		trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
-						 e->event.sequence);
+		drm_emit_vblank_event(e, seq, &now);
 	}
 
 	spin_unlock_irqrestore(&dev->event_lock, flags);