From patchwork Mon May 31 08:22:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lang Yu X-Patchwork-Id: 12288859 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.8 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,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 C65E2C4708F for ; Mon, 31 May 2021 08:23:21 +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 7C8E36103E for ; Mon, 31 May 2021 08:23:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C8E36103E Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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 3A10A8826D; Mon, 31 May 2021 08:23:20 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2088.outbound.protection.outlook.com [40.107.93.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9A8106E884; Mon, 31 May 2021 08:23:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oXxJSf7upbKiiaA8qL35Plwttee5BdkvU0X2nN6TInz81oKiargfoHq7d+E5MlT4KMoYQSG9ZBkjVH9Fsg5WZqOEAqJ39riEoB56h4BcWYwwBCLUSP/RVqwcJWn/yDbKhxduHqNKUo884Y61BftPJTF7Dlg08bW+SEopnloY1YC0buklu2VXwQAWkQ96RyqrDKSAqNBxQSjeQSOZ+lBGorO6A4Vr5UQqzNtzwKigZgFDNYaq1YJ+wDPneIbG3NbVg9groG5A4bSWZ4tkezi/Q8Paxq5eltQ4kDTKo7pAbvzAJg2knlNvCRa5iRlHLAGVSBermPzHep3gHCq/VOzz5w== 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=pomkoaOxGlUR1UGQYuCoeiDRnUGFFlIv6X6emanlapk=; b=Rpiosm9Ald51rnqvCtSexkhO0uA5BGeoQapJZZ4JcZAKnKPsrDZFIv1DLeAUO1hcIArfHphrgbU7CkSXCvDiantxHvnygaqb1lHbBzS2q3UQZ+euYXGKrGQJ2NeBgWA5ANpzKA0qn6EjrByiS/+HF0YuEJgYKmlOptABsB77R0FeoHQi9tGlT6OaiPuSMaN+uTc2umiFnRmE82yN+zYYXGdB/SNbk08YYwxvQEFNZBNppaZl/lrfOeXE3S3oXigbDWB30/mWM6LR0mQWbWUstSeWNr5n8/498gu2EPJwWMUUBv43wRC3w0Zpb2sfVPksg2n6fS1QLYrlLXpkgHlTQA== 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=none sp=none pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=pomkoaOxGlUR1UGQYuCoeiDRnUGFFlIv6X6emanlapk=; b=Z+Z1YHBth3+6AeSjmQtQDmlkvUpntooOF6wkE7I5b63joXvz1xmlgtE9Fl/4Vfj4Bsn5kM3FPEqSbUOaVS31TcYUObkuGGNzqrI35NoQD9YR694PdNThfNhwpSXrXdnNJlRoeWFtoQl9D79MHLr+qfgPhhimhsqjM68mn9Fe7UY= Received: from MWHPR17CA0087.namprd17.prod.outlook.com (2603:10b6:300:c2::25) by BL0PR12MB4689.namprd12.prod.outlook.com (2603:10b6:208:8f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20; Mon, 31 May 2021 08:23:17 +0000 Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:300:c2:cafe::2d) by MWHPR17CA0087.outlook.office365.com (2603:10b6:300:c2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22 via Frontend Transport; Mon, 31 May 2021 08:23:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (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=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; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 08:23:16 +0000 Received: from lang-desktop.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.2242.4; Mon, 31 May 2021 03:23:13 -0500 From: Lang Yu To: , Subject: [PATCH v2 1/3] drm/ttm: cleanup and add TTM_PL_FLAG_TEMPORARY flag Date: Mon, 31 May 2021 16:22:39 +0800 Message-ID: <20210531082241.4254-1-Lang.Yu@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aceffc50-e687-4994-b599-08d9240d5761 X-MS-TrafficTypeDiagnostic: BL0PR12MB4689: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3zrOVq47SHCCfKIyY8qwHfG+316N7iTV1iMvjHT2gxhZwinifBh2cDZ6CEd6SS3SXXuWjnWF7towICOq/ug7X3NZFRdWiiBk+w+Cid+gWYyhp0HC0ToLuexWduJmxKQApn2HKUusnkjXy4pE11fS6zBkQpXZ/J/0Mv7jQubk45UKOYQxeX2zmJVzg0dypnyq5lb5fUhcESo/nmz08sUMLCvXACDRj0zHBi8SNw6c697B+SdloigvTmCCMy2g4+uerbUZ0E0BW3YhZBN5qodoKb2JpRz8PtPjIvBN8xXO2FWgM2Y6QlZXkjRhIQ/i0OLbgORV2znzNx63o8wfkamoFklZaW0tvT9anDFMkw801odraepWTwY6SP8b7OCzf2RPjKCDv1PNkXYsIL3Frb7JSdMVIWeXdqrjuqjrIo1LpHQlPJ9LtwwvaIE0GbvEsdXcUw0uixy4pmU2p5qT6qzIvF4yo476jI6guBKR5V2YbCWRt50JUyftKpxWr5hIpllB7RYhbSDQ4pAKfykwmmFvHfUY6iSCyzBwpqcnGjflWrnM4KLoFou4F/trhxJ6Xf1hXsBGi+LRERfY+b7/m5v9JEppVC90w32NWkZkyQGMu6Il4ZfeMIoFTsfkXt7a8wZd5hqGHh6fsYWwAy3r0dOSTesrVLalffTkOqxzDo5SXjY2L8IoxFkVWONVYEsUaU63 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:(4636009)(376002)(346002)(136003)(39860400002)(396003)(46966006)(36840700001)(66574015)(36756003)(82310400003)(83380400001)(26005)(478600001)(86362001)(2906002)(70586007)(70206006)(1076003)(186003)(110136005)(5660300002)(2616005)(7696005)(54906003)(316002)(426003)(336012)(8936002)(6666004)(8676002)(356005)(36860700001)(81166007)(82740400003)(47076005)(4326008)(16526019)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 08:23:16.7182 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aceffc50-e687-4994-b599-08d9240d5761 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: CO1NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4689 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: Marek Olsak , =?utf-8?q?Christian_K=C3=B6nig?= , Huang Rui , Alex Deucher , Lang Yu , =?utf-8?q?Thomas_Hellstr=C3=B6?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Cleanup and just make TTM_PL_FLAG_* start from zero. Currently, we have a limitted GTT memory size and need a bounce buffer when doing buffer migration between VRAM and SYSTEM domain. The problem is under GTT memory pressure we can't do buffer migration between VRAM and SYSTEM domain. But in some cases we really need that. Eespecially when validating a VRAM backing store BO which resides in SYSTEM domain. Add TTM_PL_FLAG_TEMPORARY flag for temporary GTT memory allocation under memory pressure. It may be useful for dirvers with a limited GTT memory size. v2: add detailed comments Suggested-by: Christian König Signed-off-by: Lang Yu --- include/drm/ttm/ttm_placement.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h index aa6ba4d0cf78..9f5cfc7c2d5a 100644 --- a/include/drm/ttm/ttm_placement.h +++ b/include/drm/ttm/ttm_placement.h @@ -47,8 +47,9 @@ * top of the memory area, instead of the bottom. */ -#define TTM_PL_FLAG_CONTIGUOUS (1 << 19) -#define TTM_PL_FLAG_TOPDOWN (1 << 22) +#define TTM_PL_FLAG_CONTIGUOUS (1 << 0) +#define TTM_PL_FLAG_TOPDOWN (1 << 1) +#define TTM_PL_FLAG_TEMPORARY (1 << 2) /** * struct ttm_place From patchwork Mon May 31 08:22:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lang Yu X-Patchwork-Id: 12288861 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.8 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,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 9AAD4C4708F for ; Mon, 31 May 2021 08:23:27 +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 4F96E610A8 for ; Mon, 31 May 2021 08:23:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F96E610A8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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 7AA9289FD3; Mon, 31 May 2021 08:23:24 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2070.outbound.protection.outlook.com [40.107.223.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id D0D2489FD3; Mon, 31 May 2021 08:23:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BRr7e4fUIE9aMfzzQZ+D7dibATYv8gKUNFtoKvowN7MuI5WOABwvJYqQ+2Ru55U0NFzDQ4fXl7rS0m8OnegpBrlAfQq6k0dZfcfaTjsfsL0qH7tTMD3c6+h8yHHhYF63gY/b1zux7pGLp3t6YXPZms6z3m6FKLnk6p1bGNsoJO0qvRhKjVZkWm8WrsvWcimak0eb5w/+uNet3K7k13XssZ1/3XBr09nnFvWFG2T8tJ/CsZtfy8bCfgxBMQ7VS00N3Kck4ckkQWyhmKJ/DRgRoRKnoikkW6DmMKn7p1MbkJljcqicCCf4wFhy1JjF9YkGE+ki0+LW8bgOHRhY5lhGiw== 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=FthBQzATa8ZqgOusGg7xTNWopE+N1DNHO1iMM9r4cs0=; b=Tw5k6UkflrOWNxxeN9gYErxLxO36UrfvoEnsX20DHJKd3LmZj7pWWcWH8LEtruxTVa5gbliKEO5N++8+Argpqq1frYQdW2eifLmVE8DTF1n0b14ZlxJuuDEVALTEPxvlM3txsrzsxOF0eaJiP7SHne5d/B73gUcK8rRE/bUm3/S5wS1bgc9937GSmIHfWxDZxqgl0mPxgc1Y1pvswv0xrNOKRCNAc1zKWYVzKPdGoui51ujgiw+urxe3LlucrH3yZN49BWpQWEeSWZD6n2pYHOxXoOUJflk7nB+sv7xqPYmieY5eM0UNhZOgwcLLdPTWPKFOldldIbiKYNM9ZqTy7g== 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=none sp=none pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=FthBQzATa8ZqgOusGg7xTNWopE+N1DNHO1iMM9r4cs0=; b=b6SSbov0+0+tbn+uRHQCN3HrLPHDjOC+Cd75b5gc5ICjrL+iJgT6Zd6Wxvf2ReFIJ0QmZAEqsQ8kVjJC9gk961Yl10cmEPWKhBvUE8i3e0jAOcJfazuX1IChPF5Iiv9ElnCdCjhmDF/H9pJVhvqc53Cetnepr3HuewtctYhW+0Q= Received: from MWHPR14CA0018.namprd14.prod.outlook.com (2603:10b6:300:ae::28) by DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Mon, 31 May 2021 08:23:22 +0000 Received: from CO1NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::17) by MWHPR14CA0018.outlook.office365.com (2603:10b6:300:ae::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Mon, 31 May 2021 08:23:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (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=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; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT063.mail.protection.outlook.com (10.13.175.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 08:23:21 +0000 Received: from lang-desktop.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.2242.4; Mon, 31 May 2021 03:23:17 -0500 From: Lang Yu To: , Subject: [PATCH 2/3] drm/ttm: check with temporary GTT memory in BO validation Date: Mon, 31 May 2021 16:22:40 +0800 Message-ID: <20210531082241.4254-2-Lang.Yu@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210531082241.4254-1-Lang.Yu@amd.com> References: <20210531082241.4254-1-Lang.Yu@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 66a1a90a-0df4-4f76-9b93-08d9240d5a57 X-MS-TrafficTypeDiagnostic: DM6PR12MB2714: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8TqDxvyRc0XwmRIQvil5D5wg4PJFKA2dYz74ffhYt015iv94DWS7+pzPbXsyxoLvtQaMJwv3IsiIl519i+8LCfCSBjTr2lrlL7rF+0iH4nZTaiXE2J8sjBod4UVir2k1YvPjrYK+iooE7AGpBQDiuCzQ6WqsVVUsA0XHoqc7kQKnCLljD7oPcPGtWrzomaUnWBsvyBhe9B7VTeOGXMH4f5Fryz/yCiGwONR/nvMiqHRImczgki9ynEMp//Y6xr5IHNEXckI097aGzhlKM4pCQ+ecBI7Ha843CbmrtzGaszhIX/TErXu3gbU/2z4N67qnW123YOYN7eyUDzXfn/xLT0aI22znlTCvK2Z9a41+a9DIC9+sDo4hTdYKVpD47e2SkMLWEmp2PZSCLKnB37cqZkbnpEVCZpdFT2np2fRD7V9UD3osp2GERk0M8cOKb4WV7QldmaJxqAlxtF9aAZLlscBtWJMfVaPJkmvZppW9om+xW9zPnKhr7ffrPd/YJdi+rnAfxOcIDEMq43zji+hnyECXo7JmsFHKv/OycUGjQ0zUKFuBy/xhxrSk37WqnSxWc18NpgjQLlVAqdCkshpC/Ich6im9NU8iIwQyGvwvDUFnWANnBM9NQeoy63Mussc+bjjn6bD6XOn3puJ4gBoC1btB9F1w8INZhBXneHwKf2+M15h692UN2+E+jFIm+80y 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:(4636009)(39850400004)(396003)(136003)(346002)(376002)(36840700001)(46966006)(47076005)(1076003)(36860700001)(82310400003)(82740400003)(36756003)(16526019)(186003)(2906002)(426003)(26005)(356005)(6666004)(70586007)(70206006)(86362001)(478600001)(54906003)(8676002)(7696005)(110136005)(4744005)(316002)(81166007)(8936002)(2616005)(336012)(4326008)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 08:23:21.6892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66a1a90a-0df4-4f76-9b93-08d9240d5a57 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: CO1NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2714 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: Marek Olsak , Christian Koenig , Huang Rui , Alex Deucher , Lang Yu , =?utf-8?q?Thomas_Hellstr=C3=B6?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If a BO's backing store is temporary GTT memory, we should move it in BO validation. Signed-off-by: Lang Yu --- drivers/gpu/drm/ttm/ttm_bo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index c32a37d0a460..80c8cb2c3f31 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -944,6 +944,8 @@ static bool ttm_bo_places_compat(const struct ttm_place *places, if ((mem->start < heap->fpfn || (heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn))) continue; + if (mem->placement & TTM_PL_FLAG_TEMPORARY) + continue; *new_flags = heap->flags; if ((mem->mem_type == heap->mem_type) && From patchwork Mon May 31 08:22:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lang Yu X-Patchwork-Id: 12288863 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.8 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,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 9BCB4C47095 for ; Mon, 31 May 2021 08:23:31 +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 5C1A8610A8 for ; Mon, 31 May 2021 08:23:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C1A8610A8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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 BB7B16E87E; Mon, 31 May 2021 08:23:30 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2055.outbound.protection.outlook.com [40.107.93.55]) by gabe.freedesktop.org (Postfix) with ESMTPS id D4AC56E87E; Mon, 31 May 2021 08:23:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dVcpg/TXvpXraLo47I9o+GbbkWzLkHYVpMZhWpQQUvDlikR4CnC4Kf3U1uJEVceIQ5Pemq+zwD2jxLuFHwTNGIbIKkhTNGo7NSgXhnsmVOoVqRZtB69MvzpD3iUnFvZVweJHkLsBSEIIh0gLx06GtO5A1wLaxKw2UVGZlXn7qGjgf7Q7f0/F+zrTpIIQnzAkOM/bSV+FgxLZttpS7GNGasbUf4TKPBgpw2GI+R9WuK2ZZGvU1QY8mXQnSJI51jnKz63VAHv0F4kU7vLyrdfrI9lYqkTFEzrVat0A4w0fpxYz0DBgKACz6FFyRoJqfHe9KXJ9vPjYdUU0WNcfRKA0Ag== 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=3G67fY+A1y8Dk99cENW8wldF38B0XQQB8LLxN7gkJlU=; b=fDVCTjdVWyPmTezsAmERK/5puQOPhfeCkFm+TkH91L3P4++cjFXyBY71yIBEQ3sOMkQ9JqYM9GVOQIkmKo8x8KHtuGvcPjwNtW0JsfooqZoBZf8vzTKopzubN14NpoWI92EGYJOcNv1XJmOJWxSx4givYjhQL1H+haWffaOOPeD1s+Waq/Y70ZpVshhj4pn63UnfMG3rv62IYAlk5eIZ1PnjMLxVI/UW0IPxUGfnKzRPD1vkhNmHExes/V6aY7CB+Tkvs0S6MjEQjQd1obRbazQGxB1wpOFLbMNKzAxnJoqUReeqp55xKuPBOf7IMZ1bwX8XiS9htAT+qe3+RpKvCQ== 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=none sp=none pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=3G67fY+A1y8Dk99cENW8wldF38B0XQQB8LLxN7gkJlU=; b=eI162xw66hV/yuaVr9iaP+d2hVbNxmuN9IsLYV8xnX+3gw4lYPGIzWuCO8RPpmNJrdLT+XDo4KaECLHVnJV7tbcNsFFj5IWuoB+3tcpTeVJT2FIQe4XecJno+bC0yrWYlpo1DTbY/BJGJ7pY5Ub4vLfRISfo+dLFJEhZj0/J6fI= Received: from MW4PR04CA0031.namprd04.prod.outlook.com (2603:10b6:303:6a::6) by BY5PR12MB5526.namprd12.prod.outlook.com (2603:10b6:a03:1d7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Mon, 31 May 2021 08:23:27 +0000 Received: from CO1NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::b7) by MW4PR04CA0031.outlook.office365.com (2603:10b6:303:6a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Mon, 31 May 2021 08:23:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (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=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; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT023.mail.protection.outlook.com (10.13.175.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 08:23:26 +0000 Received: from lang-desktop.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.2242.4; Mon, 31 May 2021 03:23:23 -0500 From: Lang Yu To: , Subject: [PATCH v2 3/3] drm/amdgpu: allow temporary GTT allocation under memory pressure Date: Mon, 31 May 2021 16:22:41 +0800 Message-ID: <20210531082241.4254-3-Lang.Yu@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210531082241.4254-1-Lang.Yu@amd.com> References: <20210531082241.4254-1-Lang.Yu@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8efe37d-e37e-41de-7c31-08d9240d5d3e X-MS-TrafficTypeDiagnostic: BY5PR12MB5526: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s5wuIf6uqgniWwUj251XgyMoKOPnbeDD/xJpkXXK5ZU07uiZrQPQdPQq4y9YThbCDqughhfIZU8MIv10iPsw6FDsDp7dMR/kI+cDebelZYFSpocHp4IoLMgaUsnY7L+/jg8jRCxi7eR5XMYs5k9MjtY9yxHoN7S4a2b58wOsG0oSQAO9tYHVvawOF0fi5cFpQta5tdds2KzCmwPHMHSyN+9vcNd/dmzt+RiomVy65p1+CK4xqR5Z7dFHDD97xONbg7rrNPdBhqugWsat0yEeVvhDnueAaHtYfH3kmEf9DNabfo8lNl+5fFHqlYQZbQP/zjivzgqbhkZoCIR3ZXniYdz01vDka90seBlxpM/+8G3kggRUxO5cOh+oQOUdgw8n9fIl40gessS0wr44hHehBX1c/sKfKhlDRr0c35tufvpHZt7VPiUCl7+m0Wqsm/GDvXwKZwa22lPeSyM9k/eO0x9kS70UyAeCVVeY2Vwpis+7ZeI1rcuFM7dDlZlD2ftqo+oWIh3MVfxHj3zt0YOgkIPUEmqFKTQKJUQIDC/2JsNz61zRNWOgn4BkF3eGvaiFnPU74vHpRYEHU9Gthsxzh267FBjQbS03mkcIh8718Aep8VzGLOPS/yT1/1WRKeZEJtsBFtezUm0KiIwKyzjKtxNN/TFOBy2es0i4u8QqdVDtYayQuc/EndRKr5N3QOYa 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:(4636009)(346002)(39860400002)(376002)(396003)(136003)(36840700001)(46966006)(70586007)(356005)(36756003)(82740400003)(83380400001)(478600001)(26005)(5660300002)(2616005)(86362001)(70206006)(81166007)(4326008)(7696005)(316002)(54906003)(110136005)(2906002)(1076003)(8676002)(426003)(36860700001)(8936002)(6666004)(336012)(186003)(16526019)(47076005)(82310400003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 08:23:26.5547 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8efe37d-e37e-41de-7c31-08d9240d5d3e 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: CO1NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5526 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: Marek Olsak , Christian Koenig , Huang Rui , Alex Deucher , Lang Yu , =?utf-8?q?Thomas_Hellstr=C3=B6?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, we have a limitted GTT memory size and need a bounce buffer when doing buffer migration between VRAM and SYSTEM domain. The problem is under GTT memory pressure we can't do buffer migration between VRAM and SYSTEM domain. But in some cases we really need that. Eespecially when validating a VRAM backing store BO which resides in SYSTEM domain. To solve the problem, we allow temporary GTT allocation under memory pressure and do the following: 1. Change mgr->available into mgr->used (invert the value). 2. Always account all GTT BOs to the used space. 3. Only when it is not a temporary allocation bail out. v2: still account temporary GTT allocations Signed-off-by: Lang Yu --- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 27 ++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c index 8860545344c7..393f55f412b7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c @@ -111,14 +111,11 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, struct amdgpu_gtt_node *node; int r; - spin_lock(&mgr->lock); - if ((&tbo->mem == mem || tbo->mem.mem_type != TTM_PL_TT) && - atomic64_read(&mgr->available) < mem->num_pages) { - spin_unlock(&mgr->lock); + if ((atomic64_add_return(mem->num_pages, &mgr->used) > man->size) && + !(mem->placement & TTM_PL_FLAG_TEMPORARY)) { + atomic64_sub(mem->num_pages, &mgr->used); return -ENOSPC; } - atomic64_sub(mem->num_pages, &mgr->available); - spin_unlock(&mgr->lock); if (!place->lpfn) { mem->mm_node = NULL; @@ -152,7 +149,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, kfree(node); err_out: - atomic64_add(mem->num_pages, &mgr->available); + atomic64_sub(mem->num_pages, &mgr->used); return r; } @@ -178,7 +175,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man, kfree(node); } - atomic64_add(mem->num_pages, &mgr->available); + atomic64_sub(mem->num_pages, &mgr->used); } /** @@ -191,9 +188,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; } /** @@ -234,14 +230,17 @@ static void amdgpu_gtt_mgr_debug(struct ttm_resource_manager *man, struct drm_printer *printer) { struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man); + uint64_t used, used_pages; spin_lock(&mgr->lock); 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); + used = amdgpu_gtt_mgr_usage(man); + used_pages = used/PAGE_SIZE; + + drm_printf(printer, "man size:%llu pages, gtt available:%lld pages, usage:%lluMB\n", + man->size, used_pages > man->size ? 0 : man->size - used_pages, used >> 20); } static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = { @@ -274,7 +273,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); ret = device_create_file(adev->dev, &dev_attr_mem_info_gtt_total); if (ret) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index c0aef327292a..129d39392859 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -152,9 +152,11 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, abo->placements[0].lpfn = 0; abo->placement.busy_placement = &abo->placements[1]; abo->placement.num_busy_placement = 1; + abo->placements[1].flags |= TTM_PL_FLAG_TEMPORARY; } else { /* Move to GTT memory */ amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT); + abo->placements[0].flags |= TTM_PL_FLAG_TEMPORARY; } break; case TTM_PL_TT: @@ -538,7 +540,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict, hop->fpfn = 0; hop->lpfn = 0; hop->mem_type = TTM_PL_TT; - hop->flags = 0; + hop->flags |= TTM_PL_FLAG_TEMPORARY; return -EMULTIHOP; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h index 2877a924086f..26b67af00550 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 {