[Intel-gfx] [RFCv2 19/19] drm/i915: Initial selftests for exercising eviction

Matthew Auld matthew.william.auld at gmail.com
Tue Jan 10 19:49:48 UTC 2017


On 20 December 2016 at 13:08, Chris Wilson <chris at chris-wilson.co.uk> wrote:
> Very simple tests to just ask eviction to find some free space in a full
> GTT and one with some available space.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/i915_gem_evict.c              |   4 +
>  drivers/gpu/drm/i915/selftests/i915_gem_evict.c    | 237 +++++++++++++++++++++
>  .../gpu/drm/i915/selftests/i915_mock_selftests.h   |   1 +
>  3 files changed, 242 insertions(+)
>  create mode 100644 drivers/gpu/drm/i915/selftests/i915_gem_evict.c
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
> index f92f63e8749a..c01a9dd6298c 100644
> --- a/drivers/gpu/drm/i915/i915_gem_evict.c
> +++ b/drivers/gpu/drm/i915/i915_gem_evict.c
> @@ -383,3 +383,7 @@ int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle)
>
>         return 0;
>  }
> +
> +#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
> +#include "selftests/i915_gem_evict.c"
> +#endif
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> new file mode 100644
> index 000000000000..c31e6a6c98cd
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> @@ -0,0 +1,237 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + */
> +
> +#include "i915_selftest.h"
> +
> +#include "mock_gem_device.h"
> +
> +static int populate_ggtt(struct drm_i915_private *i915)
> +{
> +       struct drm_i915_gem_object *obj;
> +       u64 size;
> +
> +       for (size = 0; size < i915->ggtt.base.total; size += PAGE_SIZE) {
> +               struct i915_vma *vma;
> +
> +               obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
> +               if (IS_ERR(obj))
> +                       return PTR_ERR(obj);
> +
> +               vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
> +               if (IS_ERR(vma))
> +                       return PTR_ERR(vma);
> +       }
> +
> +       if (!list_empty(&i915->mm.unbound_list)) {
> +               size = 0;
> +               list_for_each_entry(obj, &i915->mm.unbound_list, global_link)
> +                       size++;
> +
> +               pr_err("Found %lld objects unbound!\n", size);
> +               return -EINVAL;
> +       }
> +
> +       if (list_empty(&i915->ggtt.base.inactive_list)) {
> +               pr_err("No objects on the GGTT inactive list!\n");
> +               return -EINVAL;
> +       }
> +
> +       return 0;
> +}
> +
> +static void unpin_ggtt(struct drm_i915_private *i915)
> +{
> +       struct i915_vma *vma;
> +
> +       list_for_each_entry(vma, &i915->ggtt.base.inactive_list, vm_link)
> +               i915_vma_unpin(vma);
> +}
> +
> +static void cleanup_objects(struct drm_i915_private *i915)
> +{
> +       struct drm_i915_gem_object *obj, *on;
> +
> +       list_for_each_entry_safe(obj, on, &i915->mm.unbound_list, global_link)
> +               i915_gem_object_put(obj);
> +
> +       list_for_each_entry_safe(obj, on, &i915->mm.bound_list, global_link)
> +               i915_gem_object_put(obj);
> +
> +       mutex_unlock(&i915->drm.struct_mutex);
> +
> +       rcu_barrier();
> +       while (flush_work(&i915->mm.free_work))
> +               rcu_barrier();
i915_gem_drain_freed_objects(i915), likewise for device_release ?

Reviewed-by: Matthew Auld <matthew.auld at intel.com>


More information about the Intel-gfx mailing list