[PATCH 2/2] drm: add support for monotonic vblank timestamps

2012-10-24 Thread Imre Deak
On Wed, 2012-10-24 at 10:08 +0200, Michel D?nzer wrote:
> On Die, 2012-10-23 at 21:53 +0300, Imre Deak wrote: 
> > Jumps in the vblank and page flip event timestamps cause trouble for
> > clients, so we should avoid them. The timestamp we get currently with
> > gettimeofday can jump, so use instead monotonic timestamps.
> > 
> > For backward compatibility use a module flag to revert back to using
> > gettimeofday timestamps. Add also a DRM_CAP_TIMESTAMP_MONOTONIC flag
> > that is simply a read only version of the module flag, so that clients
> > can query this without depending on sysfs.
> > 
> > Signed-off-by: Imre Deak 
> 
> drm_timestamp_monotonic should probably be a bool rather than an int.

Ok, will change that. Also just realized that the permission could be
0644 isntead of 0600.

--Imre  

> 
> Looks good to me otherwise, as does patch 1.
> 
> 




[PATCH 2/2] drm: add support for monotonic vblank timestamps

2012-10-24 Thread Michel Dänzer
On Die, 2012-10-23 at 21:53 +0300, Imre Deak wrote: 
> Jumps in the vblank and page flip event timestamps cause trouble for
> clients, so we should avoid them. The timestamp we get currently with
> gettimeofday can jump, so use instead monotonic timestamps.
> 
> For backward compatibility use a module flag to revert back to using
> gettimeofday timestamps. Add also a DRM_CAP_TIMESTAMP_MONOTONIC flag
> that is simply a read only version of the module flag, so that clients
> can query this without depending on sysfs.
> 
> Signed-off-by: Imre Deak 

drm_timestamp_monotonic should probably be a bool rather than an int.

Looks good to me otherwise, as does patch 1.


-- 
Earthling Michel D?nzer   |   http://www.amd.com
Libre software enthusiast |  Debian, X and DRI developer


Re: [PATCH 2/2] drm: add support for monotonic vblank timestamps

2012-10-24 Thread Imre Deak
On Wed, 2012-10-24 at 10:08 +0200, Michel Dänzer wrote:
> On Die, 2012-10-23 at 21:53 +0300, Imre Deak wrote: 
> > Jumps in the vblank and page flip event timestamps cause trouble for
> > clients, so we should avoid them. The timestamp we get currently with
> > gettimeofday can jump, so use instead monotonic timestamps.
> > 
> > For backward compatibility use a module flag to revert back to using
> > gettimeofday timestamps. Add also a DRM_CAP_TIMESTAMP_MONOTONIC flag
> > that is simply a read only version of the module flag, so that clients
> > can query this without depending on sysfs.
> > 
> > Signed-off-by: Imre Deak 
> 
> drm_timestamp_monotonic should probably be a bool rather than an int.

Ok, will change that. Also just realized that the permission could be
0644 isntead of 0600.

--Imre  

> 
> Looks good to me otherwise, as does patch 1.
> 
> 


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 2/2] drm: add support for monotonic vblank timestamps

2012-10-24 Thread Michel Dänzer
On Die, 2012-10-23 at 21:53 +0300, Imre Deak wrote: 
> Jumps in the vblank and page flip event timestamps cause trouble for
> clients, so we should avoid them. The timestamp we get currently with
> gettimeofday can jump, so use instead monotonic timestamps.
> 
> For backward compatibility use a module flag to revert back to using
> gettimeofday timestamps. Add also a DRM_CAP_TIMESTAMP_MONOTONIC flag
> that is simply a read only version of the module flag, so that clients
> can query this without depending on sysfs.
> 
> Signed-off-by: Imre Deak 

drm_timestamp_monotonic should probably be a bool rather than an int.

Looks good to me otherwise, as does patch 1.


-- 
Earthling Michel Dänzer   |   http://www.amd.com
Libre software enthusiast |  Debian, X and DRI developer
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 2/2] drm: add support for monotonic vblank timestamps

2012-10-23 Thread Imre Deak
Jumps in the vblank and page flip event timestamps cause trouble for
clients, so we should avoid them. The timestamp we get currently with
gettimeofday can jump, so use instead monotonic timestamps.

For backward compatibility use a module flag to revert back to using
gettimeofday timestamps. Add also a DRM_CAP_TIMESTAMP_MONOTONIC flag
that is simply a read only version of the module flag, so that clients
can query this without depending on sysfs.

