From patchwork Thu Mar 1 14:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10251647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 964E360365 for ; Thu, 1 Mar 2018 14:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 866E72842D for ; Thu, 1 Mar 2018 14:32:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73FDB284AF; Thu, 1 Mar 2018 14:32:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C3E272842D for ; Thu, 1 Mar 2018 14:32:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 857DB6EC91; Thu, 1 Mar 2018 14:32:29 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 63E006EC91 for ; Thu, 1 Mar 2018 14:32:27 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id o76so6539516wrb.7 for ; Thu, 01 Mar 2018 06:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=je8uCvqQZC1hdFuHvnX4w9+X8OKXOhB5dJoBYwP9bLo=; b=g+q81cpZXigpiEpjM0nugWyszy9XybWu6ypctltRmQDeeqkv0E7tTtYQx7JgT/XaFk wMvEUx7EPg80BdARXNYKSf35ic9wh05whq7ORlmRfNQsO7z6uf5cEvs8nUSqOj1wvkFj u9KEBpqM4j8ZxZMeth74RUV7yhSMQ/vmrUix1i7/wQjEYbTysKTQ9mcgqg9MFgzyt51A wQnoPFv6MPd3vePjSnTxtLVFqzz2HKop0DARueHSw1/gys8qQ/PBjZxwGV85dVjnvu1j SzJHwUr+w4XE+FX4kU1/U0Sz3b/ohi0JQCzG1NvIAAIsIdTBvn0RKkKIHqklbRqP9wlj 9fTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=je8uCvqQZC1hdFuHvnX4w9+X8OKXOhB5dJoBYwP9bLo=; b=NIptoxelpPHDNXHL8cVvMYTqzViNMCyNOiW4AGSjx3Fo8YxEyfkioQN+ydOHuhRbFS Hep8y9ID7wRBQbc6TsNWIaNfemRuU0a5FTGhiu77trSVxWULt0lBpUaa522m+xJVrYBc fVbqVLKh7o7ZrmnzOuDqGEKMuSc8gBOkgEiFrWorsqmx42ieXaaMl6kA850hhIQKnmZB 4iApVBBd+pDTzm6hgEiBOET/EqiHaN96EfgKJ88+anYyhki92NZcUlpR0OU+GfJeKxkZ tWygUFUDo63CfaSXXrkoMWhtwmc6qhaTiQH6QFB16CBdEEfCcJi/UgOT16tWzCllr5RD Fl/w== X-Gm-Message-State: APf1xPCCRjGVZK7X4fcXl/2L4Q/ajqAhBsb6TYHwthZoxJeaQT11Ifc5 AGk5EkbCfXCkgfuh1WZzlAtVJw== X-Google-Smtp-Source: AG47ELtwyJMF3RiA9EtJQSo+TcgvA7jMUylfFQHyWb6LkDKvNfzgvd7YnVlu3GfmIOpQTBhEBoPjtw== X-Received: by 10.223.187.19 with SMTP id r19mr1905555wrg.110.1519914745857; Thu, 01 Mar 2018 06:32:25 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id g7sm3621802wrb.78.2018.03.01.06.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 06:32:25 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Thu, 1 Mar 2018 14:32:17 +0000 Message-Id: <20180301143217.20884-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [PATCH i-g-t] tests/gen7_forcewake_mt: Fix test X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin 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. Signed-off-by: Tvrtko Ursulin --- 50% speculation, compile tested only! --- tests/gen7_forcewake_mt.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/gen7_forcewake_mt.c b/tests/gen7_forcewake_mt.c index 07320ef9e8ac..a2dc33bbb9dd 100644 --- a/tests/gen7_forcewake_mt.c +++ b/tests/gen7_forcewake_mt.c @@ -44,6 +44,7 @@ IGT_TEST_DESCRIPTION("Exercise a suspect workaround required for" struct thread { pthread_t thread; + bool run; void *mmio; int fd; int bit; @@ -106,10 +107,11 @@ 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) { *forcewake_mt = bit << 16 | bit; igt_assert(*forcewake_mt & bit); *forcewake_mt = bit << 16; @@ -121,13 +123,33 @@ 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++) { + *forcewake_mt = (1 << bit) << 16; + if (*forcewake_mt & (1 << bit)) + igt_warn("Failed to restore bit %u!\n", bit); + } +} + igt_simple_main { struct thread t[16]; 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 +223,10 @@ igt_simple_main usleep(1000); } + + for (i = 2; i < 16; i++) + t[i].run = false; + + for (i = 2; i < 16; i++) + pthread_join(t[i].thread, NULL); }