Re: [Intel-gfx] [PATCH] drm/i915/selftests: Add coverage of mocs registers

2019-10-24 Thread Kumar Valsan, Prathap
On Thu, Oct 24, 2019 at 08:13:29AM +0100, Chris Wilson wrote:
> Quoting Kumar Valsan, Prathap (2019-10-23 22:03:40)
> > On Tue, Oct 22, 2019 at 12:57:05PM +0100, Chris Wilson wrote:
> > > Probe the mocs registers for new contexts and across GPU resets. Similar
> > > to intel_workarounds, we have tables of what register values we expect
> > > to see, so verify that user contexts are affected by them. In the
> > > future, we should add tests similar to intel_sseu to cover dynamic
> > > reconfigurations.
> > > 
> > > Signed-off-by: Chris Wilson 
> > > Cc: Prathap Kumar Valsan 
> > > Cc: Mika Kuoppala 
> > 
> > s/for_each_engine/for_each_uabi_engine ?
> 
> No, we are inside the gt compartment, so we only operate within our
> little enclosure. Think parallelism...
Ok. Thanks.
> -Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH] drm/i915/selftests: Add coverage of mocs registers

2019-10-24 Thread Chris Wilson
Quoting Kumar Valsan, Prathap (2019-10-23 22:03:40)
> On Tue, Oct 22, 2019 at 12:57:05PM +0100, Chris Wilson wrote:
> > Probe the mocs registers for new contexts and across GPU resets. Similar
> > to intel_workarounds, we have tables of what register values we expect
> > to see, so verify that user contexts are affected by them. In the
> > future, we should add tests similar to intel_sseu to cover dynamic
> > reconfigurations.
> > 
> > Signed-off-by: Chris Wilson 
> > Cc: Prathap Kumar Valsan 
> > Cc: Mika Kuoppala 
> 
> s/for_each_engine/for_each_uabi_engine ?

No, we are inside the gt compartment, so we only operate within our
little enclosure. Think parallelism...
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH] drm/i915/selftests: Add coverage of mocs registers

2019-10-23 Thread Kumar Valsan, Prathap
On Tue, Oct 22, 2019 at 12:57:05PM +0100, Chris Wilson wrote:
> Probe the mocs registers for new contexts and across GPU resets. Similar
> to intel_workarounds, we have tables of what register values we expect
> to see, so verify that user contexts are affected by them. In the
> future, we should add tests similar to intel_sseu to cover dynamic
> reconfigurations.
> 
> Signed-off-by: Chris Wilson 
> Cc: Prathap Kumar Valsan 
> Cc: Mika Kuoppala 

s/for_each_engine/for_each_uabi_engine ?

Otherwise

