From patchwork Mon Oct 2 18:12:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 9981245 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 ECA646029B for ; Mon, 2 Oct 2017 20:46:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDAFA28906 for ; Mon, 2 Oct 2017 20:46:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D27F32899D; Mon, 2 Oct 2017 20:46:50 +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 789BE28906 for ; Mon, 2 Oct 2017 20:46:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 301546E388; Mon, 2 Oct 2017 20:46:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0070.outbound.protection.outlook.com [104.47.41.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id 157806E24A for ; Mon, 2 Oct 2017 20:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=IMPbZMebpLkxBJOzWIkdE/FTo/iqcOzUYju0eviboiw=; b=joWQ9GCtv5SEj/4rZw3IB8yr6tDwlvKXvj0TgXwT9m0uNSh/7CnNZS3ovqUiwityhORJIyRJMd3AN6TDIPDjkZbtlTy6BnyWPKIMPMC1Yhr+7JC6iolDRbqfkpCV4CWpN4+RJ1arNuXnBsAHSNzgCOUmv1jUlrOnWv9DQeASeV4= Received: from CY1PR1201CA0011.namprd12.prod.outlook.com (10.169.17.149) by DM5PR12MB1451.namprd12.prod.outlook.com (10.172.38.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Mon, 2 Oct 2017 18:13:10 +0000 Received: from BY2NAM03FT024.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::201) by CY1PR1201CA0011.outlook.office365.com (2a01:111:e400:5b9a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.9 via Frontend Transport; Mon, 2 Oct 2017 18:13:09 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by BY2NAM03FT024.mail.protection.outlook.com (10.152.84.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.77.10 via Frontend Transport; Mon, 2 Oct 2017 18:13:09 +0000 Received: from SATLEXDAG01.amd.com (10.181.40.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 2 Oct 2017 13:13:08 -0500 Received: from SCYBEXDAG01.amd.com (10.34.11.11) by SATLEXDAG01.amd.com (10.181.40.3) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 2 Oct 2017 14:13:07 -0400 Received: from agrodzovsky-All-Series.amd.com (172.27.224.79) by SCYBEXDAG01.amd.com (10.34.11.11) with Microsoft SMTP Server id 14.3.361.1; Tue, 3 Oct 2017 02:13:03 +0800 From: Andrey Grodzovsky To: Subject: [PATCH v2] amdgpu: Add deadlock detection test suit. Date: Mon, 2 Oct 2017 14:12:52 -0400 Message-ID: <1506967972-6277-1-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <6aa0edb8-2472-3d0b-4e14-91b36f6050a8@gmail.com> References: <6aa0edb8-2472-3d0b-4e14-91b36f6050a8@gmail.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(2980300002)(428002)(189002)(199003)(72206003)(189998001)(54906003)(5820100001)(2351001)(6666003)(50466002)(97736004)(101416001)(36756003)(2950100002)(6916009)(50226002)(68736007)(316002)(50986999)(76176999)(305945005)(77096006)(478600001)(23676002)(2870700001)(33646002)(5660300001)(561924002)(86362001)(2906002)(575784001)(356003)(8936002)(106466001)(81166006)(53416004)(47776003)(105586002)(8676002)(53936002)(81156014)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1451; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT024; 1:Lq8mCgzuRu53uJbzMrTtftzd+OhxLi+55wQuRS/U6RnSlxsDAXTlm+fWMGEhVR09D/zs2It66Xdh0mkUZsbxoGKH7tcbGMDkscbrPSJRZB7YAVUEK2eUuWghmDrJtTdM X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 569faab1-c67a-4c09-8fd2-08d509c13cdc X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DM5PR12MB1451; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1451; 3:fNp34hQxthcjz2LjZCRRmvKbBdCa+5EydAX+7TPFD1vPLBNz0erNKWtbdyqCZXuTjmqR+OVWH0XNVrekOid6W0Cp4rTdBCnp6K2vuWYatB3J6oKE6+rUCbM/ftFqN+cQHKehKzx5JGLFW8oZNi240tGFqeqv4HS56ZimjiaMYVu7EbTIfSgqJjmofYLN+D6yJBNSIHDblCkgToxMrv8kEyasoC2gafacWcbQhbRWUe8Y7I1ifVcK8YzxpYCeqkiSTuSwj5dXD9zfWsebhKhrAZ5tASGEyisZ1mu9bgh0u0V6XIM06HgN9xHCQibJg90vQYHUc8gF2KiA6pBOav+s7Ty08L4NxihCAJfMy4BtvFc=; 25:M/bDGF6XwFhI/UJfKpM/VXdAZG5//TFlK9tYHCnddONfT2pbTrHIlppv/r7u/pdQdzOP4emkuMGHduMLtgAUAWD3PK1kSF89D6t0X2/+m0wrw/rhsvi+OalpV4kPlouX9TGhKBl/x1ruXR8OJTHhYGE2QnzN7qT41CnFH/+1W4ck2kM9fPRJtr7siZ+lGH2Foo4gDxdE7Nb1TtYLIPb0IKGA9wEr8W8Vd3tUDeg9jtkbnjBLeTU0cW8gSgWolLLdf0iIt96dUyVq0B+iTjiT4nuObQtqw1FaHHIndXQcHQmzfNcubneuQ0On7WHtWGnP7qnTbRgzGG4Lue+muKvBDw== X-MS-TrafficTypeDiagnostic: DM5PR12MB1451: X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1451; 31:9tchNNITKZe3/j/xwyUyu4W9XoKi19GaVQPvJ8YIFlXQhi674KLR/ROyO46Lo25C71XeJ/LG8/jtdQ36dxVm72seJEanz+/1HaFtokSUZfieEpt+G9z9WUKlKSw/NBeiV7TkZlkqc0QVKGmPQenLojgVhdgWwWAD3M/G2coIOSoss6nuYwGlCOsXXh9DRRvq6Ynwe1lTN/R1sj/vIKT2YjhdD4ZnGcpZiwg2qugBEQQ=; 20:BBeRB083emHAr/04ORoxxkOHpbttI5kAGcp1EFXzRQ1UjcgtdarbT5NDFsgBd0mNlV2IR4MtyEDdnsXlzi9XPJciBxfEWCifU/1baP6VednN4lGqNdkj/mQBo8MSZ7Dc86TdBv0EEXGcuTveHYEGw+fI5uy0eMu2SNvrTsfdS/4EW7R6pf1OAGnNJDUIA7fFTRwhq6rbR7Z8QrAt1O44fR23nLEKfkNoRI709QlUhgALDmSCZq+8PLt/1P4BBIQV+I8damHNQACOCBn32u6Ua92HizGYRA61DrliSRnuoA07ymXzaBizild/Mx5g4/WfaT7rB+s2IP2CA7LtunZ1k0ZSBOlQseHVJvbYjJnbyAR+0e7PY5HVtQVkWkKaiZO/47C4Dc1KuNxtf3TSjSy2V2erx4CWZFu6P4n5RU7IqSGXz+fFJllNmJZlKKCKRF5laARYJ4X2UMa/RZ9QHksCTnEKPoqpqsW8mgcEIJMb0wmTV+S1vapIS3fEJ3hpZi8B X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(100000703101)(100105400095)(3002001)(93006095)(93003095)(6055026)(6041248)(20161123555025)(20161123564025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR12MB1451; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR: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UluK3NxanRzb1kwSTR5U25KdlFFWThrQzRnWXlncDNYY1p6WUZo?= =?utf-8?Q?y1qJeXgMKEYQK5ZqwuHgthQFE=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1451; 6:dU9jhpvAOONSyrsWXBjwOfLz2eG4ryAxqo1aXQaw7n1w2kxZmhii/OO85cOPF3k9AwQ0eAwbqscyuTb3O5U52pyzb57OGD3dt0K/9rw1g8XVE3HGX61Eib5mA7m1ers+VE2P8vKtvhO1Czh+d4edneeCmTDCjD7ro3qoz8svKXWG1RX8ZTX3CQkprqcvl9E4MzHc7q7bjNc+i7pUzw9+QB71rcikFOZh5jVinK7TPhk/3QPOZzdftAnAR7VefCR8JiYuPC4NDOtHynz5GTsZ7aB7HcQE8FO/4uUD20izckfafdfzrRXC2NjkuWKUsz1p/KXdbOUwkz5MMLjFoUGsjg==; 5:24oJrL0E6TSsWgkEUBATROlDOzhMee21GE2GiUYWaaO4f8hiG8nFOMu8mDc9wQFEs3XZZGDbd++o2XVI2PG6sBC2UdzYSp16CxWX3w/tjBON2vx919NGL92UO+axx4n5NH51ll9g+7nGo5wVYwMyHA==; 24:7eaXfrhu80khCSuB08++lriUP01wVDM7ILQcvUMprJXTPi8qDx+qTqICByyyaMk2pEyJDe3b1f951y3xE9/5jw3+HpqKsCxNr9Bpjmorw2Q=; 7:51ZVTaDZ4Dtw26jK7nJnhArBxh6vj3O0v2aJDe8m01l2v1j6yV5y/cj6fW2WLD/yR0UR1VnqMh4nbiy2FjIgAPulvIpa5B0QO0g9TItRrRHuQXhUUJkcTyHLgt75AoUBnPFLDRNKAPpWXk4vXrLFaa6ZVjLXQLgVwbtprBg+2rsO/mnCwAIQNVsnIlXzvN/1tx839trBJvE/fC55GMJvOQJfLrcug8i6h4vHz19qEgA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1451; 20:yKnQLnmp+I3+O+tNKPiXLue06ulnR4gHcDoixTqvjngNCLfDAEw52uHq7o2JGQxbweNsWyvsKBg+m8IfpoDi2+UvQycgnbKY7mRgs7gsdt5hTv5TWRVXw7KAVzf+l22oARG2iHd7o+vMDFMX37ny5MPQgXP9bBBVRCpHQ6iwgF8smX+eSqS5uyrKHr43Nmz/6SL8fOxbVWUYv5QE9BUysaCdNDV0AO8MQ4vHLsHDRnPSIAMmPPBqwg4iH3+E+nLR X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2017 18:13:09.5031 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1451 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Andrey Grodzovsky Adding initial tests for locks detection when SW scheduler FIFO is full. The test works by submitting a batch of identical commands which make the CP stall waiting for condition to become true. The condition is later satisfied form a helper thread. Other events that happen during this time might create deadlock situations. One such example is GPU reset triggered by this stall when amdgpu_lockup_timeout != 0. v2: Increase the delay from 2 to 100 ms. Comment out the compute test until it's working. Typos fix. Signed-off-by: Andrey Grodzovsky Reviewed-by: Christian König --- tests/amdgpu/Makefile.am | 6 +- tests/amdgpu/amdgpu_test.c | 6 ++ tests/amdgpu/amdgpu_test.h | 15 +++ tests/amdgpu/deadlock_tests.c | 245 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 tests/amdgpu/deadlock_tests.c diff --git a/tests/amdgpu/Makefile.am b/tests/amdgpu/Makefile.am index 9c02fd6..8700c4d 100644 --- a/tests/amdgpu/Makefile.am +++ b/tests/amdgpu/Makefile.am @@ -1,7 +1,8 @@ AM_CFLAGS = \ -I $(top_srcdir)/include/drm \ -I $(top_srcdir)/amdgpu \ - -I $(top_srcdir) + -I $(top_srcdir) \ + -pthread LDADD = $(top_builddir)/libdrm.la \ $(top_builddir)/amdgpu/libdrm_amdgpu.la \ @@ -29,4 +30,5 @@ amdgpu_test_SOURCES = \ frame.h \ uvd_enc_tests.c \ vcn_tests.c \ - uve_ib.h + uve_ib.h \ + deadlock_tests.c diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c index cd6b826..9925503 100644 --- a/tests/amdgpu/amdgpu_test.c +++ b/tests/amdgpu/amdgpu_test.c @@ -97,6 +97,12 @@ static CU_SuiteInfo suites[] = { .pCleanupFunc = suite_uvd_enc_tests_clean, .pTests = uvd_enc_tests, }, + { + .pName = "Deadlock Tests", + .pInitFunc = suite_deadlock_tests_init, + .pCleanupFunc = suite_deadlock_tests_clean, + .pTests = deadlock_tests, + }, CU_SUITE_INFO_NULL, }; diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h index d0b61ba..ece93f4 100644 --- a/tests/amdgpu/amdgpu_test.h +++ b/tests/amdgpu/amdgpu_test.h @@ -135,6 +135,21 @@ int suite_uvd_enc_tests_clean(); extern CU_TestInfo uvd_enc_tests[]; /** + * Initialize deadlock test suite + */ +int suite_deadlock_tests_init(); + +/** + * Deinitialize deadlock test suite + */ +int suite_deadlock_tests_clean(); + +/** + * Tests in uvd enc test suite + */ +extern CU_TestInfo deadlock_tests[]; + +/** * Helper functions */ static inline amdgpu_bo_handle gpu_mem_alloc( diff --git a/tests/amdgpu/deadlock_tests.c b/tests/amdgpu/deadlock_tests.c new file mode 100644 index 0000000..e23d903 --- /dev/null +++ b/tests/amdgpu/deadlock_tests.c @@ -0,0 +1,245 @@ +/* + * Copyright 2017 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#ifdef HAVE_ALLOCA_H +# include +#endif + +#include "CUnit/Basic.h" + +#include "amdgpu_test.h" +#include "amdgpu_drm.h" + +#include + + +/* + * This defines the delay in MS after which memory location designated for + * compression against reference value is written to, unblocking command + * processor + */ +#define WRITE_MEM_ADDRESS_DELAY_MS 100 + +#define PACKET_TYPE3 3 + +#define PACKET3(op, n) ((PACKET_TYPE3 << 30) | \ + (((op) & 0xFF) << 8) | \ + ((n) & 0x3FFF) << 16) + +#define PACKET3_WAIT_REG_MEM 0x3C +#define WAIT_REG_MEM_FUNCTION(x) ((x) << 0) + /* 0 - always + * 1 - < + * 2 - <= + * 3 - == + * 4 - != + * 5 - >= + * 6 - > + */ +#define WAIT_REG_MEM_MEM_SPACE(x) ((x) << 4) + /* 0 - reg + * 1 - mem + */ +#define WAIT_REG_MEM_OPERATION(x) ((x) << 6) + /* 0 - wait_reg_mem + * 1 - wr_wait_wr_reg + */ +#define WAIT_REG_MEM_ENGINE(x) ((x) << 8) + /* 0 - me + * 1 - pfp + */ + +static amdgpu_device_handle device_handle; +static uint32_t major_version; +static uint32_t minor_version; + +static pthread_t stress_thread; +static uint32_t *ptr; + +static void amdgpu_deadlock_helper(unsigned ip_type); +static void amdgpu_deadlock_gfx(void); +static void amdgpu_deadlock_compute(void); + +int suite_deadlock_tests_init(void) +{ + struct amdgpu_gpu_info gpu_info = {0}; + int r; + + r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle); + + if (r) { + if ((r == -EACCES) && (errno == EACCES)) + printf("\n\nError:%s. " + "Hint:Try to run this test program as root.", + strerror(errno)); + return CUE_SINIT_FAILED; + } + + return CUE_SUCCESS; +} + +int suite_deadlock_tests_clean(void) +{ + int r = amdgpu_device_deinitialize(device_handle); + + if (r == 0) + return CUE_SUCCESS; + else + return CUE_SCLEAN_FAILED; +} + + +CU_TestInfo deadlock_tests[] = { + { "gfx ring block test", amdgpu_deadlock_gfx }, + + /* + * BUG: Compute ring stalls and never recovers when the address is + * written after the command already submitted + */ + /* { "compute ring block test", amdgpu_deadlock_compute }, */ + + CU_TEST_INFO_NULL, +}; + +static void *write_mem_address(void *data) +{ + int i; + + /* useconds_t range is [0, 1,000,000] so use loop for waits > 1s */ + for (i = 0; i < WRITE_MEM_ADDRESS_DELAY_MS; i++) + usleep(1000); + + ptr[256] = 0x1; + + return 0; +} + +static void amdgpu_deadlock_gfx(void) +{ + amdgpu_deadlock_helper(AMDGPU_HW_IP_GFX); +} + +static void amdgpu_deadlock_compute(void) +{ + amdgpu_deadlock_helper(AMDGPU_HW_IP_COMPUTE); +} + +static void amdgpu_deadlock_helper(unsigned ip_type) +{ + amdgpu_context_handle context_handle; + amdgpu_bo_handle ib_result_handle; + void *ib_result_cpu; + uint64_t ib_result_mc_address; + struct amdgpu_cs_request ibs_request; + struct amdgpu_cs_ib_info ib_info; + struct amdgpu_cs_fence fence_status; + uint32_t expired; + int i, r, instance; + amdgpu_bo_list_handle bo_list; + amdgpu_va_handle va_handle; + + r = pthread_create(&stress_thread, NULL, write_mem_address, NULL); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_cs_ctx_create(device_handle, &context_handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_alloc_and_map(device_handle, 4096, 4096, + AMDGPU_GEM_DOMAIN_GTT, 0, + &ib_result_handle, &ib_result_cpu, + &ib_result_mc_address, &va_handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_get_bo_list(device_handle, ib_result_handle, NULL, + &bo_list); + CU_ASSERT_EQUAL(r, 0); + + ptr = ib_result_cpu; + + ptr[0] = PACKET3(PACKET3_WAIT_REG_MEM, 5); + ptr[1] = (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */ + WAIT_REG_MEM_FUNCTION(4) | /* != */ + WAIT_REG_MEM_ENGINE(0)); /* me */ + ptr[2] = (ib_result_mc_address + 256*4) & 0xfffffffc; + ptr[3] = ((ib_result_mc_address + 256*4) >> 32) & 0xffffffff; + ptr[4] = 0x00000000; /* reference value */ + ptr[5] = 0xffffffff; /* and mask */ + ptr[6] = 0x00000004; /* poll interval */ + + for (i = 7; i < 16; ++i) + ptr[i] = 0xffff1000; + + + ptr[256] = 0x0; /* the memory we wait on to change */ + + + + memset(&ib_info, 0, sizeof(struct amdgpu_cs_ib_info)); + ib_info.ib_mc_address = ib_result_mc_address; + ib_info.size = 16; + + memset(&ibs_request, 0, sizeof(struct amdgpu_cs_request)); + ibs_request.ip_type = ip_type; + ibs_request.ring = 0; + ibs_request.number_of_ibs = 1; + ibs_request.ibs = &ib_info; + ibs_request.resources = bo_list; + ibs_request.fence_info.handle = NULL; + + for (i = 0; i < 200; i++) { + r = amdgpu_cs_submit(context_handle, 0,&ibs_request, 1); + CU_ASSERT_EQUAL(r, 0); + + } + + memset(&fence_status, 0, sizeof(struct amdgpu_cs_fence)); + fence_status.context = context_handle; + fence_status.ip_type = ip_type; + fence_status.ip_instance = 0; + fence_status.ring = 0; + fence_status.fence = ibs_request.seq_no; + + r = amdgpu_cs_query_fence_status(&fence_status, + AMDGPU_TIMEOUT_INFINITE,0, &expired); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_list_destroy(bo_list); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_unmap_and_free(ib_result_handle, va_handle, + ib_result_mc_address, 4096); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_cs_ctx_free(context_handle); + CU_ASSERT_EQUAL(r, 0); + + pthread_join(stress_thread, NULL); +}