All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: igt-dev@lists.freedesktop.org
Subject: [PATCH i-g-t 25/25] i915/gem_exec_latency: Measure the latency of context switching
Date: Thu, 14 Mar 2019 14:19:39 +0000	[thread overview]
Message-ID: <20190314141939.26246-25-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20190314141939.26246-1-chris@chris-wilson.co.uk>

Measure the baseline latency between contexts in order to directly
compare that with the additional cost of preemption.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/gem_ctx_shared.c   |   2 +-
 tests/i915/gem_exec_latency.c | 142 ++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+), 1 deletion(-)

diff --git a/tests/i915/gem_ctx_shared.c b/tests/i915/gem_ctx_shared.c
index 426155356..187921c7e 100644
--- a/tests/i915/gem_ctx_shared.c
+++ b/tests/i915/gem_ctx_shared.c
@@ -595,7 +595,7 @@ static void independent(int i915, unsigned ring, unsigned flags)
 		break;
 
 	default:
-		igt_skip("mmio base not known");
+		igt_skip("mmio base not known\n");
 	}
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
diff --git a/tests/i915/gem_exec_latency.c b/tests/i915/gem_exec_latency.c
index 6dd191ece..89c5af647 100644
--- a/tests/i915/gem_exec_latency.c
+++ b/tests/i915/gem_exec_latency.c
@@ -628,6 +628,139 @@ rthog_latency_on_ring(int fd, unsigned int engine, const char *name, unsigned in
 	munmap(results, MMAP_SZ);
 }
 