Signed-off-by: Imre Deak 
---
 drivers/gpu/drm/drm_ioctl.c |3 +++
 drivers/gpu/drm/drm_irq.c   |   25 -
 drivers/gpu/drm/drm_stub.c  |8 
 include/drm/drmP.h  |1 +
 include/uapi/drm/drm.h  |1 +
 5 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 23dd975..e77bd8b 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -287,6 +287,9 @@ int drm_getcap(struct drm_device *dev, void *data, struct 
drm_file *file_priv)
req->value |= dev->driver->prime_fd_to_handle ? 
DRM_PRIME_CAP_IMPORT : 0;
req->value |= dev->driver->prime_handle_to_fd ? 
DRM_PRIME_CAP_EXPORT : 0;
break;
+   case DRM_CAP_TIMESTAMP_MONOTONIC:
+   req->value = drm_timestamp_monotonic;
+   break;
default:
return -EINVAL;
}
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 7dc203d..37e58df7 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -633,7 +633,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device 
*dev, int crtc,

/* Get system timestamp after query. */
etime = ktime_get();
-   mono_time_offset = ktime_get_monotonic_offset();
+   if (!drm_timestamp_monotonic)
+   mono_time_offset = ktime_get_monotonic_offset();

preempt_enable();

@@ -691,7 +692,9 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device 
*dev, int crtc,
vbl_status |= 0x8;
}

-   etime = ktime_sub(etime, mono_time_offset);
+   if (!drm_timestamp_monotonic)
+   etime = ktime_sub(etime, mono_time_offset);
+
/* save this only for debugging purposes */
tv_etime = ktime_to_timeval(etime);
/* Subtract time delta from raw timestamp to get final
@@ -714,6 +717,17 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct 
drm_device *dev, int crtc,
 }
 EXPORT_SYMBOL(drm_calc_vbltimestamp_from_scanoutpos);

+static struct timeval get_drm_timestamp(void)
+{
+   ktime_t now;
+
+   now = ktime_get();
+   if (!drm_timestamp_monotonic)
+   now = ktime_sub(now, ktime_get_monotonic_offset());
+
+   return ktime_to_timeval(now);
+}
+
 /**
  * drm_get_last_vbltimestamp - retrieve raw timestamp for the most recent
  * vblank interval.
@@ -751,9 +765,9 @@ u32 drm_get_last_vbltimestamp(struct drm_device *dev, int 
crtc,
}

/* GPU high precision timestamp query unsupported or failed.
-* Return gettimeofday timestamp as best estimate.
+* Return current monotonic/gettimeofday timestamp as best estimate.
 */
-   do_gettimeofday(tvblank);
+   *tvblank = get_drm_timestamp();

return 0;
 }
@@ -842,7 +856,8 @@ void drm_send_vblank_event(struct drm_device *dev, int crtc,
seq = drm_vblank_count_and_time(dev, crtc, &now);
} else {
seq = 0;
-   do_gettimeofday(&now);
+
+   now = get_drm_timestamp();
}
send_vblank_event(dev, e, seq, &now);
 }
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index c236fd2..4433453 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -46,16 +46,24 @@ EXPORT_SYMBOL(drm_vblank_offdelay);
 unsigned int drm_timestamp_precision = 20;  /* Default to 20 usecs. */
 EXPORT_SYMBOL(drm_timestamp_precision);

+/*
+ * Default to use monotonic timestamps for wait-for-vblank and page-flip
+ * complete events.
+ */
+unsigned int drm_timestamp_monotonic = 1;
+
 MODULE_AUTHOR(CORE_AUTHOR);
 MODULE_DESCRIPTION(CORE_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_PARM_DESC(debug, "Enable debug output");
 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable 
[msecs]");
 MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]");
+MODULE_PARM_DESC(timestamp_monotonic, "Use monotonic timestamps");

 module_param_named(debug, drm_debug, int, 0600);
 module_param_named(vblankoffdelay, drm_vblank_offdelay, int, 0600);
 module_param_named(timestamp_precision_usec, drm_timestamp_precision, int, 
0600);
+module_param_named(timestamp_monotonic, drm_timestamp_monotonic, int, 0600);

 struct idr drm_minors_idr;

diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 29eb237..fad21c9 100644
--- a/include/drm/drmP.h
+++ b/include/drm/dr

[PATCH 2/2] drm: add support for monotonic vblank timestamps

2012-10-23 Thread Imre Deak
Jumps in the vblank and page flip event timestamps cause trouble for
clients, so we should avoid them. The timestamp we get currently with
gettimeofday can jump, so use instead monotonic timestamps.

