From patchwork Tue Dec 10 17:59:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Yunxiang (Teddy)" X-Patchwork-Id: 13901897 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 4440AE77182 for ; Tue, 10 Dec 2024 18:00:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 82DAD10E05B; Tue, 10 Dec 2024 18:00:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="5M4PwEd5"; dkim-atps=neutral Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2075.outbound.protection.outlook.com [40.107.244.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 31EDF10E05B; Tue, 10 Dec 2024 18:00:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CX97PEpRrsaJEM33ygok9ZzZMnQO3k1pSqbxcMQ4hRrAPZScCLPcxXuQmlDzcwfPdlR0JH9Ll4LvvlbBKrWcbIa3LHUHnQc8wpkAwbSLcobhqB3WC3i0cybL7x3MbvZHanhlRnE4XWPS7Vx0L8OkRueB96FHHwD18YucGUfvQ2R8aUCe+KaeM82FM1fYFcuYFdO5tF0M/QCC+SmTRIMQl+cRxAYHlMh4o9CCSme046mUZ/bbX4rLR7v8scYlJCqfrIuLRvb3A+SeAbxhXvMKweanIclk0sQwfMfhJpq2x3v8ZOKdORE5imcuyIEj70fFfzyAVtLNIui57lvPw74MBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=wqrJLe1wi/RHT9PAGF3vluo3AzmDZF4MRJgepVb6Jqw=; b=P8QJaES20shWkA/sn8y/So2g5wDYdOD6pcC9DidNLUrQvINJfkjH53pr+2WH8dACKqfBFeGEb493qldjS2MZpmZh4q3O1jP5m7qpKmrSuqBqLYE7gWA2EkWk1HtJBZuCtIKSkr/O7+i8A6IDCOhJitfbOKdttss+7vISLkNciHU5ruOfYbEEnmxoxq09b+v2d666brvnFKX18HsZFhVonf5hrBDkPxvZgx+rIm0UFtLez9RRP8pmti9daePzQm/NrmqhEAMxIvJTbKSA+M5hdRI1mfblhNuWLJTokFS/bRCzQT5N8oI8tHSh57mlgv1RyDn9SunzslMHpqPqJvsIaQ== 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=wqrJLe1wi/RHT9PAGF3vluo3AzmDZF4MRJgepVb6Jqw=; b=5M4PwEd5Iogl9/Uimze+4/42lj675+9Eyb2C//CgL9PuGboTC2mkA3nHuLsiRnL0EH0GooOsysL501ijOCu/Duf1qZ8hrhdYtTOKCse/m6QWj3LQQ07bEo1XDFvYIVhUt1BqE7i/dJ1KNbwtX8nfad3lPC370Fv7WK3P/ydnhe0= Received: from SJ0PR05CA0056.namprd05.prod.outlook.com (2603:10b6:a03:33f::31) by DS0PR12MB9445.namprd12.prod.outlook.com (2603:10b6:8:1a1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Tue, 10 Dec 2024 18:00:05 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:a03:33f:cafe::c3) by SJ0PR05CA0056.outlook.office365.com (2603:10b6:a03:33f::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.9 via Frontend Transport; Tue, 10 Dec 2024 18:00:04 +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 CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Tue, 10 Dec 2024 18:00:04 +0000 Received: from MKM-L10-YUNXIA9.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.39; Tue, 10 Dec 2024 12:00:02 -0600 From: Yunxiang Li To: , , CC: , Yunxiang Li , Subject: [PATCH v10 1/6] drm: add drm_memory_stats_is_zero Date: Tue, 10 Dec 2024 12:59:34 -0500 Message-ID: <20241210175939.2498-2-Yunxiang.Li@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241210175939.2498-1-Yunxiang.Li@amd.com> References: <20241210175939.2498-1-Yunxiang.Li@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: CO1PEPF000042AC:EE_|DS0PR12MB9445:EE_ X-MS-Office365-Filtering-Correlation-Id: 54d5ecb9-6236-4e74-f9ee-08dd194479c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?EQCtXp9ZXXcmsJQyTU3AR4ZOfzZ3QFJ?= =?utf-8?q?jcb4ipg/ica10V28tcWBIQFYy/Y7rSSlXd9CZv6MkgccjeBbm4BssIwbuKPEwX8IH?= =?utf-8?q?f05Pl/gXjbdd+FtOoLvOukJkAdyVMOn5P2+XZkMAFUUKcVi0lvv7UxVU/szcojTGy?= =?utf-8?q?U79DqsGIegoXXz+Ku5IXcOWsoM0ylD1bE7slilPnwEr4MoPBLDdS2gl6NhEbchkKp?= =?utf-8?q?tIc3rd/jG46OEP44767pMc5Sa71jyHQQqXUQbtbYcG3DAy8pJDJkRiCb6asyBed7p?= =?utf-8?q?rh+Td3nEae70M/BA0Zh8lVJ5Qi5lE3nPst30aAPoZ/VWIMAG43xem7+VL0sqiADrt?= =?utf-8?q?wvGlNSEbqYnK1Sy/Z7SZyYsmNiAPKUyY+MaOGaEgaHoPLo6jGd0GS7+8nPBbMkspP?= =?utf-8?q?4I0sdc6EyWDr9lv1f8whLcfE2CD95RaWrrEagW4lB04DSLFkm1/Y2tvfHXyKUFVnY?= =?utf-8?q?uTWABIgeaajbjqJYauyW6sgrllstpHZRzMdZ/34HcxqG0josxhdhswU4rDLpY/1Id?= =?utf-8?q?b1JnNDgVtBG5lal/WLWg/CnPyt16lWBEozhxaLqKGFJoGoRwv6PIJ35yI66a6dmSr?= =?utf-8?q?QZ7ZQ5DC35yi/5G3G/bglhWQjQll42u/S0CuO+DnO1IGSfIJGbv0WcZv3LjALLS6d?= =?utf-8?q?v3I/tE8N35/76zTyJQDNsLu0Y7//fEhGQHYt4jvggerRyWKhxlYvrdRnrs0D733lv?= =?utf-8?q?YCos662o/QvHYJaCpNQqxuGKA8obY2rpWMDqJXvKtzWGmID7qX6srGbteST2fdqfz?= =?utf-8?q?KouyB3PWO6jfJuFLdMnVjTSnYXV/cMCJbjHRX1M9SxzkzzVBkoY8/0uG5YTxdnsUH?= =?utf-8?q?azFFsZY3kEuDa1ieg+mK8/K/6Vv2p1TIvzGBHpwyaT33yNALfZZFDp/K3rBs8ipOI?= =?utf-8?q?au4+LC+iYG4JdlJ9dI4cpo84dKTJEr9xSNGQROXnlnq44M7HYJPhHDg2RpEfm4Xld?= =?utf-8?q?38ETiCokJAgm2c8UvjsyvEI7s2sDOS8xyjPuERaT7K1Lv2TXhaV/s9ZVZobRAm96B?= =?utf-8?q?eBfXb48ugem9JENvZW5ab9fuR9DVvhWuGMxQkvTTSO0b0IqLxL69U/RSFPIaBSOAb?= =?utf-8?q?p3XWxw9FR+UIRaUDI7DhLvuKsZjNHgaUYaC2Uj7k662ibDeTDeQfVp7jOK0arr1g6?= =?utf-8?q?GtQt7Mz+547j7fswIC2tnj4oeYUNZWfrF4BaRac4kf28CVA+h3p6ZOqsNXHo1Nfpt?= =?utf-8?q?zHJzjoR5S25cG3GECLTylqc/qntL2ZXcn518r17y94KMWkadtEGYDGe4CLHPtifb+?= =?utf-8?q?QgMVnxezztTtHQiAb7SZKdeA2uopGIhY0QjXZZP9nT4X+JjAO5Oi0Z/9s7CXAiyiL?= =?utf-8?q?a2MWbdUYrYb+M6daNvdxgSBB+fa5djpKxiB1MPYQn4Zwju1uU4RTOLHSis0BwggsK?= =?utf-8?q?0meeZis4yHg?= 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:(13230040)(376014)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 18:00:04.4866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54d5ecb9-6236-4e74-f9ee-08dd194479c3 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: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9445 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" Add a helper to check if the memory stats is zero, this will be used to check for memory accounting errors. Signed-off-by: Yunxiang Li Reviewed-by: Christian König CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/drm_file.c | 10 ++++++++++ include/drm/drm_file.h | 1 + 2 files changed, 11 insertions(+) diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 714e42b051080..e285fcc28c59c 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -859,6 +859,16 @@ static void print_size(struct drm_printer *p, const char *stat, drm_printf(p, "drm-%s-%s:\t%llu%s\n", stat, region, sz, units[u]); } +int drm_memory_stats_is_zero(const struct drm_memory_stats *stats) +{ + return (stats->shared == 0 && + stats->private == 0 && + stats->resident == 0 && + stats->purgeable == 0 && + stats->active == 0); +} +EXPORT_SYMBOL(drm_memory_stats_is_zero); + /** * drm_print_memory_stats - A helper to print memory stats * @p: The printer to print output to diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index ab230d3af138d..7f91e35d027d9 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -477,6 +477,7 @@ struct drm_memory_stats { enum drm_gem_object_status; +int drm_memory_stats_is_zero(const struct drm_memory_stats *stats); void drm_print_memory_stats(struct drm_printer *p, const struct drm_memory_stats *stats, enum drm_gem_object_status supported_status, From patchwork Tue Dec 10 17:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Yunxiang (Teddy)" X-Patchwork-Id: 13901898 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 85538E77180 for ; Tue, 10 Dec 2024 18:00:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8709B10E2D0; Tue, 10 Dec 2024 18:00:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="fTJbSE/k"; dkim-atps=neutral Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2055.outbound.protection.outlook.com [40.107.220.55]) by gabe.freedesktop.org (Postfix) with ESMTPS id DBE3010E05B; Tue, 10 Dec 2024 18:00:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JiO8JqFKMXcFIlQyGxaGvCd8KsW/Mtjfk0JdV9Bca/DyfnYhwKi+Mg71e56MTP9JUylpLL7mFMTECjNYOpX7W70cDwuf9d3FZtw78lqxhh5QtZTfpUoUkK4vZWwpff2yDzhQZGq59G2E16MDiXOiTEQ65b9OwcNe7dpfz6SOnnsugKDOIfiWijMxCmc/SPYxN0pkr/aOntiNSTtznLd4DMrW8YQ1JJ77zKA1+suEecZMXHqzLfuJiFARcpLs4SfO7PAZ38G1elJy1ALVFirrjv+H4wIGXkcboWziX3rpk9dTAtxhjWdjTOYGqwWGnEeOGcU5+M4TCgYT/cFCCHN1jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=IVmkT4EaULOWwtspVkBfamFqLzxiMmRZafqnbZwevig=; b=zEsLLXm6DgOXNsWiUFKGitZT3YFEgpRhE/eJ2jU984l7MI+4qj0nNdSvAmto5QgE8SIPhij2OnVI6EMu1uj8cpeM0pBomDe6rdeRALCRR7GKVIwxPzFVqotoZmIXuLrsds3+VRDN/+xnuWKPtfvatU22RWFHzx+XkN6iwr6FZSqHB0/zt84MI/V9PEFZ4p2/f+JmFi+uhALU2VhjHz50HaKZFuSr4q26u/sMS6VBbauLvTSpE3S4z4ZzFQPvkxxLD9YZCIJMi66TUR6qoVI2Df5d6iaDR0uY9Y9GO37EOF0a9fFL2muG7nx2PmG4iMU2Ib9YhXgnlmjEAQ7FnxuvFQ== 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=IVmkT4EaULOWwtspVkBfamFqLzxiMmRZafqnbZwevig=; b=fTJbSE/kiTm2UYNIQrJwzjPcjYvQXXsQAS8wrQ4NrMIm9s4FMZM1NNJ5rzznYCDhC2F+/PCN2XkdlsROaDvz1GmwZJ7wTPbpSk1rEapqYLKGpcAmTv2EbU0t3qFq8xF11f0HSQKxLGRSayoACibXZTmgkCK9EzSFqSyCqR895dE= Received: from SJ0PR05CA0044.namprd05.prod.outlook.com (2603:10b6:a03:33f::19) by SA0PR12MB4446.namprd12.prod.outlook.com (2603:10b6:806:71::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Tue, 10 Dec 2024 18:00:06 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:a03:33f:cafe::1a) by SJ0PR05CA0044.outlook.office365.com (2603:10b6:a03:33f::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.13 via Frontend Transport; Tue, 10 Dec 2024 18:00:05 +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 CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Tue, 10 Dec 2024 18:00:05 +0000 Received: from MKM-L10-YUNXIA9.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.39; Tue, 10 Dec 2024 12:00:03 -0600 From: Yunxiang Li To: , , CC: , Yunxiang Li , , Subject: [PATCH v10 2/6] drm: make drm-active- stats optional Date: Tue, 10 Dec 2024 12:59:35 -0500 Message-ID: <20241210175939.2498-3-Yunxiang.Li@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241210175939.2498-1-Yunxiang.Li@amd.com> References: <20241210175939.2498-1-Yunxiang.Li@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: CO1PEPF000042AC:EE_|SA0PR12MB4446:EE_ X-MS-Office365-Filtering-Correlation-Id: adba262d-aac6-4ce0-cc1a-08dd19447a57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|376014|36860700013|7053199007; X-Microsoft-Antispam-Message-Info: OlpRPNNDOZwlhhTy9KcBKVaTjGm2IoVEpH/S6PT6dHlTdjCy+bIn0/s+nUlvx+gcQzuV8vfAPQ0lX90gKxJaUO+lb0Z19h1ixIBxFaqPKpI6UIfumVGjSbEm4c8Vff3gUQQw2rpkXMZauk603Vepn6F5rPkPLoBiMWl7RmEVt4Pky8wFs72XHNXR3VmAdYWqtrQDiKZhbIBO5X/RdvhGOku5W0urb2AGgVU6BHnZ3R5w+8NPWjJJPl5X0roP85Q3Lznc4h5tzLnB+SO6o7/F0Z8YUGHkM5+oxFBflMFfXxrgUQDDdLZLzKIgb+hv7U1i5K9BX/oSx4YQ6Qdeuv2xgPUpxU2z+U5Vv6NWTeZZwOlK6ukQACbY8QhAf+E1bKc+u9mRJb/C9DJ7cVJSgc2WDDZV6CNRJrl+WuRK5teJx587bxul/qhOLppCL+wBbX7OQgGGKmZlPnbk7brSgQ0BKd/eLFHqB1UPM13Mdv2PmXz3ex5Dc9WjigpXOcyNI1GnMbRrFGCmMHXR1Ci4eRUl6EfxDF1COERlAJN9QHW8oedzkcFJyK99EU7fH0N12i/IfCfNfWu4NyaXdMNvhZWtrHEteG1+aIp3tc4/7w2uOUnAfKfCksduCOHCjXmPLrG/Szb3PT0RyJ94m5NtKryEPMVFsVSO+TefIiWZ7eJnOqlaW8Wm4tApTc+t+Ee0l1B69TDza8g4zI7XhJffmq9y0IffV4UE7Hs4259ZECLix1JZPubQd8y74vTvU/8LvANExejrULb4Q9GolBF0yAVT5yObF/szcr/8FGknSe94RAnO7yq/4BgyABrU1wsWjQSjxjpypy4l81tKEyA1PBe5Wg0AofbqGWKXrI5NGf5VOZ30/0sVbyQCG6/pZQU9Ej4rIDSzE1dG9tlDOL77K8vND5I6OVh8YOp0RyugnPHvk2hNchTX7PDMRadAdfXlULond9peBMqqSchzl8ZVQvp/04ZAZ85nd9WQwk7EWjPkyjWfWzt/aOw00NeBO2JFZehOMII4NvuOPcU+amPDlKwK5coTCnVwSopS6C8+QYIpOppeOdUWe5B4YmIrlopT9T1jbZG70xwhWKDoUCi9edpMmtD5nGZmJNArkfx4NfdyDvO6Oisu8aHZMV0WKTQ4z/4BS/cQLhprhJ2r8p1I0+8yAiz02Mf2LTB/v/u7N6DYRU1NcDm5T1ousDeLIhgEcdf0xWDVCybmct5oc+Fmon+mAfms8qGv5bpHO7zC5uS/tS7+Dnq5lR+iKSk6X0g7qjOfTzE1cd+a2vcZeoD3zGlNjptBdjJzh0r2MKHT25yJ0E6bxLlxUIREsInTc+xvKfuPE8UPh094M8nZWrbmxOSFQQDZkxuPyqlQlQEOzLP2bGh+/5w7PHVXfmPvlficZGCRdrk3DV0W0o2bTCe/cdkBge0L1lmvO3ZhLS5maQYu+0iTfVcZ/6ZZVz0PO6B+Wp7I 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:(13230040)(82310400026)(1800799024)(376014)(36860700013)(7053199007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 18:00:05.5960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adba262d-aac6-4ce0-cc1a-08dd19447a57 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: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4446 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" When memory stats is generated fresh everytime by going though all the BOs, their active information is quite easy to get. But if the stats are tracked with BO's state this becomes harder since the job scheduling part doesn't really deal with individual buffers. Make drm-active- optional to enable amdgpu to switch to the second method. Signed-off-by: Yunxiang Li Reviewed-by: Tvrtko Ursulin CC: dri-devel@lists.freedesktop.org CC: intel-gfx@lists.freedesktop.org CC: amd-gfx@lists.freedesktop.org --- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 1 + drivers/gpu/drm/drm_file.c | 13 +++++++------ drivers/gpu/drm/i915/i915_drm_client.c | 1 + drivers/gpu/drm/xe/xe_drm_client.c | 1 + include/drm/drm_gem.h | 14 ++++++++------ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c index df2cf5c339255..7717e3e4f05b5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c @@ -97,6 +97,7 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file) drm_print_memory_stats(p, &stats[i].drm, + DRM_GEM_OBJECT_ACTIVE | DRM_GEM_OBJECT_RESIDENT | DRM_GEM_OBJECT_PURGEABLE, pl_name[i]); diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index e285fcc28c59c..fd06671054723 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -884,7 +884,9 @@ void drm_print_memory_stats(struct drm_printer *p, { print_size(p, "total", region, stats->private + stats->shared); print_size(p, "shared", region, stats->shared); - print_size(p, "active", region, stats->active); + + if (supported_status & DRM_GEM_OBJECT_ACTIVE) + print_size(p, "active", region, stats->active); if (supported_status & DRM_GEM_OBJECT_RESIDENT) print_size(p, "resident", region, stats->resident); @@ -917,15 +919,13 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file) if (obj->funcs && obj->funcs->status) { s = obj->funcs->status(obj); - supported_status = DRM_GEM_OBJECT_RESIDENT | - DRM_GEM_OBJECT_PURGEABLE; + supported_status |= s; } - if (drm_gem_object_is_shared_for_memory_stats(obj)) { + if (drm_gem_object_is_shared_for_memory_stats(obj)) status.shared += obj->size; - } else { + else status.private += obj->size; - } if (s & DRM_GEM_OBJECT_RESIDENT) { status.resident += add_size; @@ -938,6 +938,7 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file) if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) { status.active += add_size; + supported_status |= DRM_GEM_OBJECT_ACTIVE; /* If still active, don't count as purgeable: */ s &= ~DRM_GEM_OBJECT_PURGEABLE; diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index f586825054918..168d7375304bc 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -102,6 +102,7 @@ static void show_meminfo(struct drm_printer *p, struct drm_file *file) for_each_memory_region(mr, i915, id) drm_print_memory_stats(p, &stats[id], + DRM_GEM_OBJECT_ACTIVE | DRM_GEM_OBJECT_RESIDENT | DRM_GEM_OBJECT_PURGEABLE, mr->uabi_name); diff --git a/drivers/gpu/drm/xe/xe_drm_client.c b/drivers/gpu/drm/xe/xe_drm_client.c index 6a26923fa10e0..54941b4e850c4 100644 --- a/drivers/gpu/drm/xe/xe_drm_client.c +++ b/drivers/gpu/drm/xe/xe_drm_client.c @@ -229,6 +229,7 @@ static void show_meminfo(struct drm_printer *p, struct drm_file *file) if (man) { drm_print_memory_stats(p, &stats[mem_type], + DRM_GEM_OBJECT_ACTIVE | DRM_GEM_OBJECT_RESIDENT | (mem_type != XE_PL_SYSTEM ? 0 : DRM_GEM_OBJECT_PURGEABLE), diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index bae4865b2101a..da11c16e212aa 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -48,19 +48,21 @@ struct drm_gem_object; * enum drm_gem_object_status - bitmask of object state for fdinfo reporting * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace + * @DRM_GEM_OBJECT_ACTIVE: object is currently used by an active submission * * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status - * and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if - * it still active or not resident, in which case drm_show_fdinfo() will not + * and drm_show_fdinfo(). Note that an object can report DRM_GEM_OBJECT_PURGEABLE + * and be active or not resident, in which case drm_show_fdinfo() will not * account for it as purgeable. So drivers do not need to check if the buffer - * is idle and resident to return this bit. (Ie. userspace can mark a buffer - * as purgeable even while it is still busy on the GPU.. it does not _actually_ - * become puregeable until it becomes idle. The status gem object func does - * not need to consider this.) + * is idle and resident to return this bit, i.e. userspace can mark a buffer as + * purgeable even while it is still busy on the GPU. It will not get reported in + * the puregeable stats until it becomes idle. The status gem object func does + * not need to consider this. */ enum drm_gem_object_status { DRM_GEM_OBJECT_RESIDENT = BIT(0), DRM_GEM_OBJECT_PURGEABLE = BIT(1), + DRM_GEM_OBJECT_ACTIVE = BIT(2), }; /** From patchwork Tue Dec 10 17:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Yunxiang (Teddy)" X-Patchwork-Id: 13901900 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 32148E7717F for ; Tue, 10 Dec 2024 18:00:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8CB4E10E955; Tue, 10 Dec 2024 18:00:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="Ls/lk0x1"; dkim-atps=neutral Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2080.outbound.protection.outlook.com [40.107.96.80]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE27B10E94C; Tue, 10 Dec 2024 18:00:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DGXZvqxYMVxNDACCqiUrxeUKtZXa72AnyLjtfoYeTIb2F5mpsBt83ofCKCaENEYBfyua18xy/zGFNOd+G1Qk/2CDhBRCKqwENAVO2MfdaBpj+cRJjY2OzBrpWxnTwJvyc9CT4YYLN2NKKWI0a0FP0VfErmxhbrHdQcYr95n14YO2VbRbr46jvsq7MqZndbYDknRooFw1WCFkNutgNJNcY30bT1Txx/iEIuqdBTbESGIqAzw0kkx/WnY3jwnjdYZAvlH/koBI7bSkpYKdWVJe93jl0TyXj0QKS0iO7gJRsMx1+5zp8OoVAko/wI/goSVIaoqClEchiqZT7Rlta0ZibA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Ldky3Jp0v2BpI2Ruukws9uFdNGjxaiQlSt7HgPxOL44=; b=ko+uBThMgwNiDPnZrONFZ+cwVPoOvbNrxC63wPRmhvVxqE8/x8ZH+mDw963cuwJWnSSq+UsgU0hyjuV2u51N4MpV6kYie4N3jG1rN1XElvvS2TJxYfGg13plEyo+IyJuvqHyypPZo+qvZDhBebzXnftRAWHr9ofZkXtZNVs5G2EGXcjoSAlVIH0/iR6nqLcpNQLqFcKdMh3foTyQGyORQaxz76I2edIh6oHHtdP3ERtOSHkKKuWrQ16JovSbbn/40YYTAGQJluTp/v5Okuh7YbScnv1VguwNuSAoM0EJMWgNP0HdabVSdkJyssTfjC+e2C0z/4beXypQATyZVCdevQ== 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=Ldky3Jp0v2BpI2Ruukws9uFdNGjxaiQlSt7HgPxOL44=; b=Ls/lk0x1tLCXHdzR5WFVvqmrzyP84OZOIbJ7FIvEREiGlpPGiJHlRDk+jvT5YZlAd87iDTIJmCoPGVvq8/ATLJgFazQ0vURkCkFBjDrlrd/6U3g2ouKvPBMlZSIZOhz0XeKnS/PpZI/oNlD75cCO0pDmd62YSeQboNWna293IxM= Received: from SJ0PR05CA0048.namprd05.prod.outlook.com (2603:10b6:a03:33f::23) by DS0PR12MB8477.namprd12.prod.outlook.com (2603:10b6:8:15b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Tue, 10 Dec 2024 18:00:09 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:a03:33f:cafe::b5) by SJ0PR05CA0048.outlook.office365.com (2603:10b6:a03:33f::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.10 via Frontend Transport; Tue, 10 Dec 2024 18:00:08 +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 CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Tue, 10 Dec 2024 18:00:08 +0000 Received: from MKM-L10-YUNXIA9.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.39; Tue, 10 Dec 2024 12:00:04 -0600 From: Yunxiang Li To: , , CC: , Yunxiang Li , Subject: [PATCH v10 3/6] Documentation/gpu: Clarify drm memory stats definition Date: Tue, 10 Dec 2024 12:59:36 -0500 Message-ID: <20241210175939.2498-4-Yunxiang.Li@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241210175939.2498-1-Yunxiang.Li@amd.com> References: <20241210175939.2498-1-Yunxiang.Li@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: CO1PEPF000042AC:EE_|DS0PR12MB8477:EE_ X-MS-Office365-Filtering-Correlation-Id: eab60fa1-dedf-4062-6850-08dd19447c39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: LXIEOcjEx4U/JNGU6d7COxVNf3tcZwy7IUWHvVoWxhnqBwOSX2W/JdrbkkbZqzJIGhJGfJCzjuq73RfOHsTspCuPrJGOcqXLJzv9JTgWSutESabI2S65aw2/iag9imwy2ZKp9x2cjWqJZ8WYmYOPmpYXTGNRAGCkIgDjCJmZ7+zh6u+ujyYx3jo9utHv3RK9B/m0yItXRe5uhGijQ0HHQ5XSpz/0SxB1Sjc+Z2WDcrnYlhrECHQ2DpsS4N/dduOt8tzk0gN1JwFx9ofj5dOdXClShEzd8OjVN1+2ATeDmGOh3hRS/qCaTms2/bkPL1al1O7APZ3ynywudMrbwOOygi1xfAJNXo4v4ZLnfVb/uxeGgAWE64aRVy3jsLONqtlZuWsgWeOB1Rc7/Y0taSUjWekji8MeJBV6oRPJ9RmOsQezmdiK5IqFyymMZ205Iz4g/HKQ8SlKlZR7vKM3Y16ZwpA9rzGSEUCnu4Sb10v7JLwZhV0qDb2OEyMIvF21qVfVpyJYj6qvsi0eHXXHdlpI1gfeGYx/SgwzwKUK+AcILkUCTgTVnyMMorOmO8xrg44RcoHp0aU1UNByu3e4LVwaiAqjqJxXToDaJhuEMLbXSb2yTxgjsJJxRSty5oyXP6OeMTjmJY6lsSpR/bg9PCKE9r6AefezoAF6KgTivVind8CUIWVZEYqLI+hHk1QtuMNQka6+mivVtmFMr5D0t+kKHOAovdJyoL4yxS6ToFD9q7umtP0kRKiLIlD6U4ltfBQrVQLcl9RW8YVaBtJKS6qbh1PV/0uxHfgZ4+c+oYOeHRWrrysTmynl1ec6+2ZFvRI8R6u7jzWQYjZ8CoLQKmbwwy1HAuV9b1/xGhvQTOj/NGbeDUPY83+kLhTTlQaUohRtNi3Tl8uYB3tEonwZPS0s/Wk2CiUOBzdxLXne8k/BeXCfhBF2ZchtomKrdP5/HT4EVzjf9doUJWUdorpTOhtbq7PtQrSUzoGNVhorMOpR/62xZw+h8qAI4S7QFlE7kcCru/wTPBarYv+wOMt85aWUovNalvR6nouyDuQUv2UQFLkZOwbjsvQ53jNqlqFJPzwLr1HC+bjVthvY80oH/E/l7gLS/NfPWEtvqb+Q3RGD8Ibn/LEoMhfuFZKnShPj1Hs9F50DKXLZ5T+qnuuMOh7Oe9/xI5Qqd8MBTBv1aFKN1pvNbxoAzDq8koiZ3ThTMRgXjd/0NMmLKcHbJWF52fvhMfXE+j5ffglpc5Zr+JsLRkZMNpXUSM3ZY/FgmV/jN9U7XOZLr1xq1tLdSX0JTxpj2gWdmBZiEI3IR6Y5AZSZH8AI6Usrcawaei7wel7rFLSW4UlwJU4Q+eB7s0GAfEMFzZe98DU1vsqx465keAKmyc8wWx2SQMLHEaTY8INycxUSYCO0Rr3eMXxlFdenC8nCjVeqOnO3rLsgftSa1Z8P5PoMHCeXAh7u9tnc0DTxja8G 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:(13230040)(376014)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 18:00:08.7054 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eab60fa1-dedf-4062-6850-08dd19447c39 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: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8477 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" Define how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better. Signed-off-by: Yunxiang Li Reviewed-by: Tvrtko Ursulin CC: dri-devel@lists.freedesktop.org --- Documentation/gpu/drm-usage-stats.rst | 54 +++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index ff964c707754a..19a5323d0e682 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -140,57 +140,57 @@ both. Memory ^^^^^^ -- drm-memory-: [KiB|MiB] - -Each possible memory type which can be used to store buffer objects by the -GPU in question shall be given a stable and unique name to be returned as the -string here. +Each possible memory type which can be used to store buffer objects by the GPU +in question shall be given a stable and unique name to be used as the "" +string. The region name "memory" is reserved to refer to normal system memory. -Value shall reflect the amount of storage currently consumed by the buffer +The value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. -This key is deprecated and is an alias for drm-resident-. Only one of -the two should be present in the output. - -- drm-shared-: [KiB|MiB] +- drm-total-: [KiB|MiB] -The total size of buffers that are shared with another file (e.g., have more -than a single handle). +The total size of all requested buffers, including both shared and private +memory. The backing store for the buffers does not need to be currently +instantiated to count under this category. To avoid double-counting, if a buffer +has multiple regions where it can be allocated to, the implementation should +consistently select a single region for accounting purposes. -- drm-total-: [KiB|MiB] +- drm-shared-: [KiB|MiB] -The total size of all created buffers including shared and private memory. The -backing store for the buffers does not have to be currently instantiated to be -counted under this category. +The total size of buffers that are shared with another file (i.e., have more +than one handle). The same requirement to avoid double-counting that applies to +drm-total- also applies here. - drm-resident-: [KiB|MiB] -The total size of buffers that are resident (have their backing store present or -instantiated) in the specified region. +The total size of buffers that are resident (i.e., have their backing store +present or instantiated) in the specified region. + +- drm-memory-: [KiB|MiB] -This is an alias for drm-memory- and only one of the two should be -present in the output. +This key is deprecated and is only printed by amdgpu; it is an alias for +drm-resident-. - drm-purgeable-: [KiB|MiB] -The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable. -For example drivers which implement a form of 'madvise' like functionality can -here count buffers which have instantiated backing store, but have been marked -with an equivalent of MADV_DONTNEED. +For example, drivers that implement functionality similar to 'madvise' can count +buffers that have instantiated backing stores but have been marked with an +equivalent of MADV_DONTNEED. - drm-active-: [KiB|MiB] The total size of buffers that are active on one or more engines. -One practical example of this can be presence of unsignaled fences in an GEM -buffer reservation object. Therefore the active category is a subset of -resident. +One practical example of this could be the presence of unsignaled fences in a +GEM buffer reservation object. Therefore, the active category is a subset of the +resident category. Implementation Details ====================== From patchwork Tue Dec 10 17:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Yunxiang (Teddy)" X-Patchwork-Id: 13901899 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 0B93CE77183 for ; Tue, 10 Dec 2024 18:00:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A36110E947; Tue, 10 Dec 2024 18:00:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="v1C9AqZ6"; dkim-atps=neutral Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2042.outbound.protection.outlook.com [40.107.94.42]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A54C10E94C; Tue, 10 Dec 2024 18:00:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C5N/NzNNJZxxBghEG7XLIYUbiG9q6dZHzGdfO6V5umGYslse2YRkd6pMjfknqrY6JeJND8ZAzExCGr3iqK0MfKqaPnkNTTGu2qLbtHfgRbr+Lf1J/fCwFlI59RaJji2vMejYVDEL3/N4hikW+KriHDSggjXMzjresvBTZTEf3pEGcL+zNTVhtZjxihvV/7HTqHpqRwlYcVfFGsOlHLP0zGJ6Om7qf9a8kbG46QjYuYN24UkibGtVPvXWyvBdzxeS1qiUqcV5w9CWB1y/lRl1yEGWUpn1sG2G9eIVV+fCiCcylIzPJzZ4Wceid7J4HPCNIOTT54swjpt6Gs/SkQdYmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=XIUQT/57KDGwZBx3R/9Sp+xvZkpfbLak5DjtIRmow0s=; b=O4CRqg0LPNV/cJ2YSW5CvVRk16T+E7d64nOd7WqMZKBqTUGeoXSKmX4iwyT082uFfMO74U7f4orW8IwdZC7XS1wKSvw67JYn1ywQLchysbOLqkPEmkraIXt+lbV8naeL2kbo/nw6tRu/DORWj8FtLW3/D/LXiB/BLKn4TDr6Ec6ppgmVssiqZi7FpMKH0W9lqtQpgOp81fuKYYeZy+33K+/TyDQbRz+xy5A26Bej0exJX+ap93F6mzDQt76RRnNCmcPlTs97HhuKP+pqx6675l202u9OrKBEcpwSoTplT210b+GimlyWzf0DkaS2Lv6RWTvKg1gwMYEmjnTwaBwe1w== 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=XIUQT/57KDGwZBx3R/9Sp+xvZkpfbLak5DjtIRmow0s=; b=v1C9AqZ69M81tk1GpFTou3vEFp1up8JmQPnfvW77S8pvdBxGtnKiWCbJODJ0+c1/M+la3AoGkjXeLDkvXHd+SHWUe3EK6U5sJ1sc5Omn1ERSZTw/4dZVYZ/sqDzl/t1o4opV1use1sycgA3fIfAxXRtkailPjSAHHcTyyp3Y4LI= Received: from SJ0PR05CA0060.namprd05.prod.outlook.com (2603:10b6:a03:33f::35) by BY5PR12MB4194.namprd12.prod.outlook.com (2603:10b6:a03:210::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.14; Tue, 10 Dec 2024 18:00:11 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:a03:33f:cafe::be) by SJ0PR05CA0060.outlook.office365.com (2603:10b6:a03:33f::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.10 via Frontend Transport; Tue, 10 Dec 2024 18:00:09 +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 CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Tue, 10 Dec 2024 18:00:09 +0000 Received: from MKM-L10-YUNXIA9.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.39; Tue, 10 Dec 2024 12:00:04 -0600 From: Yunxiang Li To: , , CC: , Yunxiang Li , Subject: [PATCH v10 4/6] drm: consider GEM object shared when it is exported Date: Tue, 10 Dec 2024 12:59:37 -0500 Message-ID: <20241210175939.2498-5-Yunxiang.Li@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241210175939.2498-1-Yunxiang.Li@amd.com> References: <20241210175939.2498-1-Yunxiang.Li@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: CO1PEPF000042AC:EE_|BY5PR12MB4194:EE_ X-MS-Office365-Filtering-Correlation-Id: 42219f1e-b7dd-4f6c-c55e-08dd19447cb7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: cXtDStFooCbaAVCglEXqu1yxRFbeQvc7NO2TmPfiTcakVVgCXnhp/Tnk4xZ3/JfHpo7Zf2LT3WgbhvUiqAUeriy7EyRZABL1GsQxTE2gbBROtrHhGkbriszMhhdzJXZW1LTR14NxRLeF8N6d6eHVF94pbe6/XE+TgxsY0MaYc67c3CTdRG1gUk3JltvJjN7MJQC232lt9ha9rtSKDy9aDjG8fTUw9QlJxMQAS2hvawQnzUZhNFit9xlmHBoOhqNYQG+PNLpd+0tANDlzXf3VdoMe30TcZVZHzndoyN0K9D9h6z7t/JOBvk2EWZ9Emw63DUaqigWt/15MTNF35ve9uSf16RSKGca1btNfxN35toXaDgJlY1jV8XisZpmrSjF1/l7KThJDXiIX7fJkxYtarHIW0Zlj3ehSlx1ZiL0GR0Gw4TKrqNZU+HndnFdmdvPc0OhhZiFrfrL7umISPZ0aapzVnLQqnn8niJqHM2FTAGhHfNBvfc304FV43d3anGB9wy/Wy6EDOQ3GNe2TlZdlFHif1yekEyYPOUHsCuX3yyUITConGWIkHILEIqteJV1nxVwTR4K5rELfr0AOAHUmdBQ641wRYgv3+JVGBiYkD6qcsn9FdzoEgVzDOHkrYDo7ekMHZsyldJM2f/m75OyxrQJfjnDRuBL/yPpYPfQXYQo4X4vFgZvcMWIgNWlECWa9LYtNxoZQ9o81NmHfsJBMHFoMeYtQB7Z8dj4XmKq4tJqLvxDj+gaMiJs2/NutIy9+xYdtrdGcQ07LTxdvaq76Ea3r+Ot2uPLG3R8RpO63D9iu025qDZCg4jB18x8lzCDtWQM/suO1CozAm+NxT9wq8XIkXz3fhi+IywrAUigl4G3IxZWIVSPdUhSmhNUl+lF593VLi231HPiMXNfgmzyAN+f+l2JNk5r5CVaNtonrRAIDk8kr5pPsNW6OR7bHGkyvmfa1TaucHPeHJ5SRcL5spSFsbe5bJ8rtcYwzlqeUn//8mxI0vUce1gLS73hfvRJifw8o4LXvnpihjDy2lx+Qh0Oaw5mEzDCfaOGGILrUD1gGXMxyqMUS0+P8esJ5KZ2AZvcn53DY2P94s2ifXCoJcKz6JeRjRSk9pqmGV+H8cE/iVPhLvOwkfYgV1kFBAera+TQKECNW8OEuaxmT4a4SMPpVRqVQGreGxVisgHoUwEyJN15UwBjzQ927l0tpc76dDCYXtSxkudZItZgch9kAWzLSovPSjtbP8Da9/Nc+wxPSmNtkmX8ATWqG0mHRPIyqXA/LRr5tWaXvGscKZmS3bEfkJ4HXVNRapkZMruU6zfIuCFH3siJ2OlNeafeoD0qCcs8rLecZ3WHDu7ZtGqRRnlkMZsfWF/5uNjyXge79EqxqjZTxfrXiVvmmMVqDKNQ0fktnz/5H5PWBu/ezREJL2K4VEkQCAcRTDRpAE5JUwyhAk/Nu5NwQ91crgs7cUDOM 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:(13230040)(1800799024)(376014)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 18:00:09.5492 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42219f1e-b7dd-4f6c-c55e-08dd19447cb7 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: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4194 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" Tracking the state of a GEM object for shared stats is quite difficult since the handle_count is managed behind driver's back. So instead considers GEM object shared the moment it is exported with flink ioctl. This makes it work the same to the dma_buf case. Add a callback for drivers to get notified when GEM object is being shared. Signed-off-by: Yunxiang Li CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/drm_gem.c | 3 +++ drivers/gpu/drm/drm_prime.c | 3 +++ include/drm/drm_gem.h | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index d4bbc5d109c8b..1ead11de31f6b 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -854,6 +854,9 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data, goto err; obj->name = ret; + + if (obj->funcs->shared) + obj->funcs->shared(obj); } args->name = (uint64_t) obj->name; diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 0e3f8adf162f6..336d982d69807 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -406,6 +406,9 @@ static struct dma_buf *export_and_register_object(struct drm_device *dev, obj->dma_buf = dmabuf; get_dma_buf(obj->dma_buf); + if (obj->funcs->shared) + obj->funcs->shared(obj); + return dmabuf; } diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index da11c16e212aa..8c5ffcd485752 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -122,6 +122,16 @@ struct drm_gem_object_funcs { */ struct dma_buf *(*export)(struct drm_gem_object *obj, int flags); + /** + * @shared: + * + * Callback when GEM object becomes shared, see also + * drm_gem_object_is_shared_for_memory_stats + * + * This callback is optional. + */ + void (*shared)(struct drm_gem_object *obj); + /** * @pin: * @@ -568,7 +578,7 @@ int drm_gem_evict(struct drm_gem_object *obj); */ static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_object *obj) { - return (obj->handle_count > 1) || obj->dma_buf; + return obj->name || obj->dma_buf; } #ifdef CONFIG_LOCKDEP