+static void context_switch(int i915,
+			   unsigned int engine, const char *name,
+			   unsigned int flags)
+{
+	struct drm_i915_gem_exec_object2 obj[2];
+	struct drm_i915_gem_relocation_entry reloc[5];
+	struct drm_i915_gem_execbuffer2 eb;
+	uint32_t *cs, *bbe, *results, v;
+	unsigned int mmio_base;
+	struct igt_mean mean;
+	uint32_t ctx[2];
+
+	/* XXX i915_query()! */
+	igt_skip_on(intel_gen(intel_get_drm_devid(i915)) >= 11);
+	switch (engine) {
+	case I915_EXEC_DEFAULT:
+	case I915_EXEC_RENDER:
+		mmio_base = 0x2000;
+		break;
+#if 0
+	case I915_EXEC_BSD:
+		mmio_base = 0x12000;
+		break;
+#endif
+	case I915_EXEC_BLT:
+		mmio_base = 0x22000;
+		break;
+	case I915_EXEC_VEBOX:
+		mmio_base = 0x1a000;
+		break;
+
+	default:
+		igt_skip("mmio base not known");
+	}
+
+	for (int i = 0; i < ARRAY_SIZE(ctx); i++)
+		ctx[i] = gem_context_create(i915);
+
+	if (flags & PREEMPT) {
+		gem_context_set_priority(i915, ctx[0], -1023);
+		gem_context_set_priority(i915, ctx[1], +1023);
+	}
+
+	memset(obj, 0, sizeof(obj));
+	obj[0].handle = gem_create(i915, 4096);
+	gem_set_caching(i915, obj[0].handle, 1);
+	results = gem_mmap__cpu(i915, obj[0].handle, 0, 4096, PROT_READ);
+	gem_set_domain(i915, obj[0].handle, I915_GEM_DOMAIN_CPU, 0);
+
+	obj[1].handle = gem_create(i915, 4096);
+	memset(reloc,0, sizeof(reloc));
+	obj[1].relocation_count = ARRAY_SIZE(reloc);
+	obj[1].relocs_ptr = to_user_pointer(reloc);
+	bbe = gem_mmap__wc(i915, obj[1].handle, 0, 4096, PROT_WRITE);
+	gem_set_domain(i915, obj[1].handle,
+		       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
+
+	cs = bbe;
+	*cs++ = 0x5 << 23;
+	*cs++ = 0x24 << 23 | 2; /* SRM */
+	*cs++ = mmio_base + 0x358; /* TIMESTAMP */
+	reloc[0].target_handle = obj[0].handle;
+	reloc[0].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = 0;
+	*cs++ = 0;
+	*cs++ = MI_BATCH_BUFFER_START | 1;
+	reloc[1].target_handle = obj[1].handle;
+	reloc[1].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = 0;
+	*cs++ = 0;
+
+	cs = bbe + 64;
+	*cs++ = 0x24 << 23 | 2; /* SRM */
+	*cs++ = mmio_base + 0x358; /* TIMESTAMP */
+	reloc[2].target_handle = obj[0].handle;
+	reloc[2].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = reloc[2].delta = 4;
+	*cs++ = 0;
+	*cs++ = 0x29 << 23 | 2; /* LRM */
+	*cs++ = mmio_base + 0x600; /* GPR0 */
+	reloc[3].target_handle = obj[0].handle;
+	reloc[3].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = 0;
+	*cs++ = 0;
+	*cs++ = 0x24 << 23 | 2; /* SRM */
+	*cs++ = mmio_base + 0x600; /* GPR0 */
+	reloc[4].target_handle = obj[0].handle;
+	reloc[4].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = reloc[4].delta = 8;
+	*cs++ = 0;
+	*cs++ = 0xa << 23;
+
+	memset(&eb, 0, sizeof(eb));
+	eb.buffers_ptr = to_user_pointer(obj);
+	eb.buffer_count = ARRAY_SIZE(obj);
+	eb.flags = engine;
+	eb.flags |= LOCAL_I915_EXEC_NO_RELOC;
+
+	v = 0;
+	igt_mean_init(&mean);
+	igt_until_timeout(5) {
+		eb.rsvd1 = ctx[0];
+		eb.batch_start_offset = 0;
+		gem_execbuf(i915, &eb);
+
+		while (results[0] == v)
+			igt_assert(gem_bo_busy(i915, obj[1].handle));
+
+		eb.rsvd1 = ctx[1];
+		eb.batch_start_offset = 64 * sizeof(*cs);
+		gem_execbuf(i915, &eb);
+
+		*bbe = 0xa << 23;
+		gem_sync(i915, obj[1].handle);
+		*bbe = 0x5 << 23;
+
+		v = results[0];
+		igt_mean_add(&mean, (results[1] - results[2]) * rcs_clock);
+	}
+	igt_info("%s context switch latency%s: %.2f±%.2fus\n",
+		 name, flags & PREEMPT ? " (preempt)" : "",
+		 1e-3 * igt_mean_get(&mean),
+		 1e-3 * sqrt(igt_mean_get_variance(&mean)));
+	munmap(results, 4096);
+	munmap(bbe, 4096);
+
+	for (int i = 0; i < ARRAY_SIZE(obj); i++)
+		gem_close(i915, obj[i].handle);
+
+	for (int i = 0; i < ARRAY_SIZE(ctx); i++)
+		gem_context_destroy(i915, ctx[i]);
+}
+
 static double clockrate(int i915, int reg)
 {
 	volatile uint32_t *mmio;
@@ -753,12 +886,21 @@ igt_main
 							  e->exec_id | e->flags,
 							  e->name, CORK);
 
+				igt_subtest_f("%s-cs", e->name)
+					context_switch(device,
+						       e->exec_id | e->flags,
+						       e->name, 0);
 				igt_subtest_group {
 					igt_fixture {
 						gem_require_contexts(device);
 						igt_require(gem_scheduler_has_preemption(device));
 					}
 
+					igt_subtest_f("%s-cs-preempt", e->name)
+						context_switch(device,
+								e->exec_id | e->flags,
+								e->name, PREEMPT);
+
 					igt_subtest_f("%s-preemption", e->name)
 						latency_from_ring(device,
 								  e->exec_id | e->flags,
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: igt-dev@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH i-g-t 25/25] i915/gem_exec_latency: Measure the latency of context switching
Date: Thu, 14 Mar 2019 14:19:39 +0000	[thread overview]
Message-ID: <20190314141939.26246-25-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20190314141939.26246-1-chris@chris-wilson.co.uk>

Measure the baseline latency between contexts in order to directly
compare that with the additional cost of preemption.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/gem_ctx_shared.c   |   2 +-
 tests/i915/gem_exec_latency.c | 142 ++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+), 1 deletion(-)

diff --git a/tests/i915/gem_ctx_shared.c b/tests/i915/gem_ctx_shared.c
index 426155356..187921c7e 100644
--- a/tests/i915/gem_ctx_shared.c
+++ b/tests/i915/gem_ctx_shared.c
@@ -595,7 +595,7 @@ static void independent(int i915, unsigned ring, unsigned flags)
 		break;
 
 	default:
-		igt_skip("mmio base not known");
+		igt_skip("mmio base not known\n");
 	}
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
diff --git a/tests/i915/gem_exec_latency.c b/tests/i915/gem_exec_latency.c
index 6dd191ece..89c5af647 100644
--- a/tests/i915/gem_exec_latency.c
+++ b/tests/i915/gem_exec_latency.c
@@ -628,6 +628,139 @@ rthog_latency_on_ring(int fd, unsigned int engine, const char *name, unsigned in
 	munmap(results, MMAP_SZ);
 }
 
