提交 596c5923 编写于 作者: C Chris Wilson 提交者: Tvrtko Ursulin

drm/i915: Reduce the pointer dance of i915_is_ggtt()

The multiple levels of indirect do nothing but hinder the compiler and
the pointer chasing turns to be quite painful but painless to fix.
Signed-off-by: NChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: NTvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: NDave Gordon <david.s.gordon@intel.com>
Signed-off-by: NTvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1456484600-11477-1-git-send-email-tvrtko.ursulin@linux.intel.com
上级 1c7f4bca
...@@ -118,7 +118,7 @@ static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj) ...@@ -118,7 +118,7 @@ static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
struct i915_vma *vma; struct i915_vma *vma;
list_for_each_entry(vma, &obj->vma_list, obj_link) { list_for_each_entry(vma, &obj->vma_list, obj_link) {
if (i915_is_ggtt(vma->vm) && drm_mm_node_allocated(&vma->node)) if (vma->is_ggtt && drm_mm_node_allocated(&vma->node))
size += vma->node.size; size += vma->node.size;
} }
...@@ -165,12 +165,11 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) ...@@ -165,12 +165,11 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
seq_printf(m, " (fence: %d)", obj->fence_reg); seq_printf(m, " (fence: %d)", obj->fence_reg);
list_for_each_entry(vma, &obj->vma_list, obj_link) { list_for_each_entry(vma, &obj->vma_list, obj_link) {
seq_printf(m, " (%sgtt offset: %08llx, size: %08llx", seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
i915_is_ggtt(vma->vm) ? "g" : "pp", vma->is_ggtt ? "g" : "pp",
vma->node.start, vma->node.size); vma->node.start, vma->node.size);
if (i915_is_ggtt(vma->vm)) if (vma->is_ggtt)
seq_printf(m, ", type: %u)", vma->ggtt_view.type); seq_printf(m, ", type: %u", vma->ggtt_view.type);
else seq_puts(m, ")");
seq_puts(m, ")");
} }
if (obj->stolen) if (obj->stolen)
seq_printf(m, " (stolen: %08llx)", obj->stolen->start); seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
...@@ -347,7 +346,7 @@ static int per_file_stats(int id, void *ptr, void *data) ...@@ -347,7 +346,7 @@ static int per_file_stats(int id, void *ptr, void *data)
if (!drm_mm_node_allocated(&vma->node)) if (!drm_mm_node_allocated(&vma->node))
continue; continue;
if (i915_is_ggtt(vma->vm)) { if (vma->is_ggtt) {
stats->global += obj->base.size; stats->global += obj->base.size;
continue; continue;
} }
......
...@@ -3156,18 +3156,11 @@ bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj); ...@@ -3156,18 +3156,11 @@ bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj);
/* Some GGTT VM helpers */ /* Some GGTT VM helpers */
#define i915_obj_to_ggtt(obj) \ #define i915_obj_to_ggtt(obj) \
(&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base) (&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base)
static inline bool i915_is_ggtt(struct i915_address_space *vm)
{
struct i915_address_space *ggtt =
&((struct drm_i915_private *)(vm)->dev->dev_private)->gtt.base;
return vm == ggtt;
}
static inline struct i915_hw_ppgtt * static inline struct i915_hw_ppgtt *
i915_vm_to_ppgtt(struct i915_address_space *vm) i915_vm_to_ppgtt(struct i915_address_space *vm)
{ {
WARN_ON(i915_is_ggtt(vm)); WARN_ON(i915_is_ggtt(vm));
return container_of(vm, struct i915_hw_ppgtt, base); return container_of(vm, struct i915_hw_ppgtt, base);
} }
......
...@@ -3336,8 +3336,7 @@ static int __i915_vma_unbind(struct i915_vma *vma, bool wait) ...@@ -3336,8 +3336,7 @@ static int __i915_vma_unbind(struct i915_vma *vma, bool wait)
return ret; return ret;
} }
if (i915_is_ggtt(vma->vm) && if (vma->is_ggtt && vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
i915_gem_object_finish_gtt(obj); i915_gem_object_finish_gtt(obj);
/* release the fence reg _after_ flushing */ /* release the fence reg _after_ flushing */
...@@ -3352,7 +3351,7 @@ static int __i915_vma_unbind(struct i915_vma *vma, bool wait) ...@@ -3352,7 +3351,7 @@ static int __i915_vma_unbind(struct i915_vma *vma, bool wait)
vma->bound = 0; vma->bound = 0;
list_del_init(&vma->vm_link); list_del_init(&vma->vm_link);
if (i915_is_ggtt(vma->vm)) { if (vma->is_ggtt) {
if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) { if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
obj->map_and_fenceable = false; obj->map_and_fenceable = false;
} else if (vma->ggtt_view.pages) { } else if (vma->ggtt_view.pages) {
...@@ -4639,17 +4638,14 @@ struct i915_vma *i915_gem_obj_to_ggtt_view(struct drm_i915_gem_object *obj, ...@@ -4639,17 +4638,14 @@ struct i915_vma *i915_gem_obj_to_ggtt_view(struct drm_i915_gem_object *obj,
void i915_gem_vma_destroy(struct i915_vma *vma) void i915_gem_vma_destroy(struct i915_vma *vma)
{ {
struct i915_address_space *vm = NULL;
WARN_ON(vma->node.allocated); WARN_ON(vma->node.allocated);
/* Keep the vma as a placeholder in the execbuffer reservation lists */ /* Keep the vma as a placeholder in the execbuffer reservation lists */
if (!list_empty(&vma->exec_list)) if (!list_empty(&vma->exec_list))
return; return;
vm = vma->vm; if (!vma->is_ggtt)
i915_ppgtt_put(i915_vm_to_ppgtt(vma->vm));
if (!i915_is_ggtt(vm))
i915_ppgtt_put(i915_vm_to_ppgtt(vm));
list_del(&vma->obj_link); list_del(&vma->obj_link);
...@@ -5202,7 +5198,7 @@ u64 i915_gem_obj_offset(struct drm_i915_gem_object *o, ...@@ -5202,7 +5198,7 @@ u64 i915_gem_obj_offset(struct drm_i915_gem_object *o,
WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base); WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
list_for_each_entry(vma, &o->vma_list, obj_link) { list_for_each_entry(vma, &o->vma_list, obj_link) {
if (i915_is_ggtt(vma->vm) && if (vma->is_ggtt &&
vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
continue; continue;
if (vma->vm == vm) if (vma->vm == vm)
...@@ -5235,7 +5231,7 @@ bool i915_gem_obj_bound(struct drm_i915_gem_object *o, ...@@ -5235,7 +5231,7 @@ bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
struct i915_vma *vma; struct i915_vma *vma;
list_for_each_entry(vma, &o->vma_list, obj_link) { list_for_each_entry(vma, &o->vma_list, obj_link) {
if (i915_is_ggtt(vma->vm) && if (vma->is_ggtt &&
vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
continue; continue;
if (vma->vm == vm && drm_mm_node_allocated(&vma->node)) if (vma->vm == vm && drm_mm_node_allocated(&vma->node))
...@@ -5282,7 +5278,7 @@ unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o, ...@@ -5282,7 +5278,7 @@ unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
BUG_ON(list_empty(&o->vma_list)); BUG_ON(list_empty(&o->vma_list));
list_for_each_entry(vma, &o->vma_list, obj_link) { list_for_each_entry(vma, &o->vma_list, obj_link) {
if (i915_is_ggtt(vma->vm) && if (vma->is_ggtt &&
vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
continue; continue;
if (vma->vm == vm) if (vma->vm == vm)
......
...@@ -668,7 +668,7 @@ need_reloc_mappable(struct i915_vma *vma) ...@@ -668,7 +668,7 @@ need_reloc_mappable(struct i915_vma *vma)
if (entry->relocation_count == 0) if (entry->relocation_count == 0)
return false; return false;
if (!i915_is_ggtt(vma->vm)) if (!vma->is_ggtt)
return false; return false;
/* See also use_cpu_reloc() */ /* See also use_cpu_reloc() */
...@@ -687,8 +687,7 @@ eb_vma_misplaced(struct i915_vma *vma) ...@@ -687,8 +687,7 @@ eb_vma_misplaced(struct i915_vma *vma)
struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
struct drm_i915_gem_object *obj = vma->obj; struct drm_i915_gem_object *obj = vma->obj;
WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP && WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP && !vma->is_ggtt);
!i915_is_ggtt(vma->vm));
if (entry->alignment && if (entry->alignment &&
vma->node.start & (entry->alignment - 1)) vma->node.start & (entry->alignment - 1))
......
...@@ -3198,6 +3198,7 @@ int i915_gem_gtt_init(struct drm_device *dev) ...@@ -3198,6 +3198,7 @@ int i915_gem_gtt_init(struct drm_device *dev)
} }
gtt->base.dev = dev; gtt->base.dev = dev;
gtt->base.is_ggtt = true;
ret = gtt->gtt_probe(dev, &gtt->base.total, &gtt->stolen_size, ret = gtt->gtt_probe(dev, &gtt->base.total, &gtt->stolen_size,
&gtt->mappable_base, &gtt->mappable_end); &gtt->mappable_base, &gtt->mappable_end);
...@@ -3319,13 +3320,14 @@ __i915_gem_vma_create(struct drm_i915_gem_object *obj, ...@@ -3319,13 +3320,14 @@ __i915_gem_vma_create(struct drm_i915_gem_object *obj,
INIT_LIST_HEAD(&vma->exec_list); INIT_LIST_HEAD(&vma->exec_list);
vma->vm = vm; vma->vm = vm;
vma->obj = obj; vma->obj = obj;
vma->is_ggtt = i915_is_ggtt(vm);
if (i915_is_ggtt(vm)) if (i915_is_ggtt(vm))
vma->ggtt_view = *ggtt_view; vma->ggtt_view = *ggtt_view;
else
i915_ppgtt_get(i915_vm_to_ppgtt(vm));
list_add_tail(&vma->obj_link, &obj->vma_list); list_add_tail(&vma->obj_link, &obj->vma_list);
if (!i915_is_ggtt(vm))
i915_ppgtt_get(i915_vm_to_ppgtt(vm));
return vma; return vma;
} }
...@@ -3598,13 +3600,9 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level, ...@@ -3598,13 +3600,9 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
return 0; return 0;
if (vma->bound == 0 && vma->vm->allocate_va_range) { if (vma->bound == 0 && vma->vm->allocate_va_range) {
trace_i915_va_alloc(vma->vm,
vma->node.start,
vma->node.size,
VM_TO_TRACE_NAME(vma->vm));
/* XXX: i915_vma_pin() will fix this +- hack */ /* XXX: i915_vma_pin() will fix this +- hack */
vma->pin_count++; vma->pin_count++;
trace_i915_va_alloc(vma);
ret = vma->vm->allocate_va_range(vma->vm, ret = vma->vm->allocate_va_range(vma->vm,
vma->node.start, vma->node.start,
vma->node.size); vma->node.size);
......
...@@ -183,6 +183,7 @@ struct i915_vma { ...@@ -183,6 +183,7 @@ struct i915_vma {
#define GLOBAL_BIND (1<<0) #define GLOBAL_BIND (1<<0)
#define LOCAL_BIND (1<<1) #define LOCAL_BIND (1<<1)
unsigned int bound : 4; unsigned int bound : 4;
bool is_ggtt : 1;
/** /**
* Support different GGTT views into the same object. * Support different GGTT views into the same object.
...@@ -275,6 +276,8 @@ struct i915_address_space { ...@@ -275,6 +276,8 @@ struct i915_address_space {
u64 start; /* Start offset always 0 for dri2 */ u64 start; /* Start offset always 0 for dri2 */
u64 total; /* size addr space maps (ex. 2GB for ggtt) */ u64 total; /* size addr space maps (ex. 2GB for ggtt) */
bool is_ggtt;
struct i915_page_scratch *scratch_page; struct i915_page_scratch *scratch_page;
struct i915_page_table *scratch_pt; struct i915_page_table *scratch_pt;
struct i915_page_directory *scratch_pd; struct i915_page_directory *scratch_pd;
...@@ -330,6 +333,8 @@ struct i915_address_space { ...@@ -330,6 +333,8 @@ struct i915_address_space {
u32 flags); u32 flags);
}; };
#define i915_is_ggtt(V) ((V)->is_ggtt)
/* The Graphics Translation Table is the way in which GEN hardware translates a /* The Graphics Translation Table is the way in which GEN hardware translates a
* Graphics Virtual Address into a Physical Address. In addition to the normal * Graphics Virtual Address into a Physical Address. In addition to the normal
* collateral associated with any va->pa translations GEN hardware also has a * collateral associated with any va->pa translations GEN hardware also has a
......
...@@ -175,35 +175,24 @@ TRACE_EVENT(i915_vma_unbind, ...@@ -175,35 +175,24 @@ TRACE_EVENT(i915_vma_unbind,
__entry->obj, __entry->offset, __entry->size, __entry->vm) __entry->obj, __entry->offset, __entry->size, __entry->vm)
); );
#define VM_TO_TRACE_NAME(vm) \ TRACE_EVENT(i915_va_alloc,
(i915_is_ggtt(vm) ? "G" : \ TP_PROTO(struct i915_vma *vma),
"P") TP_ARGS(vma),
DECLARE_EVENT_CLASS(i915_va,
TP_PROTO(struct i915_address_space *vm, u64 start, u64 length, const char *name),
TP_ARGS(vm, start, length, name),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(struct i915_address_space *, vm) __field(struct i915_address_space *, vm)
__field(u64, start) __field(u64, start)
__field(u64, end) __field(u64, end)
__string(name, name)
), ),
TP_fast_assign( TP_fast_assign(
__entry->vm = vm; __entry->vm = vma->vm;
__entry->start = start; __entry->start = vma->node.start;
__entry->end = start + length - 1; __entry->end = vma->node.start + vma->node.size - 1;
__assign_str(name, name);
), ),
TP_printk("vm=%p (%s), 0x%llx-0x%llx", TP_printk("vm=%p (%c), 0x%llx-0x%llx",
__entry->vm, __get_str(name), __entry->start, __entry->end) __entry->vm, i915_is_ggtt(__entry->vm) ? 'G' : 'P', __entry->start, __entry->end)
);
DEFINE_EVENT(i915_va, i915_va_alloc,
TP_PROTO(struct i915_address_space *vm, u64 start, u64 length, const char *name),
TP_ARGS(vm, start, length, name)
); );
DECLARE_EVENT_CLASS(i915_px_entry, DECLARE_EVENT_CLASS(i915_px_entry,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册