Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tursulin@ursulin.net>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org,
	Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [CI i-g-t v3] don't look
Date: Fri,  2 Mar 2018 08:49:58 +0000	[thread overview]
Message-ID: <20180302084958.23566-1-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20180301164849.21430-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

1.
We need to tell the compiler mmio access cannot be optimized away
(volatile).

2.
We need to ensure we don't exit with forcewake left on. Signal threads
to exit in a controlled fashion and install atexit handler just in case.

v2: Do not assert from the threads.

v3: HACK

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tests/gen7_forcewake_mt.c | 69 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 64 insertions(+), 5 deletions(-)

diff --git a/tests/gen7_forcewake_mt.c b/tests/gen7_forcewake_mt.c
index 07320ef9e8ac..d8a369b0e6ff 100644
--- a/tests/gen7_forcewake_mt.c
+++ b/tests/gen7_forcewake_mt.c
@@ -29,6 +29,7 @@
  * Testcase: Exercise a suspect workaround required for FORCEWAKE_MT
  *
  */
+#pragma GCC optimize ("O0")
 
 #include "igt.h"
 #include <sys/types.h>
@@ -44,6 +45,7 @@ IGT_TEST_DESCRIPTION("Exercise a suspect workaround required for"
 
 struct thread {
 	pthread_t thread;
+	bool run;
 	void *mmio;
 	int fd;
 	int bit;
@@ -106,14 +108,26 @@ static void *igfx_get_mmio(void)
 static void *thread(void *arg)
 {
 	struct thread *t = arg;
-	uint32_t *forcewake_mt = (uint32_t *)((char *)t->mmio + FORCEWAKE_MT);
+	volatile uint32_t *forcewake_mt =
+		(uint32_t *)((char *)t->mmio + FORCEWAKE_MT);
 	uint32_t bit = 1 << t->bit;
 
-	while (1) {
+	while (t->run) {
+		uint32_t reg;
+
 		*forcewake_mt = bit << 16 | bit;
-		igt_assert(*forcewake_mt & bit);
+		reg = *forcewake_mt;
+		if (!(reg & bit)) {
+			igt_warn("Bit %u did not set! (val=%x)\n", t->bit, reg);
+			return (void *)-1;
+		}
 		*forcewake_mt = bit << 16;
-		igt_assert((*forcewake_mt & bit) == 0);
+		reg = *forcewake_mt;
+		if (reg & bit) {
+			igt_warn("Bit %u did not clear! (val=%x)\n",
+				 t->bit, reg);
+			return (void *)-1;
+		}
 	}
 
 	return NULL;
@@ -121,13 +135,39 @@ static void *thread(void *arg)
 
 #define MI_STORE_REGISTER_MEM                   (0x24<<23)
 
+static void *mmio_base;
+
+static void cleanup(int sig)
+{
+	volatile uint32_t *forcewake_mt =
+		(uint32_t *)((char *)mmio_base + FORCEWAKE_MT);
+	unsigned int bit;
+
+	for (bit = 2; bit < 16; bit++) {
+		uint32_t val = 1 << bit;
+		uint32_t reg;
+
+		*forcewake_mt = val << 16;
+		reg = *forcewake_mt;
+		if (reg & val)
+			igt_warn("Failed to restore bit %u! (val=%x)\n",
+				 bit, reg);
+	}
+}
+
 igt_simple_main
 {
 	struct thread t[16];
+	bool success = true;
 	int i;
 
+	mmio_base = igfx_get_mmio();
+
 	t[0].fd = drm_open_driver(DRIVER_INTEL);
-	t[0].mmio = igfx_get_mmio();
+	t[0].run = true;
+	t[0].mmio = mmio_base;
+
+	igt_install_exit_handler(cleanup);
 
 	for (i = 2; i < 16; i++) {
 		t[i] = t[0];
@@ -201,4 +241,23 @@ igt_simple_main
 
 		usleep(1000);
 	}
+
+	for (i = 2; i < 16; i++)
+		t[i].run = false;
+
+	for (i = 2; i < 16; i++) {
+		void *threadret = NULL;
+		int ret;
+
+		ret = pthread_join(t[i].thread, &threadret);
+		if (ret) {
+			igt_warn("failed to join thread%u! (%d)\n", i, ret);
+			success = false;
+		} else if (threadret) {
+			igt_warn("thread%u failed! (%p)\n", i, threadret);
+			success = false;
+		}
+	}
+
+	igt_assert(success);
 }
-- 
2.14.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-03-02  8:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 16:48 [Intel-gfx] [CI i-g-t] don't look Tvrtko Ursulin
2018-03-01 17:31 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-03-02  2:49 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-03-02  8:49 ` Tvrtko Ursulin [this message]
2018-03-02 18:04 ` [igt-dev] ✓ Fi.CI.BAT: success for don't look (rev2) Patchwork
2018-03-02 21:46 ` [igt-dev] ✗ Fi.CI.IGT: failure " 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=20180302084958.23566-1-tvrtko.ursulin@linux.intel.com \
    --to=tursulin@ursulin.net \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=tvrtko.ursulin@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox