From c06808fb6521822238bca4574758f30246b71c2d Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Fri, 2 Nov 2007 15:52:00 +0100 Subject: Return fence errors. Time out properly in the presence of signals. --- libdrm/xf86drm.c | 98 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 39 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 7001a0ef..5a4071b2 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2432,7 +2432,7 @@ int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type) fence->fence_class = arg.fence_class; fence->type = arg.type; fence->signaled = arg.signaled; - return 0; + return arg.error; } int drmFenceUpdate(int fd, drmFence *fence) @@ -2495,7 +2495,50 @@ int drmFenceEmit(int fd, unsigned flags, drmFence *fence, unsigned emit_type) * DRM_FENCE_FLAG_WAIT_LAZY * DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS */ + +#define DRM_IOCTL_TIMEOUT_USEC 3000000UL + +static unsigned long +drmTimeDiff(struct timeval *now, struct timeval *then) +{ + uint64_t val; + + val = now->tv_sec - then->tv_sec; + val *= 1000000LL; + val += now->tv_usec; + val -= then->tv_usec; + + return (unsigned long) val; +} + +static int +drmIoctlTimeout(int fd, unsigned long request, void *argp) +{ + int haveThen = 0; + struct timeval then, now; + int ret; + + do { + ret = ioctl(fd, request, argp); + if (ret != 0 && errno == EAGAIN) { + if (!haveThen) { + gettimeofday(&then, NULL); + haveThen = 1; + } + gettimeofday(&now, NULL); + } + } while (ret != 0 && errno == EAGAIN && + drmTimeDiff(&now, &then) < DRM_IOCTL_TIMEOUT_USEC); + + if (ret != 0) + return ((errno == EAGAIN) ? -EBUSY : -errno); + + return 0; +} + + + int drmFenceWait(int fd, unsigned flags, drmFence *fence, unsigned flush_type) { drm_fence_arg_t arg; @@ -2516,17 +2559,15 @@ int drmFenceWait(int fd, unsigned flags, drmFence *fence, unsigned flush_type) arg.type = flush_type; arg.flags = flags; - do { - ret = ioctl(fd, DRM_IOCTL_FENCE_WAIT, &arg); - } while (ret != 0 && errno == EAGAIN); + ret = drmIoctlTimeout(fd, DRM_IOCTL_FENCE_WAIT, &arg); if (ret) - return -errno; + return ret; fence->fence_class = arg.fence_class; fence->type = arg.type; fence->signaled = arg.signaled; - return 0; + return arg.error; } static void drmBOCopyReply(const struct drm_bo_info_rep *rep, drmBO *buf) @@ -2568,12 +2609,9 @@ int drmBOCreate(int fd, unsigned long size, buf->virtual = NULL; - do { - ret = ioctl(fd, DRM_IOCTL_BO_CREATE, &arg); - } while (ret != 0 && errno == EAGAIN); - + ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_CREATE, &arg); if (ret) - return -errno; + return ret; drmBOCopyReply(rep, buf); buf->mapVirtual = NULL; @@ -2665,12 +2703,9 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, * This IOCTL synchronizes the buffer. */ - do { - ret = ioctl(fd, DRM_IOCTL_BO_MAP, &arg); - } while (ret != 0 && errno == EAGAIN); - - if (ret) - return -errno; + ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_MAP, &arg); + if (ret) + return ret; drmBOCopyReply(rep, buf); buf->mapFlags = mapFlags; @@ -2715,14 +2750,12 @@ int drmBOSetStatus(int fd, drmBO *buf, req->desired_tile_stride = desired_tile_stride; req->tile_info = tile_info; - do { - ret = ioctl(fd, DRM_IOCTL_BO_SETSTATUS, &arg); - } while (ret && errno == EAGAIN); - + ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_SETSTATUS, &arg); if (ret) - return -errno; + return ret; drmBOCopyReply(rep, buf); + return 0; } @@ -2757,12 +2790,9 @@ int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint) req->handle = buf->handle; req->hint = hint; - do { - ret = ioctl(fd, DRM_IOCTL_BO_WAIT_IDLE, &arg); - } while (ret && errno == EAGAIN); - + ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_WAIT_IDLE, &arg); if (ret) - return -errno; + return ret; drmBOCopyReply(rep, buf); } @@ -2824,35 +2854,25 @@ int drmMMTakedown(int fd, unsigned memType) int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict) { struct drm_mm_type_arg arg; - int ret; memset(&arg, 0, sizeof(arg)); arg.mem_type = memType; arg.lock_flags |= (lockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0; arg.lock_flags |= (ignoreNoEvict) ? DRM_BO_LOCK_IGNORE_NO_EVICT : 0; - do{ - ret = ioctl(fd, DRM_IOCTL_MM_LOCK, &arg); - } while (ret && errno == EAGAIN); - - return (ret) ? -errno : 0; + return drmIoctlTimeout(fd, DRM_IOCTL_MM_LOCK, &arg); } int drmMMUnlock(int fd, unsigned memType, int unlockBM) { struct drm_mm_type_arg arg; - int ret; memset(&arg, 0, sizeof(arg)); arg.mem_type = memType; arg.lock_flags |= (unlockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0; - do{ - ret = ioctl(fd, DRM_IOCTL_MM_UNLOCK, &arg); - } while (ret && errno == EAGAIN); - - return (ret) ? -errno : 0; + return drmIoctlTimeout(fd, DRM_IOCTL_MM_UNLOCK, &arg); } int drmBOVersion(int fd, unsigned int *major, -- cgit v1.2.3 From 94c22c334948a49641f4a1fa84687f992e5cc5cb Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Fri, 2 Nov 2007 16:03:41 +0100 Subject: User buffer support. --- libdrm/xf86drm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 5a4071b2..165cb2f9 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2612,9 +2612,9 @@ int drmBOCreate(int fd, unsigned long size, ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_CREATE, &arg); if (ret) return ret; - + drmBOCopyReply(rep, buf); - buf->mapVirtual = NULL; + buf->virtual = user_buffer; buf->mapCount = 0; return 0; @@ -2644,7 +2644,7 @@ int drmBOUnreference(int fd, drmBO *buf) { struct drm_bo_handle_arg arg; - if (buf->mapVirtual) { + if (buf->mapVirtual && buf->mapHandle) { (void) munmap(buf->mapVirtual, buf->start + buf->size); buf->mapVirtual = NULL; buf->virtual = NULL; -- cgit v1.2.3 From 6abbbb2f4f5b6b280077a6c88bb643507c8ec8fa Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Mon, 5 Nov 2007 04:44:40 +1100 Subject: Fill fence sequence after emit ioctl. --- libdrm/xf86drm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 165cb2f9..4265c320 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2487,6 +2487,7 @@ int drmFenceEmit(int fd, unsigned flags, drmFence *fence, unsigned emit_type) fence->fence_class = arg.fence_class; fence->type = arg.type; fence->signaled = arg.signaled; + fence->sequence = arg.sequence; return 0; } -- cgit v1.2.3 From d1187641d64f442968a3b9ea6a19de6cdd45acd4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 16 Dec 2007 20:16:50 -0800 Subject: Rename inappropriately named 'mask' fields to 'proposed_flags' instead. Flags pending validation were stored in a misleadingly named field, 'mask'. As 'mask' is already used to indicate pieces of a flags field which are changing, it seems better to use a name reflecting the actual purpose of this field. I chose 'proposed_flags' as they may not actually end up in 'flags', and in an case will be modified when they are moved over. This affects the API, but not ABI of the user-mode interface. --- libdrm/xf86drm.c | 6 +++--- libdrm/xf86mm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 4265c320..e3550de7 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2578,7 +2578,7 @@ static void drmBOCopyReply(const struct drm_bo_info_rep *rep, drmBO *buf) buf->size = rep->size; buf->offset = rep->offset; buf->mapHandle = rep->arg_handle; - buf->mask = rep->mask; + buf->proposedFlags = rep->proposed_flags; buf->start = rep->buffer_start; buf->fenceFlags = rep->fence_flags; buf->replyFlags = rep->rep_flags; @@ -2592,7 +2592,7 @@ static void drmBOCopyReply(const struct drm_bo_info_rep *rep, drmBO *buf) int drmBOCreate(int fd, unsigned long size, unsigned pageAlignment, void *user_buffer, - uint64_t mask, + uint64_t flags, unsigned hint, drmBO *buf) { struct drm_bo_create_arg arg; @@ -2602,7 +2602,7 @@ int drmBOCreate(int fd, unsigned long size, memset(buf, 0, sizeof(*buf)); memset(&arg, 0, sizeof(arg)); - req->mask = mask; + req->flags = flags; req->hint = hint; req->size = size; req->page_alignment = pageAlignment; diff --git a/libdrm/xf86mm.h b/libdrm/xf86mm.h index d3df8497..c80288a7 100644 --- a/libdrm/xf86mm.h +++ b/libdrm/xf86mm.h @@ -110,7 +110,7 @@ typedef struct _drmBO unsigned handle; uint64_t mapHandle; uint64_t flags; - uint64_t mask; + uint64_t proposedFlags; unsigned mapFlags; unsigned long size; unsigned long offset; -- cgit v1.2.3