Skip to content

Commit

Permalink
drm/i915: Combine all i915_vma bitfields into a single set of flags
Browse files Browse the repository at this point in the history
In preparation to perform some magic to speed up i915_vma_pin(), which
is among the hottest of hot paths in execbuf, refactor all the bitfields
accessed by i915_vma_pin() into a single unified set of flags.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1470324762-2545-16-git-send-email-chris@chris-wilson.co.uk
  • Loading branch information
Chris Wilson committed Aug 4, 2016
1 parent 59bfa12 commit 3272db5
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 74 deletions.
8 changes: 4 additions & 4 deletions drivers/gpu/drm/i915/i915_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
struct i915_vma *vma;

list_for_each_entry(vma, &obj->vma_list, obj_link) {
if (vma->is_ggtt && drm_mm_node_allocated(&vma->node))
if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
size += vma->node.size;
}

Expand Down Expand Up @@ -181,9 +181,9 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
continue;

seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
vma->is_ggtt ? "g" : "pp",
i915_vma_is_ggtt(vma) ? "g" : "pp",
vma->node.start, vma->node.size);
if (vma->is_ggtt)
if (i915_vma_is_ggtt(vma))
seq_printf(m, ", type: %u", vma->ggtt_view.type);
seq_puts(m, ")");
}
Expand Down Expand Up @@ -356,7 +356,7 @@ static int per_file_stats(int id, void *ptr, void *data)
if (!drm_mm_node_allocated(&vma->node))
continue;