Reviewed-by: Prathap Kumar Valsan 
> ---
>  drivers/gpu/drm/i915/gt/intel_mocs.c  |   4 +
>  drivers/gpu/drm/i915/gt/selftest_mocs.c   | 393 ++
>  .../drm/i915/selftests/i915_live_selftests.h  |   1 +
>  3 files changed, 398 insertions(+)
>  create mode 100644 drivers/gpu/drm/i915/gt/selftest_mocs.c
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_mocs.c 
> b/drivers/gpu/drm/i915/gt/intel_mocs.c
> index 445ec025bda0..06dba7ff294e 100644
> --- a/drivers/gpu/drm/i915/gt/intel_mocs.c
> +++ b/drivers/gpu/drm/i915/gt/intel_mocs.c
> @@ -448,3 +448,7 @@ void intel_mocs_init(struct intel_gt *gt)
>   if (HAS_GLOBAL_MOCS_REGISTERS(gt->i915))
>   init_global_mocs(gt);
>  }
> +
> +#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
> +#include "selftest_mocs.c"
> +#endif
> diff --git a/drivers/gpu/drm/i915/gt/selftest_mocs.c 
> b/drivers/gpu/drm/i915/gt/selftest_mocs.c
> new file mode 100644
> index ..ca9679c3ee68
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/gt/selftest_mocs.c
> @@ -0,0 +1,393 @@
> +/*
> + * SPDX-License-Identifier: MIT
> + *
> + * Copyright © 2019 Intel Corporation
> + */
> +
> +#include "gt/intel_engine_pm.h"
> +#include "i915_selftest.h"
> +
> +#include "gem/selftests/mock_context.h"
> +#include "selftests/igt_reset.h"
> +#include "selftests/igt_spinner.h"
> +
> +struct live_mocs {
> + struct drm_i915_mocs_table table;
> + struct i915_vma *scratch;
> + void *vaddr;
> +};
> +
> +static int request_add_sync(struct i915_request *rq, int err)
> +{
> + i915_request_get(rq);
> + i915_request_add(rq);
> + if (i915_request_wait(rq, 0, HZ / 5) < 0)
> + err = -ETIME;
> + i915_request_put(rq);
> +
> + return err;
> +}
> +
> +static int request_add_spin(struct i915_request *rq, struct igt_spinner 
> *spin)
> +{
> + int err = 0;
> +
> + i915_request_get(rq);
> + i915_request_add(rq);
> + if (spin && !igt_wait_for_spinner(spin, rq))
> + err = -ETIME;
> + i915_request_put(rq);
> +
> + return err;
> +}
> +
> +static struct i915_vma *create_scratch(struct intel_gt *gt)
> +{
> + struct drm_i915_gem_object *obj;
> + struct i915_vma *vma;
> + int err;
> +
> + obj = i915_gem_object_create_internal(gt->i915, PAGE_SIZE);
> + if (IS_ERR(obj))
> + return ERR_CAST(obj);
> +
> + i915_gem_object_set_cache_coherency(obj, I915_CACHING_CACHED);
> +
> + vma = i915_vma_instance(obj, >->ggtt->vm, NULL);
> + if (IS_ERR(vma)) {
> + i915_gem_object_put(obj);
> + return vma;
> + }
> +
> + err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
> + if (err) {
> + i915_gem_object_put(obj);
> + return ERR_PTR(err);
> + }
> +
> + return vma;
> +}
> +
> +static int live_mocs_init(struct live_mocs *arg, struct intel_gt *gt)
> +{
> + int err;
> +
> + if (!get_mocs_settings(gt->i915, &arg->table))
> + return -EINVAL;
> +
> + arg->scratch = create_scratch(gt);
> + if (IS_ERR(arg->scratch))
> + return PTR_ERR(arg->scratch);
> +
> + arg->vaddr = i915_gem_object_pin_map(arg->scratch->obj, I915_MAP_WB);
> + if (IS_ERR(arg->vaddr)) {
> + err = PTR_ERR(arg->vaddr);
> + goto err_scratch;
> + }
> +
> + return 0;
> +
> +err_scratch:
> + i915_vma_unpin_and_release(&arg->scratch, 0);
> + return err;
> +}
> +
> +static void live_mocs_fini(struct live_mocs *arg)
> +{
> + i915_vma_unpin_and_release(&arg->scratch, I915_VMA_RELEASE_MAP);
> +}
> +
> +static int read_regs(struct i915_request *rq,
> +  u32 addr, unsigned int count,
> +  uint32_t *offset)
> +{
> + unsigned int i;
> + u32 *cs;
> +
> + GEM_BUG_ON(!IS_ALIGNED(*offset, sizeof(u32)));
> +
> + cs = intel_ring_begin(rq, 4 * count);
> + if (IS_ERR(cs))
> + return PTR_ERR(cs);
> +
> + for (i = 0; i < count; i++) {
> + *cs++ = MI_STORE_REGISTER_MEM_GEN8 | MI_USE_GGTT;
> + *cs++ = addr;
> + *cs++ = *offset;
> + *cs++ = 0;
> +
> + addr += sizeof(u32);
> + *offset += sizeof(u32);
> + }
> +
> + intel_ring_advance(rq, cs);
> +
> + return 0;
> +}
> +
> +static int read_mocs_table(struct i915_request *rq,
> +const struct drm_i915_mocs_table *table,
> +uint32_t *offset)
> +{
> + u32 addr;
> +
> + if (HAS_GLO

Re: [Intel-gfx] [PATCH] drm/i915/selftests: Add coverage of mocs registers

2019-10-18 Thread Kumar Valsan, Prathap
On Fri, Oct 18, 2019 at 01:06:39PM +0100, Chris Wilson wrote:
> Probe the mocs registers for new contexts and across GPU resets. Similar
> to intel_workarounds, we have tables of what register values we expect
> to see, so verify that user contexts are affected by them. In the
> future, we should add tests similar to intel_sseu to cover dynamic
> reconfigurations.
> 
> Signed-off-by: Chris Wilson 
> Cc: Prathap Kumar Valsan 
> Cc: Mika Kuoppala 
> ---
> +static int check_l3cc_table(struct intel_engine_cs *engine,
> + const struct drm_i915_mocs_table *table,
> + const u32 *vaddr, int *offset)
> +{
> + u16 unused_value = table->table[I915_MOCS_PTE].l3cc_value;
> + unsigned int i;
> + u32 expect;
> +
> + if (1) { /* XXX skip MCR read back */
> + *offset += table->n_entries / 2;
> + return 0;
> + }
Not checking l3cc table?

> +
> + for (i = 0; i < table->size / 2; i++) {
> + u16 low = get_entry_l3cc(table, 2 * i);
> + u16 high = get_entry_l3cc(table, 2 * i + 1);
> +
> + expect = l3cc_combine(table, low, high);
> + if (vaddr[*offset] != expect) {
> + pr_err("%s: Invalid L3CC[%d] entry, found %08x, 
> expected %08x\n",
> +engine->name, i, vaddr[*offset], expect);
> + return -EINVAL;
> + }
> + ++*offset;
> + }
> +
> + /* Odd table size - 1 left over */
> + if (table->size & 1) {
> + u16 low = get_entry_l3cc(table, 2 * i);
> +
> + expect = l3cc_combine(table, low, unused_value);
> + if (vaddr[*offset] != expect) {
> + pr_err("%s: Invalid L3CC[%d] entry, found %08x, 
> expected %08x\n",
> +engine->name, i, vaddr[*offset], expect);
> + return -EINVAL;
> + }
> + ++*offset;
> + i++;
> + }
> +
> + /* All remaining entries are also unused */
> + for (; i < table->n_entries / 2; i++) {
> + expect = l3cc_combine(table, unused_value, unused_value);
> + if (vaddr[*offset] != expect) {
> + pr_err("%s: Invalid L3CC[%d] entry, found %08x, 
> expected %08x\n",
> +engine->name, i, vaddr[*offset], expect);
> + return -EINVAL;
> + }
> + ++*offset;
> + }
> +
> + return 0;
> +}
> +
> +static int check_mocs_engine(struct live_mocs *arg,
> +  struct intel_context *ce)
> +{
> + struct i915_vma *vma = arg->scratch;
> + struct i915_request *rq;
> + int offset;
> + int err;
> +
> + memset32(arg->vaddr, STACK_MAGIC, PAGE_SIZE / sizeof(u32));
> +
> + rq = intel_context_create_request(ce);
> + if (IS_ERR(rq))
> + return PTR_ERR(rq);
> +
> + i915_vma_lock(vma);
> + err = i915_request_await_object(rq, vma->obj, true);
> + if (!err)
> + err = i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
> + i915_vma_unlock(vma);
> +
> + offset = 0;
> + if (!err)
> + err = read_mocs_table(rq, &arg->table, vma, &offset);
> + if (!err && ce->engine->class == RENDER_CLASS)
> + err = read_l3cc_table(rq, &arg->table, vma, &offset);
> +
> + err = request_add_sync(rq, err);
> + if (err)
> + return err;
> +
> + offset = 0;
> + if (!err)
> + err = check_mocs_table(ce->engine, &arg->table,
> +arg->vaddr, &offset);
> + if (!err && ce->engine->class == RENDER_CLASS)
> + err = check_l3cc_table(ce->engine, &arg->table,
> +arg->vaddr, &offset);
> + if (err)
> + return err;
> +
> + return 0;
> +}
> +
> +static int live_mocs_clean(void *arg)
> +{
> + struct intel_gt *gt = arg;
> + struct intel_engine_cs *engine;
> + enum intel_engine_id id;
> + struct live_mocs mocs;
> + int err;
> +
> + err = live_mocs_init(&mocs, gt);
> + if (err)
> + return err;
> +
> + for_each_engine(engine, gt, id) {
> + struct intel_context *ce;
> +
> + ce = intel_context_create(engine->kernel_context->gem_context,
> +   engine);
> + if (IS_ERR(ce)) {
> + err = PTR_ERR(ce);
> + break;
> + }
> +
> + err = check_mocs_engine(&mocs, ce);
> + intel_context_put(ce);
Need a _get() to pair with _put()?

> + if (err)
> + break;
> + }
> +
> + live_mocs_fini(&mocs);
> +
> + return err;
> +}
> +
[snip]
> diff --git a/drivers/gpu/drm/i915/selftests/i915_live_selftests.h 
> b/drivers/gpu/drm/i915/selftests/i915_live_selftests.h
> index 6daf6599ec79..1a6abcffce81 100644
> --- a/drivers/gpu/drm/i9