From 5968e061db90451b19c3948bbd91c6d5ac9af941 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 7 Aug 2008 15:26:30 -0700 Subject: Make flink save the kernel-assigned name and return it instead of creating another name --- libdrm/intel/intel_bufmgr_gem.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 22f8695d..f5732226 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -102,6 +102,11 @@ struct _dri_bo_gem { uint32_t gem_handle; const char *name; + /** + * Kenel-assigned global name for this object + */ + unsigned int global_name; + /** * Index of the buffer within the validation list while preparing a * batchbuffer execution. @@ -833,13 +838,16 @@ dri_gem_flink(dri_bo *bo, uint32_t *name) struct drm_gem_flink flink; int ret; - flink.handle = bo_gem->gem_handle; - - ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); - if (ret != 0) - return -errno; - - *name = flink.name; + if (!bo_gem->global_name) { + flink.handle = bo_gem->gem_handle; + + ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); + if (ret != 0) + return -errno; + bo_gem->gem_handle = flink.name; + } + + *name = bo_gem->gem_handle; return 0; } -- cgit v1.2.3 From 46e9274e8538e5b0517f611dca99dde611f4e95d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 8 Aug 2008 13:13:46 -0700 Subject: Replace the check_aperture API with one we can make thread-safe. While the bufmgr isn't thread-safe at the moment, we need it to be for shared objects between contexts. --- libdrm/intel/intel_bufmgr_fake.c | 63 ++++++++++++++++++++++++---------------- libdrm/intel/intel_bufmgr_gem.c | 2 +- 2 files changed, 39 insertions(+), 26 deletions(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index e988eb58..63dd9bef 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -43,6 +43,8 @@ #include "i915_drm.h" #include "mm.h" +#define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) + #define DBG(...) do { \ if (bufmgr_fake->bufmgr.debug) \ drmMsg(__VA_ARGS__); \ @@ -147,9 +149,6 @@ typedef struct _bufmgr_fake { int debug; int performed_rendering; - - /* keep track of the current total size of objects we have relocs for */ - unsigned long current_total_size; } dri_bufmgr_fake; typedef struct _dri_bo_fake { @@ -159,8 +158,8 @@ typedef struct _dri_bo_fake { const char *name; unsigned dirty:1; - unsigned size_accounted:1; /*this buffers size has been accounted against the aperture */ - unsigned card_dirty:1; /* has the card written to this buffer - we make need to copy it back */ + /** has the card written to this buffer - we make need to copy it back */ + unsigned card_dirty:1; unsigned int refcount; /* Flags may consist of any of the DRM_BO flags, plus * DRM_BO_NO_BACKING_STORE and BM_NO_FENCE_SUBDATA, which are the first two @@ -179,6 +178,12 @@ typedef struct _dri_bo_fake { /** relocation list */ struct fake_buffer_reloc *relocs; int nr_relocs; + /** + * Total size of the target_bos of this buffer. + * + * Used for estimation in check_aperture. + */ + unsigned int child_size; struct block *block; void *backing_store; @@ -189,8 +194,6 @@ typedef struct _dri_bo_fake { static int clear_fenced(dri_bufmgr_fake *bufmgr_fake, unsigned int fence_cookie); -static int dri_fake_check_aperture_space(dri_bo *bo); - #define MAXFENCE 0x7fffffff static int FENCE_LTE( unsigned a, unsigned b ) @@ -855,9 +858,6 @@ dri_fake_bo_validate(dri_bo *bo) return 0; } - /* reset size accounted */ - bo_fake->size_accounted = 0; - /* Allocate the card memory */ if (!bo_fake->block && !evict_and_alloc_block(bo)) { bufmgr_fake->fail = 1; @@ -941,8 +941,6 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, assert(reloc_buf); assert(target_buf); - assert(target_fake->is_static || target_fake->size_accounted); - if (reloc_fake->relocs == NULL) { reloc_fake->relocs = malloc(sizeof(struct fake_buffer_reloc) * MAX_RELOCS); @@ -954,6 +952,9 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, dri_bo_reference(target_buf); + if (!target_fake->is_static) + reloc_fake->child_size += ALIGN(target_buf->size, target_fake->alignment); + r->target_buf = target_buf; r->offset = offset; r->last_target_offset = target_buf->offset; @@ -1079,7 +1080,6 @@ dri_fake_process_relocs(dri_bo *batch_buf) assert(ret == 0); - bufmgr_fake->current_total_size = 0; return NULL; } @@ -1117,26 +1117,39 @@ dri_fake_post_submit(dri_bo *batch_buf) dri_bo_fake_post_submit(batch_buf); } +/** + * Return an error if the list of BOs will exceed the aperture size. + * + * This is a rough guess and likely to fail, as during the validate sequence we + * may place a buffer in an inopportune spot early on and then fail to fit + * a set smaller than the aperture. + */ static int -dri_fake_check_aperture_space(dri_bo *bo) +dri_fake_check_aperture_space(dri_bo **bo_array, int count) { - dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; - dri_bo_fake *bo_fake = (dri_bo_fake *)bo; - unsigned int sz; + dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo_array[0]->bufmgr; + unsigned int sz = 0; + int i; - sz = (bo->size + bo_fake->alignment - 1) & ~(bo_fake->alignment - 1); + for (i = 0; i < count; i++) { + dri_bo_fake *bo_fake = (dri_bo_fake *)bo_array[i]; - if (bo_fake->size_accounted || bo_fake->is_static) - return 0; + if (bo_fake == NULL) + continue; + + if (!bo_fake->is_static) + sz += ALIGN(bo_array[i]->size, bo_fake->alignment); + sz += bo_fake->child_size; + } - if (bufmgr_fake->current_total_size + sz > bufmgr_fake->size) { - DBG("check_space: %s bo %d %d overflowed bufmgr size %d\n", bo_fake->name, bo_fake->id, sz, bufmgr_fake->size); + if (sz > bufmgr_fake->size) { + DBG("check_space: overflowed bufmgr size, %dkb vs %dkb\n", + sz / 1024, bufmgr_fake->size / 1024); return -1; } - bufmgr_fake->current_total_size += sz; - bo_fake->size_accounted = 1; - DBG("drm_check_space: buf %d, %s %d %d\n", bo_fake->id, bo_fake->name, bo->size, bufmgr_fake->current_total_size); + DBG("drm_check_space: sz %dkb vs bufgr %dkb\n", sz / 1024 , + bufmgr_fake->size / 1024); return 0; } diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index f5732226..48752f2f 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -873,7 +873,7 @@ intel_bufmgr_gem_enable_reuse(dri_bufmgr *bufmgr) * */ static int -dri_gem_check_aperture_space(dri_bo *bo) +dri_gem_check_aperture_space(dri_bo *bo_array, int count) { return 0; } -- cgit v1.2.3 From 9e9d9b1741965f6529153bc2bcbe2dd8ba96ef3f Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 8 Aug 2008 14:08:43 -0700 Subject: Fix compile warning from check_aperture change. --- libdrm/intel/intel_bufmgr_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 48752f2f..54c800aa 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -873,7 +873,7 @@ intel_bufmgr_gem_enable_reuse(dri_bufmgr *bufmgr) * */ static int -dri_gem_check_aperture_space(dri_bo *bo_array, int count) +dri_gem_check_aperture_space(dri_bo **bo_array, int count) { return 0; } -- cgit v1.2.3 From f7a99407153eaba5724b6f1f2cadab62c6a50a26 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 8 Aug 2008 15:55:34 -0700 Subject: Drop TTM interfaces from the userland library. --- libdrm/intel/intel_bufmgr_fake.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index 63dd9bef..e2dd9dc7 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -42,6 +42,7 @@ #include "drm.h" #include "i915_drm.h" #include "mm.h" +#include "libdrm_lists.h" #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) -- cgit v1.2.3 From 966c783e96b3f8ae0271db3dd6862177c659ab13 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Mon, 11 Aug 2008 10:44:39 -0700 Subject: libdrm: Allow build outside of source tree. --- libdrm/intel/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'libdrm/intel') diff --git a/libdrm/intel/Makefile.am b/libdrm/intel/Makefile.am index 111204b1..31a8512a 100644 --- a/libdrm/intel/Makefile.am +++ b/libdrm/intel/Makefile.am @@ -24,6 +24,7 @@ AM_CFLAGS = \ $(WARN_CFLAGS) \ + -I$(top_srcdir)/libdrm \ -I$(top_srcdir)/shared-core noinst_LTLIBRARIES = libdrm_intel.la -- cgit v1.2.3 From b0e68829462aad00ce68be998da6313bca754e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 12 Aug 2008 22:22:15 -0400 Subject: [intel_bufmgr_gem] Fix flink buffer name caching (#17085, #17092). Store the global name in global_name, don't overwrite the gem_handle. --- libdrm/intel/intel_bufmgr_gem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 54c800aa..48a47701 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -844,10 +844,10 @@ dri_gem_flink(dri_bo *bo, uint32_t *name) ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); if (ret != 0) return -errno; - bo_gem->gem_handle = flink.name; + bo_gem->global_name = flink.name; } - *name = bo_gem->gem_handle; + *name = bo_gem->global_name; return 0; } -- cgit v1.2.3