+static void context_switch(int i915,
+			   unsigned int engine, const char *name,
+			   unsigned int flags)
+{
+	struct drm_i915_gem_exec_object2 obj[2];
+	struct drm_i915_gem_relocation_entry reloc[5];
+	struct drm_i915_gem_execbuffer2 eb;
+	uint32_t *cs, *bbe, *results, v;
+	unsigned int mmio_base;
+	struct igt_mean mean;
+	uint32_t ctx[2];
+
+	/* XXX i915_query()! */
+	igt_skip_on(intel_gen(intel_get_drm_devid(i915)) >= 11);
+	switch (engine) {
+	case I915_EXEC_DEFAULT:
+	case I915_EXEC_RENDER:
+		mmio_base = 0x2000;
+		break;
+#if 0
+	case I915_EXEC_BSD:
+		mmio_base = 0x12000;
+		break;
+#endif
+	case I915_EXEC_BLT:
+		mmio_base = 0x22000;
+		break;
+	case I915_EXEC_VEBOX:
+		mmio_base = 0x1a000;
+		break;
+
+	default:
+		igt_skip("mmio base not known");
+	}
+
+	for (int i = 0; i < ARRAY_SIZE(ctx); i++)
+		ctx[i] = gem_context_create(i915);
+
+	if (flags & PREEMPT) {
+		gem_context_set_priority(i915, ctx[0], -1023);
+		gem_context_set_priority(i915, ctx[1], +1023);
+	}
+
+	memset(obj, 0, sizeof(obj));
+	obj[0].handle = gem_create(i915, 4096);
+	gem_set_caching(i915, obj[0].handle, 1);
+	results = gem_mmap__cpu(i915, obj[0].handle, 0, 4096, PROT_READ);
+	gem_set_domain(i915, obj[0].handle, I915_GEM_DOMAIN_CPU, 0);
+
+	obj[1].handle = gem_create(i915, 4096);
+	memset(reloc,0, sizeof(reloc));
+	obj[1].relocation_count = ARRAY_SIZE(reloc);
+	obj[1].relocs_ptr = to_user_pointer(reloc);
+	bbe = gem_mmap__wc(i915, obj[1].handle, 0, 4096, PROT_WRITE);
+	gem_set_domain(i915, obj[1].handle,
+		       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
+
+	cs = bbe;
+	*cs++ = 0x5 << 23;
+	*cs++ = 0x24 << 23 | 2; /* SRM */
+	*cs++ = mmio_base + 0x358; /* TIMESTAMP */
+	reloc[0].target_handle = obj[0].handle;
+	reloc[0].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = 0;
+	*cs++ = 0;
+	*cs++ = MI_BATCH_BUFFER_START | 1;
+	reloc[1].target_handle = obj[1].handle;
+	reloc[1].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = 0;
+	*cs++ = 0;
+
+	cs = bbe + 64;
+	*cs++ = 0x24 << 23 | 2; /* SRM */
+	*cs++ = mmio_base + 0x358; /* TIMESTAMP */
+	reloc[2].target_handle = obj[0].handle;
+	reloc[2].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = reloc[2].delta = 4;
+	*cs++ = 0;
+	*cs++ = 0x29 << 23 | 2; /* LRM */
+	*cs++ = mmio_base + 0x600; /* GPR0 */
+	reloc[3].target_handle = obj[0].handle;
+	reloc[3].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = 0;
+	*cs++ = 0;
+	*cs++ = 0x24 << 23 | 2; /* SRM */
+	*cs++ = mmio_base + 0x600; /* GPR0 */
+	reloc[4].target_handle = obj[0].handle;
+	reloc[4].offset = (cs - bbe) * sizeof(*cs);
+	*cs++ = reloc[4].delta = 8;
+	*cs++ = 0;
+	*cs++ = 0xa << 23;
+
+	memset(&eb, 0, sizeof(eb));
+	eb.buffers_ptr = to_user_pointer(obj);
+	eb.buffer_count = ARRAY_SIZE(obj);
+	eb.flags = engine;
+	eb.flags |= LOCAL_I915_EXEC_NO_RELOC;
+
+	v = 0;
+	igt_mean_init(&mean);
+	igt_until_timeout(5) {
+		eb.rsvd1 = ctx[0];
+		eb.batch_start_offset = 0;
+		gem_execbuf(i915, &eb);
+
+		while (results[0] == v)
+			igt_assert(gem_bo_busy(i915, obj[1].handle));
+
+		eb.rsvd1 = ctx[1];
+		eb.batch_start_offset = 64 * sizeof(*cs);
+		gem_execbuf(i915, &eb);
+
+		*bbe = 0xa << 23;
+		gem_sync(i915, obj[1].handle);
+		*bbe = 0x5 << 23;
+
+		v = results[0];
+		igt_mean_add(&mean, (results[1] - results[2]) * rcs_clock);
+	}
+	igt_info("%s context switch latency%s: %.2f±%.2fus\n",
+		 name, flags & PREEMPT ? " (preempt)" : "",
+		 1e-3 * igt_mean_get(&mean),
+		 1e-3 * sqrt(igt_mean_get_variance(&mean)));
+	munmap(results, 4096);
+	munmap(bbe, 4096);
+
+	for (int i = 0; i < ARRAY_SIZE(obj); i++)
+		gem_close(i915, obj[i].handle);
+
+	for (int i = 0; i < ARRAY_SIZE(ctx); i++)
+		gem_context_destroy(i915, ctx[i]);
+}
+
 static double clockrate(int i915, int reg)
 {
 	volatile uint32_t *mmio;
@@ -753,12 +886,21 @@ igt_main
 							  e->exec_id | e->flags,
 							  e->name, CORK);
 
+				igt_subtest_f("%s-cs", e->name)
+					context_switch(device,
+						       e->exec_id | e->flags,
+						       e->name, 0);
 				igt_subtest_group {
 					igt_fixture {
 						gem_require_contexts(device);
 						igt_require(gem_scheduler_has_preemption(device));
 					}
 
+					igt_subtest_f("%s-cs-preempt", e->name)
+						context_switch(device,
+								e->exec_id | e->flags,
+								e->name, PREEMPT);
+
 					igt_subtest_f("%s-preemption", e->name)
 						latency_from_ring(device,
 								  e->exec_id | e->flags,
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-03-14 14:19 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 14:19 [PATCH i-g-t 01/25] i915/gem_create: Always try to create an object of at least one page Chris Wilson
2019-03-14 14:19 ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 02/25] lib/i915: Pretty print HW semaphores Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 03/25] lib: Add GPU power measurement Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 04/25] i915/gem_exec_schedule: Measure semaphore power consumption Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 05/25] i915/gem_exec_whisper: Measure total power consumed Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 06/25] i915/gem_exec_schedule: Verify that using HW semaphores doesn't block Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 07/25] i915/gem_exec_nop: poll-sequential requires ordering between rings Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 08/25] i915/gem_sync: Make switch-default asymmetric Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 09/25] i915/gem_ctx_param: Remove kneecapping Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 10/25] i915/gem_exec_big: Add a single shot test Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 11/25] kms_fence_pin_leak: Ask for the GPU before use Chris Wilson
2019-03-14 14:19   ` [Intel-gfx] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 12/25] drm-uapi: Import i915_drm.h upto 364df3d04d51 Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 13/25] lib/i915: Improve gem_context error messages Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 14/25] i915/gem_ctx_param: Test set/get (copy) VM Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 15/25] i915/gem_ctx_create: Basic checks for constructor properties Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 16/25] i915: Add gem_ctx_clone Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 17/25] i915: Add gem_vm_create Chris Wilson
2019-03-14 14:19   ` [Intel-gfx] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 18/25] i915: Exercise creating context with shared GTT Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 19/25] i915/gem_ctx_switch: Exercise queues Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 20/25] i915/gem_exec_whisper: Fork all-engine tests one-per-engine Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 21/25] i915/gem_exec_whisper: debugfs/next_seqno is defunct Chris Wilson
2019-03-14 14:19   ` [Intel-gfx] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 22/25] i915: Add gem_ctx_engines Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 23/25] i915: Add gem_exec_balancer Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` [PATCH i-g-t 24/25] i915/gem_exec_balancer: Exercise bonded pairs Chris Wilson
2019-03-14 14:19   ` [igt-dev] " Chris Wilson
2019-03-14 14:19 ` Chris Wilson [this message]
2019-03-14 14:19   ` [Intel-gfx] [PATCH i-g-t 25/25] i915/gem_exec_latency: Measure the latency of context switching Chris Wilson
2019-03-14 15:01 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/25] i915/gem_create: Always try to create an object of at least one page Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190314141939.26246-25-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.