From patchwork Fri Sep 29 19:50:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 9978819 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 5073A60311 for ; Fri, 29 Sep 2017 23:24:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F78E28249 for ; Fri, 29 Sep 2017 23:24:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3000E29794; Fri, 29 Sep 2017 23:24:27 +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=BAD_ENC_HEADER,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 0583328249 for ; Fri, 29 Sep 2017 23:24:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C6D56E168; Fri, 29 Sep 2017 23:24:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 11933 seconds by postgrey-1.35 at gabe; Fri, 29 Sep 2017 23:24:21 UTC Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0076.outbound.protection.outlook.com [104.47.41.76]) by gabe.freedesktop.org (Postfix) with ESMTPS id 83F146E166; Fri, 29 Sep 2017 23:24:21 +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=7B043UP0IWJjR+8IOtUBcta//Cg1XtrNn4OERyWqpqw=; b=QISa7PxDyepg9UAoTpM3DcHyqK8Du0h8kK499TUv0MwWr26qETIvFPWR4a+X27m4eqZb4CBf08KzFrZ0pW/GLU7CHRTuKtHded7eYqpZbUeg3q6gakJcKnpkFqDOBiqXO8YplJdTJWvomcjlIscx4mXRWisypuXJYDUEkuCI3ck= Received: from MWHPR12CA0062.namprd12.prod.outlook.com (10.175.47.152) by MWHPR12MB1456.namprd12.prod.outlook.com (10.172.55.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Fri, 29 Sep 2017 19:50:44 +0000 Received: from DM3NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::200) by MWHPR12CA0062.outlook.office365.com (2603:10b6:300:103::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.56.9 via Frontend Transport; Fri, 29 Sep 2017 19:50:44 +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 SATLEXCHOV01.amd.com (165.204.84.17) by DM3NAM03FT045.mail.protection.outlook.com (10.152.82.208) 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; Fri, 29 Sep 2017 19:50:43 +0000 Received: from SCYBEXDAG01.amd.com (10.34.11.11) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 29 Sep 2017 14:50:42 -0500 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; Sat, 30 Sep 2017 03:50:38 +0800 From: Andrey Grodzovsky To: , Subject: [PATCH] amdgpu: Add deadlock detection test suit. Date: Fri, 29 Sep 2017 15:50:20 -0400 Message-ID: <1506714620-6048-1-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 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)(376002)(39860400002)(346002)(2980300002)(428002)(189002)(199003)(50466002)(97736004)(47776003)(6666003)(36756003)(68736007)(105586002)(5003940100001)(53416004)(77096006)(106466001)(33646002)(450100002)(305945005)(81156014)(356003)(4326008)(189998001)(53936002)(561924002)(5660300001)(8676002)(8936002)(2906002)(48376002)(101416001)(72206003)(54906003)(478600001)(575784001)(50226002)(110136005)(86362001)(50986999)(316002)(81166006)(16586007); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1456; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT045; 1:SEao+np1XyLnuF6Y3+SpzcfE9bYZYUvCEPmK+lOMhh2v0H1bb3bBBlTiw30Ogp9suyG3Lq9ht038XusLfcNksyyYxOUzkXup4MRDWOxIEFI5o/tpuLj/dY4DwrzAnpjh X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8047ead3-6798-4335-869d-08d507735ea1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR: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G0o3MuM4pCajotxiXfooXFuzMmJM8LWqIKa/GBJrCh4ihlVqJVOCLS7YhmK1rpz0vKcMdBCOiKyI2/Nm+06h+1foPN+NDm++OwjcO14XB4eFGybFR9B7fDP69yNq23eI/9abI2DijwrwMAdYNoLbyb+odJooqjPKvzM+gkGTZY9GfTfwHnLZbU//fkyXFua+avFOuNYUMC7AwuNyeYxjVbi0mZ26QZ9BPtHA0N1JKT/NKpVaO1TnkO2YdbOvlqe8UdKQEaZh9ovE4Mz6DrtRpgszZeVZjkCivAV9BdvXgRmSVdGm4GSu9iIS67yPn1ZmDetHQqmFLoW2N/SDuVQCY5QrIpRrDQyAYwEzTyDBa9d3fqoMX6wyCTpXMm7G5K5zm0D2gxttKs1hVsVPzGLVkreJhgZ1F9jVCZT39gU3bWePKR3H4vMvQiibVNfCwU5DHu+ZNoH//4v+XJUy+YPh67iDrhVmQijO3cJSa9EBxWu+unGTs6w0wuLHogEVLI 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)(3002001)(10201501046)(93006095)(93003095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR12MB1456; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR12MB1456; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1456; 4:Sd+qmCTxELcxonT/cHtk3ssOjUV/l02/0vcdMvV3ba9tNjxDgyuNMewUAiOd/+KhxXTRXmkAFums/CDqqfX1vjC62unzc8EOyhCBt7n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qWhpNbtJ23IXZTijFJUnN8u/91Xug4gBFkescUNMrtIKJZi/2SRm9brTMIq7b5z8VDgxq1JbNnapI/n6fF8mEO8BlxYFnNW4Ja3uds=; 7:JEH5ZKpWqZIUgG/PpOZbTECbcf1jJJpSnjtcXN5vl08BRF0SWNABAvtPskhHhI1gEUGqmyzsoB2l3AseoOrHskwW+B4Pw378RnPfh7+Z/1phvAU+2/r30uCqRfq1NRO6OFfvMRQjC+2wJCavCul7JCTbi/3vavbb1iHg8Z2k5Sf6LqXR/zYhqKjdf4Eneaufz7Nn/n14ab0OLT8byeuuJppZvFbuKovjqtvCzgfPt8c= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1456; 20:BvEvLb7fM4tWdVOiDtXIolqSFEJUoImyYmhE8EEXj++kBYrcg2fOgcgFBdyknbk5ymHSN0WqnCo2OGh0C6SJD+z5LM0RScyYmZYiySNRlqLxoZkyKY+u4r6G0GHuLhAu4xAo2EoXhwqMYL+c/C9mKOlsNunbkmtjSwBY41hsX/T0M/KT2wwbfkx0ZV9sW0WT5HiHmEZBojgck3UCQDJGZhxmdpBwombxQbJEUMM62Fphx+Iq98JB4ftE6oq1RU1U X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2017 19:50:43.0883 (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=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1456 Cc: Alexander.Deucher@amd.com, christian.koenig@amd.com 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. Change-Id: Ifc3a571481a85c947b107680cf17f59187180fe0 Signed-off-by: Andrey Grodzovsky --- tests/amdgpu/Makefile.am | 6 +- tests/amdgpu/amdgpu_test.c | 6 ++ tests/amdgpu/amdgpu_test.h | 15 +++ tests/amdgpu/deadlock_tests.c | 244 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 269 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..992d191 --- /dev/null +++ b/tests/amdgpu/deadlock_tests.c @@ -0,0 +1,244 @@ +/* + * Copyright 2014 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 2 + +#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 }, + { "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) +{ + /* + * BUG: Compute ring stalls and never recovers when the address is + * written after the command already submitted + */ + + /* 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); +}