From patchwork Tue Jun 22 16:23:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 12338013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69075C49EA2 for ; Tue, 22 Jun 2021 16:24:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3824F60238 for ; Tue, 22 Jun 2021 16:24:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3824F60238 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D5C5C6E5CC; Tue, 22 Jun 2021 16:24:16 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2059.outbound.protection.outlook.com [40.107.237.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB0306E5C8; Tue, 22 Jun 2021 16:24:14 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PeRB1fCPeOaA3fCKc81b7YZGK7hD5Qxhp2VI+i/JVCu3rjNMrDxG703I/5VwJ9EmHhYx1wpazaxFzF+aIH+6gyqrsu9DA8EEG1uv82a0M+23F/1cpXmK6dJ44P+qqTOu1ZDYM89R8aLlqR3+BmE/Db5BAWTL34/CRzEl5+MYy4inJxiUNr5/XuSlozofHuu3jK0R9Ex13gsJvX+2srhga/9IdQnQFkmTZQst5FG9+fq52c/jCm2dSesM25Es1Go9Uh58LQJnPGuRPhj2oOej1ipFVxpF+ZtiahnzPZlx+RQTQAaTHPYRcZkZ5xVNdkSRmQDOvxQ2KxuZ2OqtVnE1Qg== 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-SenderADCheck; bh=1CaiVlPbXcMzNAIKpwZZwB1jg9zp/xGy6bWKgEEYdfw=; b=gXvH0Ra9+kWEixBR2PWBREbVU+67LATDQ5R1M3kOmnDy4OS6iSkLiz8Tq9ypa9PiyExYEVsROq3d0ZxBmuKrtKxvRy/xHA1T2xAwil+acKRlm/Y9TCKmtOXQfnFX8aYYL9lAGJLMd0rolK7OYnoZGF7JWrxwB8NxMdfqkkWB9YQIy7A5VFxNYw36f5fEHRtIEBVrXZVeDgZOoZlDMUJMBHa80dEyLjHjEEU78gYRtBScCZNoRLo99sn+3EtFcrYiJ+siB3EFl1Q14UlLc/FIcK+4YoNi9EhOB/jfC9Mq0m0HLyRSeOVSSDWH8SXESUvR3GnNdyNBwN64pIiKAgBfGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=1CaiVlPbXcMzNAIKpwZZwB1jg9zp/xGy6bWKgEEYdfw=; b=3JnNnu1ysrgUjKgCuyiabtgadEAO5bZOgyDxI7FWHitbMAXoZTGmp0EMo5QLZS6MhwqhbH9M9VzrWzpyIckmOqT6OC0LkhQir4PLaM7EcXgRzoKerwTXttjHtSIBDqHCiDSXBE4bN99CruFeXXFn3ld4fsmgt3J0lLFbTsgv64k= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none; lists.freedesktop.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) by SA0PR12MB4399.namprd12.prod.outlook.com (2603:10b6:806:98::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18; Tue, 22 Jun 2021 16:24:13 +0000 Received: from SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::9f8:ec71:6535:cd36]) by SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::9f8:ec71:6535:cd36%5]) with mapi id 15.20.4242.023; Tue, 22 Jun 2021 16:24:13 +0000 From: Andrey Grodzovsky To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 4/6] drm/amdgpu: switch gtt_mgr to counting used pages Date: Tue, 22 Jun 2021 12:23:37 -0400 Message-Id: <20210622162339.761651-4-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210622162339.761651-1-andrey.grodzovsky@amd.com> References: <20210622162339.761651-1-andrey.grodzovsky@amd.com> X-Originating-IP: [2607:fea8:3edf:49b0:5c6b:dde9:a4fe:685] X-ClientProxiedBy: YT1PR01CA0137.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::16) To SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from agrodzovsky-All-Series.hitronhub.home (2607:fea8:3edf:49b0:5c6b:dde9:a4fe:685) by YT1PR01CA0137.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18 via Frontend Transport; Tue, 22 Jun 2021 16:24:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aeb7a891-d1c4-43cd-4451-08d9359a2c21 X-MS-TrafficTypeDiagnostic: SA0PR12MB4399: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r5DiIst9sfXYH8/aTgFULAaGna1+G4lnMsTJnDKtSGuBhBCoA1e21ydta3Cm92HLomq91jqi8lkoSWHXLSa1BGojB3pcr3LACsLBOkiuCBHwF2vKXmDmClXh9RtoDw0gIA+cYA9uTbMWyLEIp7yEJpEq9wzcKvmK/E0CQj9SZ6b02D4hckpfQ+WvIw+s1qOuYQHIJNlJn58Y78Ol1tstsYDij3H65uveQutzWdc6b33I9yZmVfJYfW0b4nS37xWqSH3s6LWT1lBFRHzhU83qqcOLMS7NSUwGaWw61Lqw49eNL5ASvv74bBpFsJzLGtC8P3fwt9QTJQuDkPR5/zvq3kimByirUdOm879Bf8Oovu8RuZuLFgJwMzProNsHmIcR+61NxAvfgo34Ic3nSGCXfmGbnlcmpIGPq3fFRylwGb6cf/SpomoNOH4NThTu6fi7h9yw2YShQpCblco3xk/zyle8DzIn3SQVPlJPj/djRl9iqF1+4PO9P1jxHrM71oVP9oRiGiIwvS6kTS5phG6iCU4f7yYcDNtnIaz/ESv+35iLbpi5LEq1602AGoJ3F9xEVO2EBuwpqCpRgde08Itwb99Z0Xu+H2C9Q3jh7QlcMKA= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB4623.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(36756003)(66476007)(66556008)(66946007)(2616005)(44832011)(2906002)(8936002)(8676002)(5660300002)(6666004)(86362001)(6486002)(16526019)(186003)(66574015)(6512007)(6506007)(83380400001)(1076003)(52116002)(38100700002)(4326008)(498600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?0cWcNeNMclDmmlXYOQJ7aEJ+2ZoJ?= =?utf-8?q?DS6SVOtLWHe1joeQo8a8kJ0HG9Dw4kb6uEWC2vUEx2RG+wT2V5SA3IkWFhsyCp5n4?= =?utf-8?q?pM2qgJhwL31kcx/UlmOZWfkzz8pNuGQMVZ9ujEs9trM64TujpHVP+1CBA71CHSRlr?= =?utf-8?q?Le/KeTtI8593E9j6vspptfodXUrtOcDuXwvu0yQR6YRZlnTsuN0WnOF8rfCtsuDxT?= =?utf-8?q?JgNEqq10J91q1Eu5xfE4Ua40hM2bShrlCKsWvHxJVN6NhKld0Yyg0FA9/tlDT6WHd?= =?utf-8?q?SP268O9zGwHkTZzufNsDYXemn30/V/tX0wBNFwdWfDwlvCHix5Ny7Hr4+4tKbs4ph?= =?utf-8?q?wvpq7RdxhDdk+k+GncQJebCTV+c5Y488Tc0Rgw82WNjg2L85Z21/HciFw4F3H1Mcm?= =?utf-8?q?QkHxNAsEabW4X+yjbLC/iQ58MqanyJr0jR9iVFzK8c/Ul9Q4w2I9nIQgxx0uQBzOv?= =?utf-8?q?ZsEPniLZdv7pTEMsQmCxp9gfVy3/Z2OqJEh89nl3Y0mAqJYByCoYZ0lFLV8wLymq3?= =?utf-8?q?BVC2nu84oSynVebggfJiL9fcepilQpqx4KKWgtG8W/wGGQWxW4gFx1f2rlHkLmHaw?= =?utf-8?q?Hz43akyeG0bHDsc1qfDEvFhNHpznp1w7lIpnJde+HmKlweNjmedlhbvClJLhD8Dng?= =?utf-8?q?1ZWIfnuHCAqD3GtTcD/0WDx1qPR10kClTFRE8K+xRujygXML5HxsydpVcrlHmtTw+?= =?utf-8?q?v9orTBUN0S+vziLwE3E7u9upH+MyrDEY19ZS0vsbL8sMj0Mx+uqzTaZ0pkDCBiw6E?= =?utf-8?q?QXX/JO/Y4aYGDKeivlhLpWLvl22tLsvHhoHmibNxBasNkDUqbTH8P/dVb+b+Y8p65?= =?utf-8?q?cHA2rOhYse9SAg7lMLX/8IVnpwwl3rbJrvuB9hhNI2xU1l6SvuMH3Y/g/bGE4m8Fn?= =?utf-8?q?SUYdZ28jT/AH9AKO/FsdMM4HlpunHxOHfV72z6d/VQ4UVXufy7WwC2INGo8cDvm0h?= =?utf-8?q?jQc9Uohsxghwi/5XD9x/HwEO2Saa6RKtSC5aZclYGZ4GrHiL7Xo6hhprqTpKWf/nn?= =?utf-8?q?w476u7et9s9hemPmWEnPqbaDlMuyqcvEugCzs3jBVOjSl3J2zGlu8romoVtYbVWLT?= =?utf-8?q?ntlwRy8ITMZAswcNMujqjqmerVHiL4DQoflFjzDdo2K2pslkptqHu8PQg2oo0Cfj2?= =?utf-8?q?e27havNytohF9m/20UUyoOmSPZxYE8D1YdvhqC7xxUpyJQoW6p9FfyGKKpE4vuDF9?= =?utf-8?q?m63P2LIVHZ76Qkb7wYZBqjuz/siWS8SonUg0SOXdCSJTc5CqGMsWNBXQHtbj8qACP?= =?utf-8?q?j2I7BlIlGqi+dl5+/BvJe0kIbXtjQW/7fuS8oWtFWcoE+DbVL45UmMJKSWnBe3nRl?= =?utf-8?q?n8dkdHi3da0szqx?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: aeb7a891-d1c4-43cd-4451-08d9359a2c21 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB4623.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2021 16:24:13.3567 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9kQdOc0n5sppYN9PfZqF2A7t+FwaAPtPm8Wd3n05sLz1ViAk4hY6BPQu2LdV4VHubphn2OdYuM0L1AF0a/3l+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4399 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: , Cc: ckoenig.leichtzumerken@gmail.com, Lang.Yu@amd.com, =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Lang Yu Change mgr->available into mgr->used (invert the value). Makes more sense to do it this way since we don't need the spinlock any more to double check the handling. v3 (chk): separated from the TEMPOARAY FLAG change. Signed-off-by: Lang Yu Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 26 ++++++++------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c index b694dc96b336..495dd3bd4f1c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c @@ -132,14 +132,10 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, struct amdgpu_gtt_node *node; int r; - if (!(place->flags & TTM_PL_FLAG_TEMPORARY)) { - spin_lock(&mgr->lock); - if (atomic64_read(&mgr->available) < num_pages) { - spin_unlock(&mgr->lock); - return -ENOSPC; - } - atomic64_sub(num_pages, &mgr->available); - spin_unlock(&mgr->lock); + if (!(place->flags & TTM_PL_FLAG_TEMPORARY) && + atomic64_add_return(num_pages, &mgr->used) > man->size) { + atomic64_sub(num_pages, &mgr->used); + return -ENOSPC; } node = kzalloc(struct_size(node, base.mm_nodes, 1), GFP_KERNEL); @@ -177,7 +173,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, err_out: if (!(place->flags & TTM_PL_FLAG_TEMPORARY)) - atomic64_add(num_pages, &mgr->available); + atomic64_sub(num_pages, &mgr->used); return r; } @@ -202,7 +198,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man, spin_unlock(&mgr->lock); if (!(res->placement & TTM_PL_FLAG_TEMPORARY)) - atomic64_add(res->num_pages, &mgr->available); + atomic64_sub(res->num_pages, &mgr->used); kfree(node); } @@ -217,9 +213,8 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man, uint64_t amdgpu_gtt_mgr_usage(struct ttm_resource_manager *man) { struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man); - s64 result = man->size - atomic64_read(&mgr->available); - return (result > 0 ? result : 0) * PAGE_SIZE; + return atomic64_read(&mgr->used) * PAGE_SIZE; } /** @@ -269,9 +264,8 @@ static void amdgpu_gtt_mgr_debug(struct ttm_resource_manager *man, drm_mm_print(&mgr->mm, printer); spin_unlock(&mgr->lock); - drm_printf(printer, "man size:%llu pages, gtt available:%lld pages, usage:%lluMB\n", - man->size, (u64)atomic64_read(&mgr->available), - amdgpu_gtt_mgr_usage(man) >> 20); + drm_printf(printer, "man size:%llu pages, gtt used:%llu pages\n", + man->size, atomic64_read(&mgr->used)); } static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = { @@ -303,7 +297,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size) size = (adev->gmc.gart_size >> PAGE_SHIFT) - start; drm_mm_init(&mgr->mm, start, size); spin_lock_init(&mgr->lock); - atomic64_set(&mgr->available, gtt_size >> PAGE_SHIFT); + atomic64_set(&mgr->used, 0); ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager); ttm_resource_manager_set_used(man, true); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h index e69f3e8e06e5..3205fd520060 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h @@ -52,7 +52,7 @@ struct amdgpu_gtt_mgr { struct ttm_resource_manager manager; struct drm_mm mm; spinlock_t lock; - atomic64_t available; + atomic64_t used; }; struct amdgpu_preempt_mgr {