summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIlija Hadzic <ilijahadzic@gmail.com>2013-05-08 22:39:38 -0400
committerMichel Dänzer <michel@daenzer.net>2013-05-29 15:06:27 +0200
commit373671d2eed30e30b3bdee7e40426cf58c127234 (patch)
tree2d26db3a50d2f34c51bf90686e4dc49ab5ba61f8 /src
parent006fbbd1d38a089b50ab3197d32815689ed249fa (diff)
drmmode: add drmmode_get_current_ust function
The new helper function retrieves current time in the format that is compatible with vblank timestamps. v2: - fix an incorrect statement in a comment - add a #define so that don't depend on libdrm patches that have not yet been accepted upstream Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'src')
-rw-r--r--src/drmmode_display.c25
-rw-r--r--src/drmmode_display.h5
2 files changed, 30 insertions, 0 deletions
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 13e65fa3..5db58daa 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <sys/ioctl.h>
+#include <time.h>
#include "micmap.h"
#include "xf86cmap.h"
#include "radeon.h"
@@ -216,6 +217,30 @@ drmmode_ConvertToKMode(ScrnInfoPtr scrn,
}
+/*
+ * Retrieves present time in microseconds that is compatible
+ * with units used by vblank timestamps. Depending on the kernel
+ * version and DRM kernel module configuration, the vblank
+ * timestamp can either be in real time or monotonic time
+ */
+int drmmode_get_current_ust(int drm_fd, CARD64 *ust)
+{
+ uint64_t cap_value;
+ int ret;
+ struct timespec now;
+
+ ret = drmGetCap(drm_fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap_value);
+ if (ret || !cap_value)
+ /* old kernel or drm_timestamp_monotonic turned off */
+ ret = clock_gettime(CLOCK_REALTIME, &now);
+ else
+ ret = clock_gettime(CLOCK_MONOTONIC, &now);
+ if (ret)
+ return ret;
+ *ust = ((CARD64)now.tv_sec * 1000000) + ((CARD64)now.tv_nsec / 1000);
+ return 0;
+}
+
static void
drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode)
{
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index b63ec8eb..add2ee48 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -34,6 +34,10 @@
#include "radeon_probe.h"
+#ifndef DRM_CAP_TIMESTAMP_MONOTONIC
+#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
+#endif
+
typedef struct {
int fd;
unsigned fb_id;
@@ -115,6 +119,7 @@ extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id);
+int drmmode_get_current_ust(int drm_fd, CARD64 *ust);
#endif