* Small execbuf coherency fixes
@ 2016-08-10 11:54 Chris Wilson
2016-08-10 11:54 ` [PATCH 1/9] drm/i915: Cache kmap between relocations Chris Wilson
` (10 more replies)
0 siblings, 11 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
Execbuf suffers from a coherency problem which in theory is handled by
the prepare for direct access implemented by pwrite. The issue being not
only is that function non-existent (implemented inline for pwrite) it is
missing a barrier or two.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/9] drm/i915: Cache kmap between relocations
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 2/9] drm/i915: Extract i915_gem_obj_prepare_shmem_write() Chris Wilson
` (9 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
When doing relocations, we have to obtain a mapping to the page
containing the target address. This is either a kmap or iomap depending
on GPU and its cache coherency. Neighbouring relocation entries are
typically within the same page and so we can cache our kmapping between
them and avoid those pesky TLB flushes.
Note that there is some sleight-of-hand in how the slow relocate works
as the reloc_entry_cache implies pagefaults disabled (as we are inside a
kmap_atomic section). However, the slow relocate code is meant to be the
fallback from the atomic fast path failing. Fortunately it works as we
already have performed the copy_from_user for the relocation array (no
more pagefaults there) and the kmap_atomic cache is enabled after we
have waited upon an active buffer (so no more sleeping in atomic).
Magic!
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 165 +++++++++++++++++++----------
1 file changed, 111 insertions(+), 54 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 7e963033863f..5caa7ba55cf5 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -308,9 +308,55 @@ relocation_target(struct drm_i915_gem_relocation_entry *reloc,
return gen8_canonical_addr((int)reloc->delta + target_offset);
}
+struct reloc_cache {
+ void *vaddr;
+ unsigned int page;
+ enum { KMAP, IOMAP } type;
+};
+
+static void reloc_cache_init(struct reloc_cache *cache)
+{
+ cache->page = -1;
+ cache->vaddr = NULL;
+}
+
+static void reloc_cache_fini(struct reloc_cache *cache)
+{
+ if (!cache->vaddr)
+ return;
+
+ switch (cache->type) {
+ case KMAP:
+ kunmap_atomic(cache->vaddr);
+ break;
+
+ case IOMAP:
+ io_mapping_unmap_atomic(cache->vaddr);
+ break;
+ }
+}
+
+static void *reloc_kmap(struct drm_i915_gem_object *obj,
+ struct reloc_cache *cache,
+ int page)
+{
+ if (cache->page == page)
+ return cache->vaddr;
+
+ if (cache->vaddr)
+ kunmap_atomic(cache->vaddr);
+
+ cache->page = page;
+ cache->vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, page));
+ cache->type = KMAP;
+
+ return cache->vaddr;
+}
+
static int
relocate_entry_cpu(struct drm_i915_gem_object *obj,
struct drm_i915_gem_relocation_entry *reloc,
+ struct reloc_cache *cache,
uint64_t target_offset)
{
struct drm_device *dev = obj->base.dev;
@@ -323,34 +369,47 @@ relocate_entry_cpu(struct drm_i915_gem_object *obj,
if (ret)
return ret;
- vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj,
- reloc->offset >> PAGE_SHIFT));
+ vaddr = reloc_kmap(obj, cache, reloc->offset >> PAGE_SHIFT);
*(uint32_t *)(vaddr + page_offset) = lower_32_bits(delta);
- if (INTEL_INFO(dev)->gen >= 8) {
- page_offset = offset_in_page(page_offset + sizeof(uint32_t));
-
- if (page_offset == 0) {
- kunmap_atomic(vaddr);
- vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj,
- (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT));
+ if (INTEL_GEN(dev) >= 8) {
+ page_offset += sizeof(uint32_t);
+ if (page_offset == PAGE_SIZE) {
+ vaddr = reloc_kmap(obj, cache, cache->page + 1);
+ page_offset = 0;
}
-
*(uint32_t *)(vaddr + page_offset) = upper_32_bits(delta);
}
- kunmap_atomic(vaddr);
-
return 0;
}
+static void *reloc_iomap(struct drm_i915_private *i915,
+ struct reloc_cache *cache,
+ uint64_t offset)
+{
+ if (cache->page == offset >> PAGE_SHIFT)
+ return cache->vaddr;
+
+ if (cache->vaddr)
+ io_mapping_unmap_atomic(cache->vaddr);
+
+ cache->page = offset >> PAGE_SHIFT;
+ cache->vaddr =
+ io_mapping_map_atomic_wc(i915->ggtt.mappable,
+ offset & PAGE_MASK);
+ cache->type = IOMAP;
+
+ return cache->vaddr;
+}
+
static int
relocate_entry_gtt(struct drm_i915_gem_object *obj,
struct drm_i915_gem_relocation_entry *reloc,
+ struct reloc_cache *cache,
uint64_t target_offset)
{
struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
- struct i915_ggtt *ggtt = &dev_priv->ggtt;
struct i915_vma *vma;
uint64_t delta = relocation_target(reloc, target_offset);
uint64_t offset;
@@ -372,28 +431,19 @@ relocate_entry_gtt(struct drm_i915_gem_object *obj,
/* Map the page containing the relocation we're going to perform. */
offset = vma->node.start;
offset += reloc->offset;
- reloc_page = io_mapping_map_atomic_wc(ggtt->mappable,
- offset & PAGE_MASK);
+ reloc_page = reloc_iomap(dev_priv, cache, offset);
iowrite32(lower_32_bits(delta), reloc_page + offset_in_page(offset));
if (INTEL_GEN(dev_priv) >= 8) {
offset += sizeof(uint32_t);
-
- if (offset_in_page(offset) == 0) {
- io_mapping_unmap_atomic(reloc_page);
- reloc_page =
- io_mapping_map_atomic_wc(ggtt->mappable,
- offset);
- }
-
+ if (offset_in_page(offset) == 0)
+ reloc_page = reloc_iomap(dev_priv, cache, offset);
iowrite32(upper_32_bits(delta),
reloc_page + offset_in_page(offset));
}
- io_mapping_unmap_atomic(reloc_page);
-
unpin:
- i915_vma_unpin(vma);
+ __i915_vma_unpin(vma);
return ret;
}
@@ -409,6 +459,7 @@ clflush_write32(void *addr, uint32_t value)
static int
relocate_entry_clflush(struct drm_i915_gem_object *obj,
struct drm_i915_gem_relocation_entry *reloc,
+ struct reloc_cache *cache,
uint64_t target_offset)
{
struct drm_device *dev = obj->base.dev;
@@ -421,24 +472,18 @@ relocate_entry_clflush(struct drm_i915_gem_object *obj,
if (ret)
return ret;
- vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj,
- reloc->offset >> PAGE_SHIFT));
+ vaddr = reloc_kmap(obj, cache, reloc->offset >> PAGE_SHIFT);
clflush_write32(vaddr + page_offset, lower_32_bits(delta));
- if (INTEL_INFO(dev)->gen >= 8) {
- page_offset = offset_in_page(page_offset + sizeof(uint32_t));
-
- if (page_offset == 0) {
- kunmap_atomic(vaddr);
- vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj,
- (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT));
+ if (INTEL_GEN(dev) >= 8) {
+ page_offset += sizeof(uint32_t);
+ if (page_offset == PAGE_SIZE) {
+ vaddr = reloc_kmap(obj, cache, cache->page + 1);
+ page_offset = 0;
}
-
clflush_write32(vaddr + page_offset, upper_32_bits(delta));
}
- kunmap_atomic(vaddr);
-
return 0;
}
@@ -459,7 +504,8 @@ static bool object_is_idle(struct drm_i915_gem_object *obj)
static int
i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
struct eb_vmas *eb,
- struct drm_i915_gem_relocation_entry *reloc)
+ struct drm_i915_gem_relocation_entry *reloc,
+ struct reloc_cache *cache)
{
struct drm_device *dev = obj->base.dev;
struct drm_gem_object *target_obj;
@@ -543,11 +589,11 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
return -EFAULT;
if (use_cpu_reloc(obj))
- ret = relocate_entry_cpu(obj, reloc, target_offset);
+ ret = relocate_entry_cpu(obj, reloc, cache, target_offset);
else if (obj->map_and_fenceable)
- ret = relocate_entry_gtt(obj, reloc, target_offset);
+ ret = relocate_entry_gtt(obj, reloc, cache, target_offset);
else if (static_cpu_has(X86_FEATURE_CLFLUSH))
- ret = relocate_entry_clflush(obj, reloc, target_offset);
+ ret = relocate_entry_clflush(obj, reloc, cache, target_offset);
else {
WARN_ONCE(1, "Impossible case in relocation handling\n");
ret = -ENODEV;
@@ -570,9 +616,11 @@ i915_gem_execbuffer_relocate_vma(struct i915_vma *vma,
struct drm_i915_gem_relocation_entry stack_reloc[N_RELOC(512)];
struct drm_i915_gem_relocation_entry __user *user_relocs;
struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
- int remain, ret;
+ struct reloc_cache cache;
+ int remain, ret = 0;
user_relocs = u64_to_user_ptr(entry->relocs_ptr);
+ reloc_cache_init(&cache);
remain = entry->relocation_count;
while (remain) {
@@ -582,19 +630,23 @@ i915_gem_execbuffer_relocate_vma(struct i915_vma *vma,
count = ARRAY_SIZE(stack_reloc);
remain -= count;
- if (__copy_from_user_inatomic(r, user_relocs, count*sizeof(r[0])))
- return -EFAULT;
+ if (__copy_from_user_inatomic(r, user_relocs, count*sizeof(r[0]))) {
+ ret = -EFAULT;
+ goto out;
+ }
do {
u64 offset = r->presumed_offset;
- ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, r);
+ ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, r, &cache);
if (ret)
- return ret;
+ goto out;
if (r->presumed_offset != offset &&
- __put_user(r->presumed_offset, &user_relocs->presumed_offset)) {
- return -EFAULT;
+ __put_user(r->presumed_offset,
+ &user_relocs->presumed_offset)) {
+ ret = -EFAULT;
+ goto out;
}
user_relocs++;
@@ -602,7 +654,9 @@ i915_gem_execbuffer_relocate_vma(struct i915_vma *vma,
} while (--count);
}
- return 0;
+out:
+ reloc_cache_fini(&cache);
+ return ret;
#undef N_RELOC
}
@@ -612,15 +666,18 @@ i915_gem_execbuffer_relocate_vma_slow(struct i915_vma *vma,
struct drm_i915_gem_relocation_entry *relocs)
{
const struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
- int i, ret;
+ struct reloc_cache cache;
+ int i, ret = 0;
+ reloc_cache_init(&cache);
for (i = 0; i < entry->relocation_count; i++) {
- ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, &relocs[i]);
+ ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, &relocs[i], &cache);
if (ret)
- return ret;
+ break;
}
+ reloc_cache_fini(&cache);
- return 0;
+ return ret;
}
static int
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/9] drm/i915: Extract i915_gem_obj_prepare_shmem_write()
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
2016-08-10 11:54 ` [PATCH 1/9] drm/i915: Cache kmap between relocations Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 3/9] drm/i915: Before accessing an object via the cpu, flush GTT writes Chris Wilson
` (8 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
This is a companion to i915_gem_obj_prepare_shmem_read() that prepares
the backing storage for direct writes. It first serialises with the GPU,
pins the backing storage and then indicates what clfushes are required in
order for the writes to be coherent.
Whilst here, fix support for ancient CPUs without clflush for which we
cannot do the GTT+clflush tricks.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_cmd_parser.c | 2 +-
drivers/gpu/drm/i915/i915_drv.h | 6 +-
drivers/gpu/drm/i915/i915_gem.c | 142 +++++++++++++++++++--------------
3 files changed, 90 insertions(+), 60 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
index 1db829c8b912..c21cab7d1d61 100644
--- a/drivers/gpu/drm/i915/i915_cmd_parser.c
+++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
@@ -973,7 +973,7 @@ static u32 *copy_batch(struct drm_i915_gem_object *dest_obj,
u32 batch_start_offset,
u32 batch_len)
{
- int needs_clflush = 0;
+ unsigned int needs_clflush;
void *src_base, *src;
void *dst = NULL;
int ret;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 578eba0176ca..7124e952953b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3104,7 +3104,11 @@ void i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv);
void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
- int *needs_clflush);
+ unsigned int *needs_clflush);
+int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
+ unsigned int *needs_clflush);
+#define CLFLUSH_BEFORE 0x1
+#define CLFLUSH_AFTER 0x2
int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index e7d05ee29d7d..f2b330d3539c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -600,35 +600,95 @@ __copy_from_user_swizzled(char *gpu_vaddr, int gpu_offset,
* flush the object from the CPU cache.
*/
int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
- int *needs_clflush)
+ unsigned int *needs_clflush)
{
int ret;
*needs_clflush = 0;
- if (WARN_ON(!i915_gem_object_has_struct_page(obj)))
- return -EINVAL;
+ if (!i915_gem_object_has_struct_page(obj))
+ return -ENODEV;
ret = i915_gem_object_wait_rendering(obj, true);
if (ret)
return ret;
- if (!(obj->base.read_domains & I915_GEM_DOMAIN_CPU)) {
- /* If we're not in the cpu read domain, set ourself into the gtt
- * read domain and manually flush cachelines (if required). This
- * optimizes for the case when the gpu will dirty the data
- * anyway again before the next pread happens. */
+ /* If we're not in the cpu read domain, set ourself into the gtt
+ * read domain and manually flush cachelines (if required). This
+ * optimizes for the case when the gpu will dirty the data
+ * anyway again before the next pread happens.
+ */
+ if (!(obj->base.read_domains & I915_GEM_DOMAIN_CPU))
*needs_clflush = !cpu_cache_is_coherent(obj->base.dev,
obj->cache_level);
+
+ ret = i915_gem_object_get_pages(obj);
+ if (ret)
+ return ret;
+
+ i915_gem_object_pin_pages(obj);
+
+ if (*needs_clflush && !static_cpu_has(X86_FEATURE_CLFLUSH)) {
+ ret = i915_gem_object_set_to_cpu_domain(obj, false);
+ if (ret) {
+ i915_gem_object_unpin_pages(obj);
+ return ret;
+ }
+ *needs_clflush = 0;
}
+ return 0;
+}
+
+int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
+ unsigned int *needs_clflush)
+{
+ int ret;
+
+ *needs_clflush = 0;
+ if (!i915_gem_object_has_struct_page(obj))
+ return -ENODEV;
+
+ ret = i915_gem_object_wait_rendering(obj, false);
+ if (ret)
+ return ret;
+
+ /* If we're not in the cpu write domain, set ourself into the
+ * gtt write domain and manually flush cachelines (as required).
+ * This optimizes for the case when the gpu will use the data
+ * right away and we therefore have to clflush anyway.
+ */
+ if (obj->base.write_domain != I915_GEM_DOMAIN_CPU)
+ *needs_clflush |= cpu_write_needs_clflush(obj) << 1;
+
+ /* Same trick applies to invalidate partially written cachelines read
+ * before writing.
+ */
+ if (!(obj->base.read_domains & I915_GEM_DOMAIN_CPU))
+ *needs_clflush |= !cpu_cache_is_coherent(obj->base.dev,
+ obj->cache_level);
+
ret = i915_gem_object_get_pages(obj);
if (ret)
return ret;
i915_gem_object_pin_pages(obj);
- return ret;
+ if (*needs_clflush && !static_cpu_has(X86_FEATURE_CLFLUSH)) {
+ ret = i915_gem_object_set_to_cpu_domain(obj, true);
+ if (ret) {
+ i915_gem_object_unpin_pages(obj);
+ return ret;
+ }
+ *needs_clflush = 0;
+ }
+
+ if ((*needs_clflush & CLFLUSH_AFTER) == 0)
+ obj->cache_dirty = true;
+
+ intel_fb_obj_invalidate(obj, ORIGIN_CPU);
+ obj->dirty = 1;
+ return 0;
}
/* Per-page copy function for the shmem pread fastpath.
@@ -860,19 +920,14 @@ i915_gem_shmem_pread(struct drm_device *dev,
int needs_clflush = 0;
struct sg_page_iter sg_iter;
- if (!i915_gem_object_has_struct_page(obj))
- return -ENODEV;
-
- user_data = u64_to_user_ptr(args->data_ptr);
- remain = args->size;
-
- obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
-
ret = i915_gem_obj_prepare_shmem_read(obj, &needs_clflush);
if (ret)
return ret;
+ obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
+ user_data = u64_to_user_ptr(args->data_ptr);
offset = args->offset;
+ remain = args->size;
for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents,
offset >> PAGE_SHIFT) {
@@ -1233,42 +1288,17 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
int shmem_page_offset, page_length, ret = 0;
int obj_do_bit17_swizzling, page_do_bit17_swizzling;
int hit_slowpath = 0;
- int needs_clflush_after = 0;
- int needs_clflush_before = 0;
+ unsigned int needs_clflush;
struct sg_page_iter sg_iter;
- user_data = u64_to_user_ptr(args->data_ptr);
- remain = args->size;
-
- obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
-
- ret = i915_gem_object_wait_rendering(obj, false);
+ ret = i915_gem_obj_prepare_shmem_write(obj, &needs_clflush);
if (ret)
return ret;
- if (obj->base.write_domain != I915_GEM_DOMAIN_CPU) {
- /* If we're not in the cpu write domain, set ourself into the gtt
- * write domain and manually flush cachelines (if required). This
- * optimizes for the case when the gpu will use the data
- * right away and we therefore have to clflush anyway. */
- needs_clflush_after = cpu_write_needs_clflush(obj);
- }
- /* Same trick applies to invalidate partially written cachelines read
- * before writing. */
- if ((obj->base.read_domains & I915_GEM_DOMAIN_CPU) == 0)
- needs_clflush_before =
- !cpu_cache_is_coherent(dev, obj->cache_level);
-
- ret = i915_gem_object_get_pages(obj);
- if (ret)
- return ret;
-
- intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-
- i915_gem_object_pin_pages(obj);
-
+ obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
+ user_data = u64_to_user_ptr(args->data_ptr);
offset = args->offset;
- obj->dirty = 1;
+ remain = args->size;
for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents,
offset >> PAGE_SHIFT) {
@@ -1292,7 +1322,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
/* If we don't overwrite a cacheline completely we need to be
* careful to have up-to-date data by first clflushing. Don't
* overcomplicate things and flush the entire patch. */
- partial_cacheline_write = needs_clflush_before &&
+ partial_cacheline_write = needs_clflush & CLFLUSH_BEFORE &&
((shmem_page_offset | page_length)
& (boot_cpu_data.x86_clflush_size - 1));
@@ -1302,7 +1332,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
ret = shmem_pwrite_fast(page, shmem_page_offset, page_length,
user_data, page_do_bit17_swizzling,
partial_cacheline_write,
- needs_clflush_after);
+ needs_clflush & CLFLUSH_AFTER);
if (ret == 0)
goto next_page;
@@ -1311,7 +1341,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
ret = shmem_pwrite_slow(page, shmem_page_offset, page_length,
user_data, page_do_bit17_swizzling,
partial_cacheline_write,
- needs_clflush_after);
+ needs_clflush & CLFLUSH_AFTER);
mutex_lock(&dev->struct_mutex);
@@ -1333,17 +1363,15 @@ out:
* cachelines in-line while writing and the object moved
* out of the cpu write domain while we've dropped the lock.
*/
- if (!needs_clflush_after &&
+ if (!(needs_clflush & CLFLUSH_AFTER) &&
obj->base.write_domain != I915_GEM_DOMAIN_CPU) {
if (i915_gem_clflush_object(obj, obj->pin_display))
- needs_clflush_after = true;
+ needs_clflush |= CLFLUSH_AFTER;
}
}
- if (needs_clflush_after)
+ if (needs_clflush & CLFLUSH_AFTER)
i915_gem_chipset_flush(to_i915(dev));
- else
- obj->cache_dirty = true;
intel_fb_obj_flush(obj, false, ORIGIN_CPU);
return ret;
@@ -1422,10 +1450,8 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
if (ret == -EFAULT || ret == -ENOSPC) {
if (obj->phys_handle)
ret = i915_gem_phys_pwrite(obj, args, file);
- else if (i915_gem_object_has_struct_page(obj))
- ret = i915_gem_shmem_pwrite(dev, obj, args, file);
else
- ret = -ENODEV;
+ ret = i915_gem_shmem_pwrite(dev, obj, args, file);
}
i915_gem_object_put(obj);
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/9] drm/i915: Before accessing an object via the cpu, flush GTT writes
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
2016-08-10 11:54 ` [PATCH 1/9] drm/i915: Cache kmap between relocations Chris Wilson
2016-08-10 11:54 ` [PATCH 2/9] drm/i915: Extract i915_gem_obj_prepare_shmem_write() Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 4/9] drm/i915: Wait for writes through the GTT to land before reading back Chris Wilson
` (7 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
If we want to read the pages directly via the CPU, we have to be sure
that we have to flush the writes via the GTT (as the CPU can not see
the address aliasing).
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index f2b330d3539c..887dc33ae6d4 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -613,6 +613,8 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
if (ret)
return ret;
+ i915_gem_object_flush_gtt_write_domain(obj);
+
/* If we're not in the cpu read domain, set ourself into the gtt
* read domain and manually flush cachelines (if required). This
* optimizes for the case when the gpu will dirty the data
@@ -653,6 +655,8 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
if (ret)
return ret;
+ i915_gem_object_flush_gtt_write_domain(obj);
+
/* If we're not in the cpu write domain, set ourself into the
* gtt write domain and manually flush cachelines (as required).
* This optimizes for the case when the gpu will use the data
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/9] drm/i915: Wait for writes through the GTT to land before reading back
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (2 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 3/9] drm/i915: Before accessing an object via the cpu, flush GTT writes Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 5/9] drm/i915: Pin the pages first in shmem prepare read/write Chris Wilson
` (6 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
If we quickly switch from writing through the GTT to a read of the
physical page directly with the CPU (e.g. performing relocations through
the GTT and then running the command parser), we can observe that the
writes are not visible to the CPU. It is not a coherency problem, as
extensive investigations with clflush have demonstrated, but a mere
timing issue - we have to wait for the GTT to complete it's write before
we start our read from the CPU.
The issue can be illustrated in userspace with:
gtt = gem_mmap__gtt(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
cpu = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
for (i = 0; i < OBJECT_SIZE / 64; i++) {
int x = 16*i + (i%16);
gtt[x] = i;
clflush(&cpu[x], sizeof(cpu[x]));
assert(cpu[x] == i);
}
Experimenting with that shows that this behaviour is indeed limited to
recent Atom-class hardware.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 887dc33ae6d4..da4b266fce72 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3113,20 +3113,30 @@ i915_gem_clflush_object(struct drm_i915_gem_object *obj,
static void
i915_gem_object_flush_gtt_write_domain(struct drm_i915_gem_object *obj)
{
+ struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
uint32_t old_write_domain;
if (obj->base.write_domain != I915_GEM_DOMAIN_GTT)
return;
/* No actual flushing is required for the GTT write domain. Writes
- * to it immediately go to main memory as far as we know, so there's
+ * to it "immediately" go to main memory as far as we know, so there's
* no chipset flush. It also doesn't land in render cache.
*
* However, we do have to enforce the order so that all writes through
* the GTT land before any writes to the device, such as updates to
* the GATT itself.
+ *
+ * We also have to wait a bit for the writes to land from the GTT.
+ * An uncached read (i.e. mmio) seems to be ideal for the round-trip
+ * timing. This issue has only been observed when switching quickly
+ * between GTT writes and CPU reads from inside the kernel on recent hw,
+ * and it appears to only affect discrete GTT blocks (i.e. on LLC
+ * system agents we cannot reproduce this behaviour).
*/
wmb();
+ if (INTEL_GEN(dev_priv) >= 6 && !HAS_LLC(dev_priv))
+ POSTING_READ(RING_ACTHD(dev_priv->engine[RCS].mmio_base));
old_write_domain = obj->base.write_domain;
obj->base.write_domain = 0;
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/9] drm/i915: Pin the pages first in shmem prepare read/write
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (3 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 4/9] drm/i915: Wait for writes through the GTT to land before reading back Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 6/9] drm/i915: Tidy up flush cpu/gtt write domains Chris Wilson
` (5 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
There is an improbable, but not impossible, case that if we leave the
pages unpin as we operate on the object, then somebody may steal the
lock and change the cache domains after we have already inspected them.
(Whilst here, avail ourselves of the opportunity to take a couple of
steps to make the two functions look more similar.)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 48 ++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index da4b266fce72..e18f0d2df883 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -613,6 +613,12 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
if (ret)
return ret;
+ ret = i915_gem_object_get_pages(obj);
+ if (ret)
+ return ret;
+
+ i915_gem_object_pin_pages(obj);
+
i915_gem_object_flush_gtt_write_domain(obj);
/* If we're not in the cpu read domain, set ourself into the gtt
@@ -624,22 +630,20 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
*needs_clflush = !cpu_cache_is_coherent(obj->base.dev,
obj->cache_level);
- ret = i915_gem_object_get_pages(obj);
- if (ret)
- return ret;
-
- i915_gem_object_pin_pages(obj);
-
if (*needs_clflush && !static_cpu_has(X86_FEATURE_CLFLUSH)) {
ret = i915_gem_object_set_to_cpu_domain(obj, false);
- if (ret) {
- i915_gem_object_unpin_pages(obj);
- return ret;
- }
+ if (ret)
+ goto err_unpin;
+
*needs_clflush = 0;
}
+ /* return with the pages pinned */
return 0;
+
+err_unpin:
+ i915_gem_object_unpin_pages(obj);
+ return ret;
}
int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
@@ -655,6 +659,12 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
if (ret)
return ret;
+ ret = i915_gem_object_get_pages(obj);
+ if (ret)
+ return ret;
+
+ i915_gem_object_pin_pages(obj);
+
i915_gem_object_flush_gtt_write_domain(obj);
/* If we're not in the cpu write domain, set ourself into the
@@ -672,18 +682,11 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
*needs_clflush |= !cpu_cache_is_coherent(obj->base.dev,
obj->cache_level);
- ret = i915_gem_object_get_pages(obj);
- if (ret)
- return ret;
-
- i915_gem_object_pin_pages(obj);
-
if (*needs_clflush && !static_cpu_has(X86_FEATURE_CLFLUSH)) {
ret = i915_gem_object_set_to_cpu_domain(obj, true);
- if (ret) {
- i915_gem_object_unpin_pages(obj);
- return ret;
- }
+ if (ret)
+ goto err_unpin;
+
*needs_clflush = 0;
}
@@ -692,7 +695,12 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
intel_fb_obj_invalidate(obj, ORIGIN_CPU);
obj->dirty = 1;
+ /* return with the pages pinned */
return 0;
+
+err_unpin:
+ i915_gem_object_unpin_pages(obj);
+ return ret;
}
/* Per-page copy function for the shmem pread fastpath.
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 6/9] drm/i915: Tidy up flush cpu/gtt write domains
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (4 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 5/9] drm/i915: Pin the pages first in shmem prepare read/write Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 7/9] drm/i915: Refactor execbuffer relocation writing Chris Wilson
` (4 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
Since we know the write domain, we can drop the local variable and make
the code look a tiny bit simpler.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index e18f0d2df883..e71512bf1599 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3122,7 +3122,6 @@ static void
i915_gem_object_flush_gtt_write_domain(struct drm_i915_gem_object *obj)
{
struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
- uint32_t old_write_domain;
if (obj->base.write_domain != I915_GEM_DOMAIN_GTT)
return;
@@ -3146,36 +3145,30 @@ i915_gem_object_flush_gtt_write_domain(struct drm_i915_gem_object *obj)
if (INTEL_GEN(dev_priv) >= 6 && !HAS_LLC(dev_priv))
POSTING_READ(RING_ACTHD(dev_priv->engine[RCS].mmio_base));
- old_write_domain = obj->base.write_domain;
- obj->base.write_domain = 0;
-
intel_fb_obj_flush(obj, false, ORIGIN_GTT);
+ obj->base.write_domain = 0;
trace_i915_gem_object_change_domain(obj,
obj->base.read_domains,
- old_write_domain);
+ I915_GEM_DOMAIN_GTT);
}
/** Flushes the CPU write domain for the object if it's dirty. */
static void
i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj)
{
- uint32_t old_write_domain;
-
if (obj->base.write_domain != I915_GEM_DOMAIN_CPU)
return;
if (i915_gem_clflush_object(obj, obj->pin_display))
i915_gem_chipset_flush(to_i915(obj->base.dev));
- old_write_domain = obj->base.write_domain;
- obj->base.write_domain = 0;
-
intel_fb_obj_flush(obj, false, ORIGIN_CPU);
+ obj->base.write_domain = 0;
trace_i915_gem_object_change_domain(obj,
obj->base.read_domains,
- old_write_domain);
+ I915_GEM_DOMAIN_CPU);
}
/**
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 7/9] drm/i915: Refactor execbuffer relocation writing
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (5 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 6/9] drm/i915: Tidy up flush cpu/gtt write domains Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 8/9] drm/i915: Fallback to single page GTT mmappings for relocations Chris Wilson
` (3 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
With in the introduction of the reloc page cache, we are just one step
away from refactoring the relocation write functions into one. Not only
does it tidy the code (slightly), but it greatly simplifies the control
logic much to gcc's satisfaction.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 293 +++++++++++++++--------------
1 file changed, 151 insertions(+), 142 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 5caa7ba55cf5..e01c59917a01 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -39,6 +39,8 @@
#include "intel_drv.h"
#include "intel_frontbuffer.h"
+#define DBG_USE_CPU_RELOC 0 /* force relocations to use the CPU write path */
+
#define __EXEC_OBJECT_HAS_PIN (1<<31)
#define __EXEC_OBJECT_HAS_FENCE (1<<30)
#define __EXEC_OBJECT_NEEDS_MAP (1<<29)
@@ -59,6 +61,7 @@ struct i915_execbuffer_params {
};
struct eb_vmas {
+ struct drm_i915_private *i915;
struct list_head vmas;
int and;
union {
@@ -68,7 +71,8 @@ struct eb_vmas {
};
static struct eb_vmas *
-eb_create(struct drm_i915_gem_execbuffer2 *args)
+eb_create(struct drm_i915_private *i915,
+ struct drm_i915_gem_execbuffer2 *args)
{
struct eb_vmas *eb = NULL;
@@ -95,6 +99,7 @@ eb_create(struct drm_i915_gem_execbuffer2 *args)
} else
eb->and = -args->buffer_count;
+ eb->i915 = i915;
INIT_LIST_HEAD(&eb->vmas);
return eb;
}
@@ -278,6 +283,9 @@ static void eb_destroy(struct eb_vmas *eb)
static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
{
+ if (DBG_USE_CPU_RELOC)
+ return DBG_USE_CPU_RELOC > 0;
+
return (HAS_LLC(obj->base.dev) ||
obj->base.write_domain == I915_GEM_DOMAIN_CPU ||
obj->cache_level != I915_CACHE_NONE);
@@ -302,37 +310,58 @@ static inline uint64_t gen8_noncanonical_addr(uint64_t address)
}
static inline uint64_t
-relocation_target(struct drm_i915_gem_relocation_entry *reloc,
+relocation_target(const struct drm_i915_gem_relocation_entry *reloc,
uint64_t target_offset)
{
return gen8_canonical_addr((int)reloc->delta + target_offset);
}
struct reloc_cache {
- void *vaddr;
+ struct drm_i915_private *i915;
+ struct drm_mm_node node;
+ unsigned long vaddr;
unsigned int page;
- enum { KMAP, IOMAP } type;
+ bool use_64bit_reloc;
};
-static void reloc_cache_init(struct reloc_cache *cache)
+static void reloc_cache_init(struct reloc_cache *cache,
+ struct drm_i915_private *i915)
{
cache->page = -1;
- cache->vaddr = NULL;
+ cache->vaddr = 0;
+ cache->i915 = i915;
+ cache->use_64bit_reloc = INTEL_GEN(cache->i915) >= 8;
+}
+
+static inline void *unmask_page(unsigned long p)
+{
+ return (void *)(uintptr_t)(p & PAGE_MASK);
+}
+
+static inline unsigned int unmask_flags(unsigned long p)
+{
+ return p & ~PAGE_MASK;
}
+#define KMAP 0x4
+
static void reloc_cache_fini(struct reloc_cache *cache)
{
+ void *vaddr;
+
if (!cache->vaddr)
return;
- switch (cache->type) {
- case KMAP:
- kunmap_atomic(cache->vaddr);
- break;
+ vaddr = unmask_page(cache->vaddr);
+ if (cache->vaddr & KMAP) {
+ if (cache->vaddr & CLFLUSH_AFTER)
+ mb();
- case IOMAP:
- io_mapping_unmap_atomic(cache->vaddr);
- break;
+ kunmap_atomic(vaddr);
+ i915_gem_object_unpin_pages((struct drm_i915_gem_object *)cache->node.mm);
+ } else {
+ io_mapping_unmap_atomic(vaddr);
+ i915_vma_unpin((struct i915_vma *)cache->node.mm);
}
}
@@ -340,148 +369,139 @@ static void *reloc_kmap(struct drm_i915_gem_object *obj,
struct reloc_cache *cache,
int page)
{
- if (cache->page == page)
- return cache->vaddr;
+ void *vaddr;
- if (cache->vaddr)
- kunmap_atomic(cache->vaddr);
+ if (cache->vaddr) {
+ kunmap_atomic(unmask_page(cache->vaddr));
+ } else {
+ unsigned int flushes;
+ int ret;
+ ret = i915_gem_obj_prepare_shmem_write(obj, &flushes);
+ if (ret)
+ return ERR_PTR(ret);
+
+ cache->vaddr = flushes | KMAP;
+ cache->node.mm = (void *)obj;
+ if (flushes)
+ mb();
+ }
+
+ vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, page));
+ cache->vaddr = unmask_flags(cache->vaddr) | (unsigned long)vaddr;
cache->page = page;
- cache->vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, page));
- cache->type = KMAP;
- return cache->vaddr;
+ return vaddr;
}
-static int
-relocate_entry_cpu(struct drm_i915_gem_object *obj,
- struct drm_i915_gem_relocation_entry *reloc,
- struct reloc_cache *cache,
- uint64_t target_offset)
+static void *reloc_iomap(struct drm_i915_gem_object *obj,
+ struct reloc_cache *cache,
+ int page)
{
- struct drm_device *dev = obj->base.dev;
- uint32_t page_offset = offset_in_page(reloc->offset);
- uint64_t delta = relocation_target(reloc, target_offset);
- char *vaddr;
- int ret;
+ void *vaddr;
- ret = i915_gem_object_set_to_cpu_domain(obj, true);
- if (ret)
- return ret;
+ if (cache->vaddr) {
+ io_mapping_unmap_atomic(unmask_page(cache->vaddr));
+ } else {
+ struct i915_vma *vma;
+ int ret;
- vaddr = reloc_kmap(obj, cache, reloc->offset >> PAGE_SHIFT);
- *(uint32_t *)(vaddr + page_offset) = lower_32_bits(delta);
+ if (use_cpu_reloc(obj))
+ return NULL;
- if (INTEL_GEN(dev) >= 8) {
- page_offset += sizeof(uint32_t);
- if (page_offset == PAGE_SIZE) {
- vaddr = reloc_kmap(obj, cache, cache->page + 1);
- page_offset = 0;
- }
- *(uint32_t *)(vaddr + page_offset) = upper_32_bits(delta);
- }
+ ret = i915_gem_object_set_to_gtt_domain(obj, true);
+ if (ret)
+ return ERR_PTR(ret);
- return 0;
-}
+ vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
+ PIN_MAPPABLE | PIN_NONBLOCK);
+ if (IS_ERR(vma))
+ return NULL;
-static void *reloc_iomap(struct drm_i915_private *i915,
- struct reloc_cache *cache,
- uint64_t offset)
-{
- if (cache->page == offset >> PAGE_SHIFT)
- return cache->vaddr;
+ ret = i915_gem_object_put_fence(obj);
+ if (ret) {
+ i915_vma_unpin(vma);
+ return ERR_PTR(ret);
+ }
- if (cache->vaddr)
- io_mapping_unmap_atomic(cache->vaddr);
+ cache->node.start = vma->node.start;
+ cache->node.mm = (void *)vma;
+ }
- cache->page = offset >> PAGE_SHIFT;
- cache->vaddr =
- io_mapping_map_atomic_wc(i915->ggtt.mappable,
- offset & PAGE_MASK);
- cache->type = IOMAP;
+ vaddr = io_mapping_map_atomic_wc(cache->i915->ggtt.mappable,
+ cache->node.start + (page << PAGE_SHIFT));
+ cache->page = page;
+ cache->vaddr = (unsigned long)vaddr;
- return cache->vaddr;
+ return vaddr;
}
-static int
-relocate_entry_gtt(struct drm_i915_gem_object *obj,
- struct drm_i915_gem_relocation_entry *reloc,
- struct reloc_cache *cache,
- uint64_t target_offset)
+static void *reloc_vaddr(struct drm_i915_gem_object *obj,
+ struct reloc_cache *cache,
+ int page)
{
- struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
- struct i915_vma *vma;
- uint64_t delta = relocation_target(reloc, target_offset);
- uint64_t offset;
- void __iomem *reloc_page;
- int ret;
-
- vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
- if (IS_ERR(vma))
- return PTR_ERR(vma);
-
- ret = i915_gem_object_set_to_gtt_domain(obj, true);
- if (ret)
- goto unpin;
-
- ret = i915_gem_object_put_fence(obj);
- if (ret)
- goto unpin;
-
- /* Map the page containing the relocation we're going to perform. */
- offset = vma->node.start;
- offset += reloc->offset;
- reloc_page = reloc_iomap(dev_priv, cache, offset);
- iowrite32(lower_32_bits(delta), reloc_page + offset_in_page(offset));
+ void *vaddr;
- if (INTEL_GEN(dev_priv) >= 8) {
- offset += sizeof(uint32_t);
- if (offset_in_page(offset) == 0)
- reloc_page = reloc_iomap(dev_priv, cache, offset);
- iowrite32(upper_32_bits(delta),
- reloc_page + offset_in_page(offset));
+ if (cache->page == page) {
+ vaddr = unmask_page(cache->vaddr);
+ } else {
+ vaddr = NULL;
+ if ((cache->vaddr & KMAP) == 0)
+ vaddr = reloc_iomap(obj, cache, page);
+ if (!vaddr)
+ vaddr = reloc_kmap(obj, cache, page);
}
-unpin:
- __i915_vma_unpin(vma);
- return ret;
+ return vaddr;
}
-static void
-clflush_write32(void *addr, uint32_t value)
+static void clflush_write32(u32 *addr, u32 value, unsigned int flushes)
{
- /* This is not a fast path, so KISS. */
- drm_clflush_virt_range(addr, sizeof(uint32_t));
- *(uint32_t *)addr = value;
- drm_clflush_virt_range(addr, sizeof(uint32_t));
+ if (unlikely(flushes & (CLFLUSH_BEFORE | CLFLUSH_AFTER))) {
+ if (flushes & CLFLUSH_BEFORE) {
+ clflushopt(addr);
+ mb();
+ }
+
+ *addr = value;
+
+ /* Writes to the same cacheline are serialised by the CPU
+ * (including clflush). On the write path, we only require
+ * that it hits memory in an orderly fashion and place
+ * mb barriers at the start and end of the relocation phase
+ * to ensure ordering of clflush wrt to the system.
+ */
+ if (flushes & CLFLUSH_AFTER)
+ clflushopt(addr);
+ } else
+ *addr = value;
}
static int
-relocate_entry_clflush(struct drm_i915_gem_object *obj,
- struct drm_i915_gem_relocation_entry *reloc,
- struct reloc_cache *cache,
- uint64_t target_offset)
+relocate_entry(struct drm_i915_gem_object *obj,
+ const struct drm_i915_gem_relocation_entry *reloc,
+ struct reloc_cache *cache,
+ u64 target_offset)
{
- struct drm_device *dev = obj->base.dev;
- uint32_t page_offset = offset_in_page(reloc->offset);
- uint64_t delta = relocation_target(reloc, target_offset);
- char *vaddr;
- int ret;
+ u64 offset = reloc->offset;
+ bool wide = cache->use_64bit_reloc;
+ void *vaddr;
- ret = i915_gem_object_set_to_gtt_domain(obj, true);
- if (ret)
- return ret;
+ target_offset = relocation_target(reloc, target_offset);
+repeat:
+ vaddr = reloc_vaddr(obj, cache, offset >> PAGE_SHIFT);
+ if (IS_ERR(vaddr))
+ return PTR_ERR(vaddr);
- vaddr = reloc_kmap(obj, cache, reloc->offset >> PAGE_SHIFT);
- clflush_write32(vaddr + page_offset, lower_32_bits(delta));
+ clflush_write32(vaddr + offset_in_page(offset),
+ lower_32_bits(target_offset),
+ cache->vaddr);
- if (INTEL_GEN(dev) >= 8) {
- page_offset += sizeof(uint32_t);
- if (page_offset == PAGE_SIZE) {
- vaddr = reloc_kmap(obj, cache, cache->page + 1);
- page_offset = 0;
- }
- clflush_write32(vaddr + page_offset, upper_32_bits(delta));
+ if (wide) {
+ offset += sizeof(u32);
+ target_offset >>= 32;
+ wide = false;
+ goto repeat;
}
return 0;
@@ -568,7 +588,7 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
/* Check that the relocation address is valid... */
if (unlikely(reloc->offset >
- obj->base.size - (INTEL_INFO(dev)->gen >= 8 ? 8 : 4))) {
+ obj->base.size - (cache->use_64bit_reloc ? 8 : 4))) {
DRM_DEBUG("Relocation beyond object bounds: "
"obj %p target %d offset %d size %d.\n",
obj, reloc->target_handle,
@@ -588,23 +608,12 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
if (pagefault_disabled() && !object_is_idle(obj))
return -EFAULT;
- if (use_cpu_reloc(obj))
- ret = relocate_entry_cpu(obj, reloc, cache, target_offset);
- else if (obj->map_and_fenceable)
- ret = relocate_entry_gtt(obj, reloc, cache, target_offset);
- else if (static_cpu_has(X86_FEATURE_CLFLUSH))
- ret = relocate_entry_clflush(obj, reloc, cache, target_offset);
- else {
- WARN_ONCE(1, "Impossible case in relocation handling\n");
- ret = -ENODEV;
- }
-
+ ret = relocate_entry(obj, reloc, cache, target_offset);
if (ret)
return ret;
/* and update the user's relocation entry */
reloc->presumed_offset = target_offset;
-
return 0;
}
@@ -620,7 +629,7 @@ i915_gem_execbuffer_relocate_vma(struct i915_vma *vma,
int remain, ret = 0;
user_relocs = u64_to_user_ptr(entry->relocs_ptr);
- reloc_cache_init(&cache);
+ reloc_cache_init(&cache, eb->i915);
remain = entry->relocation_count;
while (remain) {
@@ -669,7 +678,7 @@ i915_gem_execbuffer_relocate_vma_slow(struct i915_vma *vma,
struct reloc_cache cache;
int i, ret = 0;
- reloc_cache_init(&cache);
+ reloc_cache_init(&cache, eb->i915);
for (i = 0; i < entry->relocation_count; i++) {
ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, &relocs[i], &cache);
if (ret)
@@ -1095,8 +1104,8 @@ i915_gem_execbuffer_move_to_gpu(struct drm_i915_gem_request *req,
if (flush_chipset)
i915_gem_chipset_flush(req->engine->i915);
- if (flush_domains & I915_GEM_DOMAIN_GTT)
- wmb();
+ /* Make sure (untracked) CPU relocs/parsing are flushed */
+ wmb();
/* Unconditionally invalidate GPU caches and TLBs. */
return req->engine->emit_flush(req, EMIT_INVALIDATE);
@@ -1657,7 +1666,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
memset(¶ms_master, 0x00, sizeof(params_master));
- eb = eb_create(args);
+ eb = eb_create(dev_priv, args);
if (eb == NULL) {
i915_gem_context_put(ctx);
mutex_unlock(&dev->struct_mutex);
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 8/9] drm/i915: Fallback to single page GTT mmappings for relocations
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (6 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 7/9] drm/i915: Refactor execbuffer relocation writing Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 11:54 ` [PATCH 9/9] drm/i915: Disallow direct CPU access to stolen pages " Chris Wilson
` (2 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
If we cannot pin the entire object into the mappable region of the GTT,
try to pin a single page instead. This is much more likely to succeed,
and prevents us falling back to the clflush slow path.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 61 ++++++++++++++++++++++++------
1 file changed, 50 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index e01c59917a01..aef7408f7fbd 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -331,6 +331,7 @@ static void reloc_cache_init(struct reloc_cache *cache,
cache->vaddr = 0;
cache->i915 = i915;
cache->use_64bit_reloc = INTEL_GEN(cache->i915) >= 8;
+ cache->node.allocated = false;
}
static inline void *unmask_page(unsigned long p)
@@ -360,8 +361,18 @@ static void reloc_cache_fini(struct reloc_cache *cache)
kunmap_atomic(vaddr);
i915_gem_object_unpin_pages((struct drm_i915_gem_object *)cache->node.mm);
} else {
+ wmb();
io_mapping_unmap_atomic(vaddr);
- i915_vma_unpin((struct i915_vma *)cache->node.mm);
+ if (cache->node.allocated) {
+ struct i915_ggtt *ggtt = &cache->i915->ggtt;
+
+ ggtt->base.clear_range(&ggtt->base,
+ cache->node.start,
+ cache->node.size,
+ true);
+ drm_mm_remove_node(&cache->node);
+ } else
+ i915_vma_unpin((struct i915_vma *)cache->node.mm);
}
}
@@ -398,8 +409,19 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,
struct reloc_cache *cache,
int page)
{
+ struct i915_ggtt *ggtt = &cache->i915->ggtt;
+ unsigned long offset;
void *vaddr;
+ if (cache->node.allocated) {
+ wmb();
+ ggtt->base.insert_page(&ggtt->base,
+ i915_gem_object_get_dma_address(obj, page),
+ cache->node.start, I915_CACHE_NONE, 0);
+ cache->page = page;
+ return unmask_page(cache->vaddr);
+ }
+
if (cache->vaddr) {
io_mapping_unmap_atomic(unmask_page(cache->vaddr));
} else {
@@ -415,21 +437,38 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,
vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
PIN_MAPPABLE | PIN_NONBLOCK);
- if (IS_ERR(vma))
- return NULL;
+ if (IS_ERR(vma)) {
+ memset(&cache->node, 0, sizeof(cache->node));
+ ret = drm_mm_insert_node_in_range_generic
+ (&ggtt->base.mm, &cache->node,
+ 4096, 0, 0,
+ 0, ggtt->mappable_end,
+ DRM_MM_SEARCH_DEFAULT,
+ DRM_MM_CREATE_DEFAULT);
+ if (ret)
+ return ERR_PTR(ret);
+ } else {
+ ret = i915_gem_object_put_fence(obj);
+ if (ret) {
+ i915_vma_unpin(vma);
+ return ERR_PTR(ret);
+ }
- ret = i915_gem_object_put_fence(obj);
- if (ret) {
- i915_vma_unpin(vma);
- return ERR_PTR(ret);
+ cache->node.start = vma->node.start;
+ cache->node.mm = (void *)vma;
}
+ }
- cache->node.start = vma->node.start;
- cache->node.mm = (void *)vma;
+ offset = cache->node.start;
+ if (cache->node.allocated) {
+ ggtt->base.insert_page(&ggtt->base,
+ i915_gem_object_get_dma_address(obj, page),
+ offset, I915_CACHE_NONE, 0);
+ } else {
+ offset += page << PAGE_SHIFT;
}
- vaddr = io_mapping_map_atomic_wc(cache->i915->ggtt.mappable,
- cache->node.start + (page << PAGE_SHIFT));
+ vaddr = io_mapping_map_atomic_wc(cache->i915->ggtt.mappable, offset);
cache->page = page;
cache->vaddr = (unsigned long)vaddr;
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 9/9] drm/i915: Disallow direct CPU access to stolen pages for relocations
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (7 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 8/9] drm/i915: Fallback to single page GTT mmappings for relocations Chris Wilson
@ 2016-08-10 11:54 ` Chris Wilson
2016-08-10 12:32 ` ✗ Ro.CI.BAT: failure for series starting with [1/9] drm/i915: Cache kmap between relocations Patchwork
2016-08-12 10:01 ` Small execbuf coherency fixes Joonas Lahtinen
10 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-10 11:54 UTC (permalink / raw)
To: intel-gfx; +Cc: mika.kuoppala
As we cannot access the backing pages behind stolen objects, we should
not attempt to do so for relocations.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index aef7408f7fbd..d12336dac0b0 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -283,6 +283,9 @@ static void eb_destroy(struct eb_vmas *eb)
static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
{
+ if (!i915_gem_object_has_struct_page(obj))
+ return false;
+
if (DBG_USE_CPU_RELOC)
return DBG_USE_CPU_RELOC > 0;
--
2.8.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 13+ messages in thread
* ✗ Ro.CI.BAT: failure for series starting with [1/9] drm/i915: Cache kmap between relocations
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (8 preceding siblings ...)
2016-08-10 11:54 ` [PATCH 9/9] drm/i915: Disallow direct CPU access to stolen pages " Chris Wilson
@ 2016-08-10 12:32 ` Patchwork
2016-08-12 10:01 ` Small execbuf coherency fixes Joonas Lahtinen
10 siblings, 0 replies; 13+ messages in thread
From: Patchwork @ 2016-08-10 12:32 UTC (permalink / raw)
To: Chris Wilson; +Cc: intel-gfx
== Series Details ==
Series: series starting with [1/9] drm/i915: Cache kmap between relocations
URL : https://patchwork.freedesktop.org/series/10904/
State : failure
== Summary ==
Applying: drm/i915: Cache kmap between relocations
fatal: sha1 information is lacking or useless (drivers/gpu/drm/i915/i915_gem_execbuffer.c).
error: could not build fake ancestor
Patch failed at 0001 drm/i915: Cache kmap between relocations
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Small execbuf coherency fixes
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
` (9 preceding siblings ...)
2016-08-10 12:32 ` ✗ Ro.CI.BAT: failure for series starting with [1/9] drm/i915: Cache kmap between relocations Patchwork
@ 2016-08-12 10:01 ` Joonas Lahtinen
2016-08-12 10:41 ` Chris Wilson
10 siblings, 1 reply; 13+ messages in thread
From: Joonas Lahtinen @ 2016-08-12 10:01 UTC (permalink / raw)
To: Chris Wilson, intel-gfx; +Cc: mika.kuoppala
On ke, 2016-08-10 at 12:54 +0100, Chris Wilson wrote:
> Execbuf suffers from a coherency problem which in theory is handled by
> the prepare for direct access implemented by pwrite. The issue being not
> only is that function non-existent (implemented inline for pwrite) it is
> missing a barrier or two.
I already provided review feedback for this series, so after that is
applied I'll proceed to review. Don't forget to CC me.
Regards, Joonas
> -Chris
>
--
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Small execbuf coherency fixes
2016-08-12 10:01 ` Small execbuf coherency fixes Joonas Lahtinen
@ 2016-08-12 10:41 ` Chris Wilson
0 siblings, 0 replies; 13+ messages in thread
From: Chris Wilson @ 2016-08-12 10:41 UTC (permalink / raw)
To: Joonas Lahtinen; +Cc: intel-gfx, mika.kuoppala
On Fri, Aug 12, 2016 at 01:01:37PM +0300, Joonas Lahtinen wrote:
> On ke, 2016-08-10 at 12:54 +0100, Chris Wilson wrote:
> > Execbuf suffers from a coherency problem which in theory is handled by
> > the prepare for direct access implemented by pwrite. The issue being not
> > only is that function non-existent (implemented inline for pwrite) it is
> > missing a barrier or two.
>
> I already provided review feedback for this series, so after that is
> applied I'll proceed to review. Don't forget to CC me.
Just added the r-b tags. I did not agree with the minor changes in the
context of the larger series.
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2016-08-12 10:41 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-10 11:54 Small execbuf coherency fixes Chris Wilson
2016-08-10 11:54 ` [PATCH 1/9] drm/i915: Cache kmap between relocations Chris Wilson
2016-08-10 11:54 ` [PATCH 2/9] drm/i915: Extract i915_gem_obj_prepare_shmem_write() Chris Wilson
2016-08-10 11:54 ` [PATCH 3/9] drm/i915: Before accessing an object via the cpu, flush GTT writes Chris Wilson
2016-08-10 11:54 ` [PATCH 4/9] drm/i915: Wait for writes through the GTT to land before reading back Chris Wilson
2016-08-10 11:54 ` [PATCH 5/9] drm/i915: Pin the pages first in shmem prepare read/write Chris Wilson
2016-08-10 11:54 ` [PATCH 6/9] drm/i915: Tidy up flush cpu/gtt write domains Chris Wilson
2016-08-10 11:54 ` [PATCH 7/9] drm/i915: Refactor execbuffer relocation writing Chris Wilson
2016-08-10 11:54 ` [PATCH 8/9] drm/i915: Fallback to single page GTT mmappings for relocations Chris Wilson
2016-08-10 11:54 ` [PATCH 9/9] drm/i915: Disallow direct CPU access to stolen pages " Chris Wilson
2016-08-10 12:32 ` ✗ Ro.CI.BAT: failure for series starting with [1/9] drm/i915: Cache kmap between relocations Patchwork
2016-08-12 10:01 ` Small execbuf coherency fixes Joonas Lahtinen
2016-08-12 10:41 ` Chris Wilson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.