if (vma->is_ggtt) {
if (i915_vma_is_ggtt(vma)) {
stats->global += vma->node.size;
} else {
struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Expand Down
40 changes: 22 additions & 18 deletions drivers/gpu/drm/i915/i915_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,8 @@ int i915_vma_unbind(struct i915_vma *vma)
GEM_BUG_ON(obj->bind_count == 0);
GEM_BUG_ON(!obj->pages);

if (vma->is_ggtt && vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
if (i915_vma_is_ggtt(vma) &&
vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
i915_gem_object_finish_gtt(obj);

/* release the fence reg _after_ flushing */
Expand All @@ -2876,12 +2877,12 @@ int i915_vma_unbind(struct i915_vma *vma)
trace_i915_vma_unbind(vma);
vma->vm->unbind_vma(vma);
}
vma->bound = 0;
vma->flags &= ~(I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND);

drm_mm_remove_node(&vma->node);
list_move_tail(&vma->vm_link, &vma->vm->unbound_list);

if (vma->is_ggtt) {
if (i915_vma_is_ggtt(vma)) {
if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
obj->map_and_fenceable = false;
} else if (vma->ggtt_view.pages) {
Expand All @@ -2904,7 +2905,7 @@ int i915_vma_unbind(struct i915_vma *vma)
i915_gem_object_unpin_pages(obj);

destroy:
if (unlikely(vma->closed))
if (unlikely(i915_vma_is_closed(vma)))
i915_vma_destroy(vma);

return 0;
Expand Down Expand Up @@ -2985,7 +2986,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
u64 min_alignment;
int ret;

GEM_BUG_ON(vma->bound);
GEM_BUG_ON(vma->flags & (I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND));
GEM_BUG_ON(drm_mm_node_allocated(&vma->node));

size = max(size, vma->size);
Expand Down Expand Up @@ -3707,21 +3708,22 @@ void __i915_vma_set_map_and_fenceable(struct i915_vma *vma)
int
i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
{
unsigned int bound = vma->bound;
unsigned int bound;
int ret;

GEM_BUG_ON((flags & (PIN_GLOBAL | PIN_USER)) == 0);
GEM_BUG_ON((flags & PIN_GLOBAL) && !vma->is_ggtt);
GEM_BUG_ON((flags & PIN_GLOBAL) && !i915_vma_is_ggtt(vma));

if (WARN_ON(i915_vma_pin_count(vma) == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
bound = vma->flags;
if (WARN_ON((bound & I915_VMA_PIN_MASK) == I915_VMA_PIN_MASK))
return -EBUSY;

/* Pin early to prevent the shrinker/eviction logic from destroying
* our vma as we insert and bind.
*/
__i915_vma_pin(vma);

if (!bound) {
if ((bound & (I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND)) == 0) {
ret = i915_vma_insert(vma, size, alignment, flags);
if (ret)
goto err;
Expand All @@ -3731,7 +3733,7 @@ i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
if (ret)
goto err;

if ((bound ^ vma->bound) & GLOBAL_BIND)
if ((bound ^ vma->flags) & I915_VMA_GLOBAL_BIND)
__i915_vma_set_map_and_fenceable(vma);

GEM_BUG_ON(i915_vma_misplaced(vma, size, alignment, flags));
Expand Down Expand Up @@ -4032,9 +4034,9 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
* unbound now.
*/
list_for_each_entry_safe(vma, next, &obj->vma_list, obj_link) {
GEM_BUG_ON(!vma->is_ggtt);
GEM_BUG_ON(!i915_vma_is_ggtt(vma));
GEM_BUG_ON(i915_vma_is_active(vma));
vma->pin_count = 0;
vma->flags &= ~I915_VMA_PIN_MASK;
i915_vma_close(vma);
}
GEM_BUG_ON(obj->bind_count);
Expand Down Expand Up @@ -4094,7 +4096,8 @@ struct i915_vma *i915_gem_obj_to_ggtt_view(struct drm_i915_gem_object *obj,
GEM_BUG_ON(!view);

list_for_each_entry(vma, &obj->vma_list, obj_link)
if (vma->is_ggtt && i915_ggtt_view_equal(&vma->ggtt_view, view))
if (i915_vma_is_ggtt(vma) &&
i915_ggtt_view_equal(&vma->ggtt_view, view))
return vma;
return NULL;
}
Expand Down Expand Up @@ -4583,7 +4586,7 @@ u64 i915_gem_obj_offset(struct drm_i915_gem_object *o,
WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);

list_for_each_entry(vma, &o->vma_list, obj_link) {
if (vma->is_ggtt &&
if (i915_vma_is_ggtt(vma) &&
vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
continue;
if (vma->vm == vm)
Expand All @@ -4601,7 +4604,8 @@ u64 i915_gem_obj_ggtt_offset_view(struct drm_i915_gem_object *o,
struct i915_vma *vma;

list_for_each_entry(vma, &o->vma_list, obj_link)
if (vma->is_ggtt && i915_ggtt_view_equal(&vma->ggtt_view, view))
if (i915_vma_is_ggtt(vma) &&
i915_ggtt_view_equal(&vma->ggtt_view, view))
return vma->node.start;

WARN(1, "global vma for this object not found. (view=%u)\n", view->type);
Expand All @@ -4614,7 +4618,7 @@ bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
struct i915_vma *vma;

list_for_each_entry(vma, &o->vma_list, obj_link) {
if (vma->is_ggtt &&
if (i915_vma_is_ggtt(vma) &&
vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
continue;
if (vma->vm == vm && drm_mm_node_allocated(&vma->node))
Expand All @@ -4630,7 +4634,7 @@ bool i915_gem_obj_ggtt_bound_view(struct drm_i915_gem_object *o,
struct i915_vma *vma;

list_for_each_entry(vma, &o->vma_list, obj_link)
if (vma->is_ggtt &&
if (i915_vma_is_ggtt(vma) &&
i915_ggtt_view_equal(&vma->ggtt_view, view) &&
drm_mm_node_allocated(&vma->node))
return true;
Expand All @@ -4645,7 +4649,7 @@ unsigned long i915_gem_obj_ggtt_size(struct drm_i915_gem_object *o)
GEM_BUG_ON(list_empty(&o->vma_list));

list_for_each_entry(vma, &o->vma_list, obj_link) {
if (vma->is_ggtt &&
if (i915_vma_is_ggtt(vma) &&
vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL)
return vma->node.size;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/i915_gem_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static void i915_ppgtt_close(struct i915_address_space *vm)
struct i915_vma *vma, *vn;

list_for_each_entry_safe(vma, vn, *phase, vm_link)
if (!vma->closed)
if (!i915_vma_is_closed(vma))
i915_vma_close(vma);
}
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/i915/i915_gem_execbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ need_reloc_mappable(struct i915_vma *vma)
if (entry->relocation_count == 0)
return false;

if (!vma->is_ggtt)
if (!i915_vma_is_ggtt(vma))
return false;

/* See also use_cpu_reloc() */
Expand All @@ -736,7 +736,8 @@ eb_vma_misplaced(struct i915_vma *vma)
struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
struct drm_i915_gem_object *obj = vma->obj;

WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP && !vma->is_ggtt);
WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP &&
!i915_vma_is_ggtt(vma));

if (entry->alignment &&
vma->node.start & (entry->alignment - 1))
Expand Down
46 changes: 23 additions & 23 deletions drivers/gpu/drm/i915/i915_gem_gtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,7 @@ static int ggtt_bind_vma(struct i915_vma *vma,
* GLOBAL/LOCAL_BIND, it's all the same ptes. Hence unconditionally
* upgrade to both bound if we bind either to avoid double-binding.
*/
vma->bound |= GLOBAL_BIND | LOCAL_BIND;
vma->flags |= I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND;

return 0;
}
Expand All @@ -2674,14 +2674,14 @@ static int aliasing_gtt_bind_vma(struct i915_vma *vma,
pte_flags |= PTE_READ_ONLY;


if (flags & GLOBAL_BIND) {
if (flags & I915_VMA_GLOBAL_BIND) {
vma->vm->insert_entries(vma->vm,
vma->ggtt_view.pages,
vma->node.start,
cache_level, pte_flags);
}

if (flags & LOCAL_BIND) {
if (flags & I915_VMA_LOCAL_BIND) {
struct i915_hw_ppgtt *appgtt =
to_i915(vma->vm->dev)->mm.aliasing_ppgtt;
appgtt->base.insert_entries(&appgtt->base,
Expand All @@ -2698,12 +2698,12 @@ static void ggtt_unbind_vma(struct i915_vma *vma)
struct i915_hw_ppgtt *appgtt = to_i915(vma->vm->dev)->mm.aliasing_ppgtt;
const u64 size = min(vma->size, vma->node.size);

if (vma->bound & GLOBAL_BIND)
if (vma->flags & I915_VMA_GLOBAL_BIND)
vma->vm->clear_range(vma->vm,
vma->node.start, size,
true);

if (vma->bound & LOCAL_BIND && appgtt)
if (vma->flags & I915_VMA_LOCAL_BIND && appgtt)
appgtt->base.clear_range(&appgtt->base,
vma->node.start, size,
true);
Expand Down Expand Up @@ -3334,27 +3334,27 @@ i915_vma_retire(struct i915_gem_active *active,
return;

list_move_tail(&vma->vm_link, &vma->vm->inactive_list);
if (unlikely(vma->closed && !i915_vma_is_pinned(vma)))
if (unlikely(i915_vma_is_closed(vma) && !i915_vma_is_pinned(vma)))
WARN_ON(i915_vma_unbind(vma));
}

void i915_vma_destroy(struct i915_vma *vma)
{
GEM_BUG_ON(vma->node.allocated);
GEM_BUG_ON(i915_vma_is_active(vma));
GEM_BUG_ON(!vma->closed);
GEM_BUG_ON(!i915_vma_is_closed(vma));

list_del(&vma->vm_link);
if (!vma->is_ggtt)
if (!i915_vma_is_ggtt(vma))
i915_ppgtt_put(i915_vm_to_ppgtt(vma->vm));

kmem_cache_free(to_i915(vma->obj->base.dev)->vmas, vma);
}

void i915_vma_close(struct i915_vma *vma)
{
GEM_BUG_ON(vma->closed);
vma->closed = true;
GEM_BUG_ON(i915_vma_is_closed(vma));
vma->flags |= I915_VMA_CLOSED;

list_del_init(&vma->obj_link);
if (!i915_vma_is_active(vma) && !i915_vma_is_pinned(vma))
Expand Down Expand Up @@ -3386,9 +3386,9 @@ __i915_gem_vma_create(struct drm_i915_gem_object *obj,
vma->vm = vm;
vma->obj = obj;
vma->size = obj->base.size;
vma->is_ggtt = i915_is_ggtt(vm);

if (i915_is_ggtt(vm)) {
vma->flags |= I915_VMA_GGTT;
vma->ggtt_view = *view;
if (view->type == I915_GGTT_VIEW_PARTIAL) {
vma->size = view->params.partial.size;
Expand Down Expand Up @@ -3433,7 +3433,7 @@ i915_gem_obj_lookup_or_create_ggtt_vma(struct drm_i915_gem_object *obj,
if (!vma)
vma = __i915_gem_vma_create(obj, &ggtt->base, view);

GEM_BUG_ON(vma->closed);
GEM_BUG_ON(i915_vma_is_closed(vma));
return vma;

}
Expand Down Expand Up @@ -3644,27 +3644,28 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma)
int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
u32 flags)
{
int ret;
u32 bind_flags;
u32 vma_flags;
int ret;

if (WARN_ON(flags == 0))
return -EINVAL;

bind_flags = 0;
if (flags & PIN_GLOBAL)
bind_flags |= GLOBAL_BIND;
bind_flags |= I915_VMA_GLOBAL_BIND;
if (flags & PIN_USER)
bind_flags |= LOCAL_BIND;
bind_flags |= I915_VMA_LOCAL_BIND;

vma_flags = vma->flags & (I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND);
if (flags & PIN_UPDATE)
bind_flags |= vma->bound;
bind_flags |= vma_flags;
else
bind_flags &= ~vma->bound;

bind_flags &= ~vma_flags;
if (bind_flags == 0)
return 0;

if (vma->bound == 0 && vma->vm->allocate_va_range) {
if (vma_flags == 0 && vma->vm->allocate_va_range) {
trace_i915_va_alloc(vma);
ret = vma->vm->allocate_va_range(vma->vm,
vma->node.start,
Expand All @@ -3677,8 +3678,7 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
if (ret)
return ret;

vma->bound |= bind_flags;

vma->flags |= bind_flags;
return 0;
}

Expand All @@ -3690,8 +3690,8 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
if (WARN_ON(!vma->obj->map_and_fenceable))
return IO_ERR_PTR(-ENODEV);

GEM_BUG_ON(!vma->is_ggtt);
GEM_BUG_ON((vma->bound & GLOBAL_BIND) == 0);
GEM_BUG_ON(!i915_vma_is_ggtt(vma));
GEM_BUG_ON((vma->flags & I915_VMA_GLOBAL_BIND) == 0);

ptr = vma->iomap;
if (ptr == NULL) {
Expand Down
Loading

0 comments on commit 3272db5

Please sign in to comment.