For backward compatibility use a module flag to revert back to using
gettimeofday timestamps. Add also a DRM_CAP_TIMESTAMP_MONOTONIC flag
that is simply a read only version of the module flag, so that clients
can query this without depending on sysfs.

Signed-off-by: Imre Deak 
---
 drivers/gpu/drm/drm_ioctl.c |3 +++
 drivers/gpu/drm/drm_irq.c   |   25 -
 drivers/gpu/drm/drm_stub.c  |8 
 include/drm/drmP.h  |1 +
 include/uapi/drm/drm.h  |1 +
 5 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 23dd975..e77bd8b 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -287,6 +287,9 @@ int drm_getcap(struct drm_device *dev, void *data, struct 
drm_file *file_priv)
req->value |= dev->driver->prime_fd_to_handle ? 
DRM_PRIME_CAP_IMPORT : 0;
req->value |= dev->driver->prime_handle_to_fd ? 
DRM_PRIME_CAP_EXPORT : 0;
break;
+   case DRM_CAP_TIMESTAMP_MONOTONIC:
+   req->value = drm_timestamp_monotonic;
+   break;
default:
return -EINVAL;
}
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 7dc203d..37e58df7 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -633,7 +633,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device 
*dev, int crtc,
 
/* Get system timestamp after query. */
etime = ktime_get();
-   mono_time_offset = ktime_get_monotonic_offset();
+   if (!drm_timestamp_monotonic)
+   mono_time_offset = ktime_get_monotonic_offset();
 
preempt_enable();
 
@@ -691,7 +692,9 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device 
*dev, int crtc,
vbl_status |= 0x8;
}
 
-   etime = ktime_sub(etime, mono_time_offset);
+   if (!drm_timestamp_monotonic)
+   etime = ktime_sub(etime, mono_time_offset);
+
/* save this only for debugging purposes */
tv_etime = ktime_to_timeval(etime);
/* Subtract time delta from raw timestamp to get final
@@ -714,6 +717,17 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct 
drm_device *dev, int crtc,
 }
 EXPORT_SYMBOL(drm_calc_vbltimestamp_from_scanoutpos);
 
+static struct timeval get_drm_timestamp(void)
+{
+   ktime_t now;
+
+   now = ktime_get();
+   if (!drm_timestamp_monotonic)
+   now = ktime_sub(now, ktime_get_monotonic_offset());
+
+   return ktime_to_timeval(now);
+}
+
 /**
  * drm_get_last_vbltimestamp - retrieve raw timestamp for the most recent
  * vblank interval.
@@ -751,9 +765,9 @@ u32 drm_get_last_vbltimestamp(struct drm_device *dev, int 
crtc,
}
 
/* GPU high precision timestamp query unsupported or failed.
-* Return gettimeofday timestamp as best estimate.
+* Return current monotonic/gettimeofday timestamp as best estimate.
 */
-   do_gettimeofday(tvblank);
+   *tvblank = get_drm_timestamp();
 
return 0;
 }
@@ -842,7 +856,8 @@ void drm_send_vblank_event(struct drm_device *dev, int crtc,
seq = drm_vblank_count_and_time(dev, crtc, &now);
} else {
seq = 0;
-   do_gettimeofday(&now);
+
+   now = get_drm_timestamp();
}
send_vblank_event(dev, e, seq, &now);
 }
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index c236fd2..4433453 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -46,16 +46,24 @@ EXPORT_SYMBOL(drm_vblank_offdelay);
 unsigned int drm_timestamp_precision = 20;  /* Default to 20 usecs. */
 EXPORT_SYMBOL(drm_timestamp_precision);
 
+/*
+ * Default to use monotonic timestamps for wait-for-vblank and page-flip
+ * complete events.
+ */
+unsigned int drm_timestamp_monotonic = 1;
+
 MODULE_AUTHOR(CORE_AUTHOR);
 MODULE_DESCRIPTION(CORE_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_PARM_DESC(debug, "Enable debug output");
 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable 
[msecs]");
 MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]");
+MODULE_PARM_DESC(timestamp_monotonic, "Use monotonic timestamps");
 
 module_param_named(debug, drm_debug, int, 0600);
 module_param_named(vblankoffdelay, drm_vblank_offdelay, int, 0600);
 module_param_named(timestamp_precision_usec, drm_timestamp_precision, int, 
0600);
+module_param_named(timestamp_monotonic, drm_timestamp_monotonic, int, 0600);
 
 struct idr drm_minors_idr;
 
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 29eb237..fad21c9 100644
--- a/include/drm/drmP.h
+++ b/inc