From patchwork Fri Mar 2 08:47:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10253627 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 D63A660211 for ; Fri, 2 Mar 2018 08:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C61F228896 for ; Fri, 2 Mar 2018 08:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAA77288B8; Fri, 2 Mar 2018 08:48:09 +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 0A62428896 for ; Fri, 2 Mar 2018 08:48:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8308A6EDE7; Fri, 2 Mar 2018 08:48:07 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7AC9E6EDE7 for ; Fri, 2 Mar 2018 08:48:06 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id k9so9216193wre.9 for ; Fri, 02 Mar 2018 00:48:06 -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:in-reply-to:references; bh=lph23TAcCMqjwWnNqYyYAqFwzqRYc8ko31HWVjgu3x4=; b=mmUi63Rqk7k1bJdG8nTcISF9AVKNA3ZBy1TodwFYV2vKZn2zVZiFPLEi9zYV7Mc1+6 aKJfdzhiLsP4WO0GfVbYDG2Vh8x7ELbRnfJBwkUAHtc4c1H6gwr4Nftz93ui+Pnj2G3T zEqpfnZi0gN0cFKdT3OxQNPZnzgvQA1knh+wTa4RFWrmVUZV2rTxm7JiGFQ9sqIoz/Yi 7xAe0bKhMW/nTLME8pjH6JvTSLWcLjliT4pwTslABVhQ/Vtltl5DRDWT9xnmMRa3Jg3/ OiAOKqXqHrHRygJ1aSACx+U9IOzsbQqSbdLKEUnOk6S/pnri2mnvLkqOmoIt6/7HS9C1 syYQ== 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:in-reply-to :references; bh=lph23TAcCMqjwWnNqYyYAqFwzqRYc8ko31HWVjgu3x4=; b=DI3I1sV1AjxQUiDwxC1Vpf3UB9ImhXH/kVCHeWS7aGImAcMuU8NBS2tdeV1Z9qpMKj Cs225/corCyLLJawKSaj1gKPyTp/XFp5jjMRYyHO1MmvxEsrU42u7lE7MnU303SHaXbH Q1qWdtBfhJWPhkPjGg93IdUXA3TE2ngB6FnMvH9xC3N4bLdY/uRSijkGIQbwQK9EOAGD CWW9SqKaGvyUO162eSnznEnr6mbhS2mmOd5jWk7O+S2ZnepucP7a8q+GhOKaztZt3Gl2 ZK7u1e84HMjQtpD23eTjSkky8q2LP8d5LEKRMo6E/E3PoJLzLLe/TwkmSAR4jbNZfFWJ vQMA== X-Gm-Message-State: APf1xPBA9jLbokhzt/5CACg0LWu4tVqtVPnD+XDb8nuxWOuZ/wLIuzl9 nM4Ig1963dOGIVv7Rg7X5GJ4fBzc X-Google-Smtp-Source: AG47ELs8eAowKhFAdZym8oKHdkXGg78H+BK6t2CxBvinhNY3dcSUXvyQiR3xZEflCj2uLjNsknWx+g== X-Received: by 10.223.199.137 with SMTP id l9mr4579113wrg.6.1519980484929; Fri, 02 Mar 2018 00:48:04 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id c14sm5445949wrd.17.2018.03.02.00.48.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 00:48:04 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Fri, 2 Mar 2018 08:47:55 +0000 Message-Id: <20180302084755.23472-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180301143217.20884-1-tvrtko.ursulin@linux.intel.com> References: <20180301143217.20884-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t v2] 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. v2: Do not assert from the threads. Signed-off-by: Tvrtko Ursulin --- tests/gen7_forcewake_mt.c | 68 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/tests/gen7_forcewake_mt.c b/tests/gen7_forcewake_mt.c index 07320ef9e8ac..608217fe652a 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,14 +107,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 +134,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 +240,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); }