diff mbox

drm/via: use monotonic time for VIA_WAIT_IRQ

Message ID 20171127111728.1710742-1-arnd@arndb.de (mailing list archive)
State New, archived
Headers show

Commit Message

Arnd Bergmann Nov. 27, 2017, 11:17 a.m. UTC
The normal DRM vblank interrupt events started using monotonic times in
commit c61eef726a78 ("drm: add support for monotonic vblank timestamps"),
which is useful for a number of reasons, including the possible y2038
overflow.

The VIA_WAIT_IRQ ioctl uses the same drm_wait_vblank_reply as
DRM_IOCTL_WAIT_VBLANK, but still uses wall-clock time.

This converts it to using monotonic time as well, which is more
consistent, and avoids problems with the y2038 overflow as well
as synchronization issues when the real time skips.

I could not find the matching user space that calls the VIA_WAIT_IRQ
ioctl to verify that this is safe, but it very likely is. Please
either test or review the user space side before applying this.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/via/via_irq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Daniel Vetter Nov. 27, 2017, 4:24 p.m. UTC | #1
On Mon, Nov 27, 2017 at 12:17:03PM +0100, Arnd Bergmann wrote:
> The normal DRM vblank interrupt events started using monotonic times in
> commit c61eef726a78 ("drm: add support for monotonic vblank timestamps"),
> which is useful for a number of reasons, including the possible y2038
> overflow.
> 
> The VIA_WAIT_IRQ ioctl uses the same drm_wait_vblank_reply as
> DRM_IOCTL_WAIT_VBLANK, but still uses wall-clock time.
> 
> This converts it to using monotonic time as well, which is more
> consistent, and avoids problems with the y2038 overflow as well
> as synchronization issues when the real time skips.
> 
> I could not find the matching user space that calls the VIA_WAIT_IRQ
> ioctl to verify that this is safe, but it very likely is. Please
> either test or review the user space side before applying this.

You need to check out _seriously_ old versions of mesa and X (plus it's
drivers). Git ftw.

The only caller I've found (in the Xv implementation of the via/openchrome
ddx) doesn't even care about the timestamp. I'm mildly tempted to just
report 0 always, but via isn't worth that much bother really.

Applied, thanks for the patch.
-Daniel

> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/gpu/drm/via/via_irq.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
> index 24e71578af4d..c96830ccc0ec 100644
> --- a/drivers/gpu/drm/via/via_irq.c
> +++ b/drivers/gpu/drm/via/via_irq.c
> @@ -343,7 +343,7 @@ void via_driver_irq_uninstall(struct drm_device *dev)
>  int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
>  {
>  	drm_via_irqwait_t *irqwait = data;
> -	struct timeval now;
> +	struct timespec64 now;
>  	int ret = 0;
>  	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
>  	drm_via_irq_t *cur_irq = dev_priv->via_irqs;
> @@ -377,9 +377,9 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
>  
>  	ret = via_driver_irq_wait(dev, irqwait->request.irq, force_sequence,
>  				  &irqwait->request.sequence);
> -	do_gettimeofday(&now);
> +	ktime_get_ts64(&now);
>  	irqwait->reply.tval_sec = now.tv_sec;
> -	irqwait->reply.tval_usec = now.tv_usec;
> +	irqwait->reply.tval_usec = now.tv_nsec / NSEC_PER_USEC;
>  
>  	return ret;
>  }
> -- 
> 2.9.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
index 24e71578af4d..c96830ccc0ec 100644
--- a/drivers/gpu/drm/via/via_irq.c
+++ b/drivers/gpu/drm/via/via_irq.c
@@ -343,7 +343,7 @@  void via_driver_irq_uninstall(struct drm_device *dev)
 int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	drm_via_irqwait_t *irqwait = data;
-	struct timeval now;
+	struct timespec64 now;
 	int ret = 0;
 	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
 	drm_via_irq_t *cur_irq = dev_priv->via_irqs;
@@ -377,9 +377,9 @@  int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
 
 	ret = via_driver_irq_wait(dev, irqwait->request.irq, force_sequence,
 				  &irqwait->request.sequence);
-	do_gettimeofday(&now);
+	ktime_get_ts64(&now);
 	irqwait->reply.tval_sec = now.tv_sec;
-	irqwait->reply.tval_usec = now.tv_usec;
+	irqwait->reply.tval_usec = now.tv_nsec / NSEC_PER_USEC;
 
 	return ret;
 }