From patchwork Sun May 12 07:59:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 13662601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7FDCAC10F1A for ; Sun, 12 May 2024 07:59:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 90E6D10E080; Sun, 12 May 2024 07:59:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="VEc90iIx"; dkim-atps=neutral Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2061.outbound.protection.outlook.com [40.107.243.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id BFA5610E080; Sun, 12 May 2024 07:59:34 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XrC7A2WYckN3/gWCCmIyEuH7e4gbyFiMfxqwYyH1qEu2hfFlWjGRwnVSUEuSKB8Ssl7u41/kzZxLn6K8/8Cnf6WXL9QZ13wQcLtwooAdPxYu0/CVuAX6c/VKUdLNA8d0mP30b2aBGq3gcNL5XPjt5vVuAAZZ18DWnt/wwb48G45Hy46mUzjg+gvN1SOgxfif5iFI2tcL5VXhXm6uAhGiuRCSCAMibPX4/YPOnZhY1y64UDjoashNZDpt215zUD4JS0y9x42RmRw7qcF6dJKVVroUx3GE8U6ukqRyd2s74SiMJQvmQFQhMQ2tEN3W/A+Rbt79A6zGcB5A+2ty3P1S9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xc3gbNccS9zJ/rrk71j++WVUrMYjipHEuqz8Z8YblXo=; b=gUI+HGD7xDqOC9FNEUAT5ru48UuXJ0gjGLwm4m+Zv0x5IG52/4xGNbI2IcfFNkPtwVH4n6ZQCMsO/yf3K9OOzkOIpTBFWq6LmB26Om3/kL+PXLZ0AQu8VsPCixCMJJrWQjIdILT2mGvcxobwQXtXyWWie1JhaZzFXx5oiE0kaxRjxbEt6VGv/rHLyftkEQfgo266EUDFyuHN9pkzl5d8LkKzDr5aJUiL0FBA0c9wqDGo40BlPI/EyJyorXbxILoGPoA1YE7XNsWw/bmyh2qpF9K1wTiEzMuHTibvnDMk1YrQBN5kFMUKjM9nGx/Ud6Ij9sd+kCzIkpXnrzqsDdk5ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xc3gbNccS9zJ/rrk71j++WVUrMYjipHEuqz8Z8YblXo=; b=VEc90iIxotAagVwbA2IVlJ0uf0PqOtJAQUuQ1bH2pPr5R+we3SXbZKyP6ctV7nzIctHSebyB4+HdK7Cd1YdUbV9LI9L5c6xarVqldEipV6I5XLTFsxY3i75wZkYzyZliSXpBAEj2IUv33Et313DyquBYHQ7U4aXXhdXWpo3C/6I= Received: from BL1PR13CA0425.namprd13.prod.outlook.com (2603:10b6:208:2c3::10) by SN7PR12MB7105.namprd12.prod.outlook.com (2603:10b6:806:2a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Sun, 12 May 2024 07:59:29 +0000 Received: from BL6PEPF0002256F.namprd02.prod.outlook.com (2603:10b6:208:2c3:cafe::95) by BL1PR13CA0425.outlook.office365.com (2603:10b6:208:2c3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.21 via Frontend Transport; Sun, 12 May 2024 07:59:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0002256F.mail.protection.outlook.com (10.167.249.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Sun, 12 May 2024 07:59:28 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 12 May 2024 02:59:26 -0500 From: Arunpravin Paneer Selvam To: , , CC: , , , Arunpravin Paneer Selvam Subject: [PATCH v2 2/2] drm/tests: Add a unit test for range bias allocation Date: Sun, 12 May 2024 13:29:09 +0530 Message-ID: <20240512075909.2688-2-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240512075909.2688-1-Arunpravin.PaneerSelvam@amd.com> References: <20240512075909.2688-1-Arunpravin.PaneerSelvam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0002256F:EE_|SN7PR12MB7105:EE_ X-MS-Office365-Filtering-Correlation-Id: fbf741a0-6e2b-4d35-aa9f-08dc72597309 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: 5NiwqxvAcRL+miTYQfbpqQi+FHzFd4Pc+h894ymBAausPsOtx77zr3VxbVNRKOeMjgkb+q08/V/lbjn+d7SGThKNcTA7Rqmukq6ihriIgwUjRRanGTto/8P9hXmJTwnEQZfAVl0pjsaAYCd5bkh+grwn+iXs98JfGJ8Dhb5/GfwBvkQUojmAP4AQGGhvVMLU9hdZf3SvKYP5ej6pFqnEZHfSiYKF8hmTKkx38FnGTsxjExRVnxsNF6f2GgCldmlkaLDw0u1m8UF5rwVv4W3LKF4eo8wPyrq/v4Xjv7TrBz/o5fru0846ZT/UQacqJdiQFzV4hQ2E7eB7equ3NQD6HN0YUL+Bi2RnPZdWsueaIvcoduHAJe5amZ7iS5Cqw4GxKVfkUfq7kFsHC5MIWekDj/I1hgL3C9shsqXVeBth87jXsYfbfuUWxU6SQzA6rcIcbXQx+46mAAAyybTtXvo3Xe1Qb7cAMGlXHVxQZWoi0UxVqcq6CAgqDRtMnHsaRbutASjOnp2dUQL0v1LvkftuY4HNcvEs2lSJmadh5NGQbrGmi6uaYlBVOxVhLrnEALftgoZq9HuGsFlK2fuCdY+rfvPJOsNCibFOLYtA0eYolH48OpcjBVxSpxl8muzL0+ksdaMp6UxQUkOiFPTJcug9nY/9L4nNCQC2nUncKG/SQ5yyXQMd55bel0yVPIQwQbVGTo+bcx03lHCFGr0PAtUsa4JolxEfgb8fe6jxloNENPWX2Rg+PohlvUbtjLwMcrcysCm11qcwGDOA2lHzLkuBrnyM2nGB7WgGfkmQOwm/fXFl7Q7ENzm85+1PqZV6JYU2SdK62iMTPzKNQsBKbiJ0MMxl7u/hkETr5yjD8QWqcKlYpw/sA9az6AMsSum4rlndt4e28C8m5HLJiVhcc+3oZSpnj8JklqAk0ZnpknG28GISz5p0GqvxwiHqqF4eQqCEQCmsJSx4KZZ6+S0YjRWec5B/e3xx/8fv7IzKo8T/ecWt5+YXC6ceKmtWaCS8XpbLrXm2rcAYzgfQQdi/nFQAyTQKpM8FDW6xJ8E1/5xT/Sh/uRYSmcnlWfFgPvVUcV1Vkyf8XRe7f0lPWmHLLKfYQrqrA/Mfe1NbxsfElJ3Ud+D2ziKjvsNKpp1B0qWzRg2cWhlnUDBKS3lMWAavIaztx/hs72gXii9sagqFGLjP/H5nDNE+mb39y0oXknQCjg5uWtwSBrFJoe56nrY29LlRthmY5CWaorpk1FfjCmJ6y/mqE5Rtuhtq5F0M02LnlqfUxHAh+rYsFJC87UAXeOoyz9edmTvsTcYbbUuWfP2LLO+OtczvfG0iMHLzC/TQuto/kwtx+FeCV6L3vd3WyIabk559za+bnp3CgyDf2qbVxR7MYrCwRXnyN8iDEc756FvW X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(82310400017)(1800799015)(376005)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2024 07:59:28.6968 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fbf741a0-6e2b-4d35-aa9f-08dc72597309 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0002256F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7105 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Allocate cleared blocks in the bias range when the DRM buddy's clear avail is zero. This will validate the bias range allocation in scenarios like system boot when no cleared blocks are available and exercise the fallback path too. The resulting blocks should always be dirty. Signed-off-by: Arunpravin Paneer Selvam Reviewed-by: Matthew Auld --- drivers/gpu/drm/tests/drm_buddy_test.c | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c index e3b50e240d36..a194f271bc55 100644 --- a/drivers/gpu/drm/tests/drm_buddy_test.c +++ b/drivers/gpu/drm/tests/drm_buddy_test.c @@ -26,6 +26,8 @@ static void drm_test_buddy_alloc_range_bias(struct kunit *test) u32 mm_size, ps, bias_size, bias_start, bias_end, bias_rem; DRM_RND_STATE(prng, random_seed); unsigned int i, count, *order; + struct drm_buddy_block *block; + unsigned long flags; struct drm_buddy mm; LIST_HEAD(allocated); @@ -222,6 +224,39 @@ static void drm_test_buddy_alloc_range_bias(struct kunit *test) drm_buddy_free_list(&mm, &allocated, 0); drm_buddy_fini(&mm); + + /* + * Allocate cleared blocks in the bias range when the DRM buddy's clear avail is + * zero. This will validate the bias range allocation in scenarios like system boot + * when no cleared blocks are available and exercise the fallback path too. The resulting + * blocks should always be dirty. + */ + + KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_init(&mm, mm_size, ps), + "buddy_init failed\n"); + mm.clear_avail = 0; + + bias_start = round_up(prandom_u32_state(&prng) % (mm_size - ps), ps); + bias_end = round_up(bias_start + prandom_u32_state(&prng) % (mm_size - bias_start), ps); + bias_end = max(bias_end, bias_start + ps); + bias_rem = bias_end - bias_start; + + flags = DRM_BUDDY_CLEAR_ALLOCATION | DRM_BUDDY_RANGE_ALLOCATION; + u32 size = max(round_up(prandom_u32_state(&prng) % bias_rem, ps), ps); + + KUNIT_ASSERT_FALSE_MSG(test, + drm_buddy_alloc_blocks(&mm, bias_start, + bias_end, size, ps, + &allocated, + flags), + "buddy_alloc failed with bias(%x-%x), size=%u, ps=%u\n", + bias_start, bias_end, size, ps); + + list_for_each_entry(block, &allocated, link) + KUNIT_EXPECT_EQ(test, drm_buddy_block_is_clear(block), false); + + drm_buddy_free_list(&mm, &allocated, 0); + drm_buddy_fini(&mm); } static void drm_test_buddy_alloc_clear(struct kunit *test)